簡體   English   中英

使用Frank和Cucumber時,如何使用gets模塊獲取輸入?

[英]How do I take input using the gets module when using Frank and cucumber?

背景資料

我目前正在將Frank與Cucumber一起使用以在iOS應用上自動進行測試。 一切都能正常運行,我可以將應用程序法蘭化,運行等。Symbiote可以正常運行,Cucumber也可以。 我已經編寫了許多可以完全按照我的預期工作的測試步驟。 我所有的步驟都是用Ruby編寫的。

問題

我的問題是,當一切正常進行時,我希望能夠有一個能夠接受輸入的步驟。 我以為我可以只使用gets模塊,但是由於某種原因,它不等待任何用戶輸入,並且我只能在功能失敗后才能看到提示。 這是該步驟的代碼:

    When(/^I verify the device via text$/) do
  print "What's the Verify link?"
  link_to_app = gets.chomp
  sleep 20
  press_home_on_simulator
  sleep 1
  # for this next part you're gonna need this link:
  # https://github.com/moredip/Frank/issues/177
  # It's used to go out of the app and open an html doc in safari
  html_format = "<!DOCTYPE HTML><html><head><title></title><meta http-equiv=\"refresh\" content=\"0;URL='#{link_to_app}'\"></head><boßdy></body></html>"
  html = html_format
  require 'tempfile'
  file = Tempfile.new(['launch', '.html'])

  begin
    file.write(html)
    %x( /usr/bin/open "#{file.path}" -a "iPhone Simulator" )
  ensure
    file.close
    file.unlink
  end

  sleep 2
end

這基本上是為了獲得只能從SMS文本中獲取的鏈接,並允許我自動轉到模擬器中的該鏈接(此鏈接用於應用程序中的帳戶驗證)。 如我之前所說,它不會跳過提示並等待任何輸入,而是會跳過過去。

基本上,當我使用Frank和Cucumber時,如何使gets模塊工作並接受輸入?

謝謝

嘗試使用STDIN.gets,而不是普通的舊gets

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM