Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Watir/Rspec浏览器循环_Ruby_Rspec_Watir_Watir Webdriver - Fatal编程技术网

Ruby Watir/Rspec浏览器循环

Ruby Watir/Rspec浏览器循环,ruby,rspec,watir,watir-webdriver,Ruby,Rspec,Watir,Watir Webdriver,我需要一些帮助使用Watir/Rspec循环中的多个浏览器 我的目标是: 转到Google.ca 快速搜索 关闭浏览器 使用不同的浏览器循环步骤1-3 我可以使用Watir使其工作,但不知道如何使用Rspec使其工作 Watir(工作代码): Rspec(不工作): 以上代码就是这样的: 加载Firefox 去谷歌 装载铬 去谷歌 在Chrome上搜索 似乎当我加入Rspecdescripe时,循环并没有像我预期的那样工作。最终找到了答案:) 以下代码适用于希望在不为每个浏览器制定不同

我需要一些帮助使用Watir/Rspec循环中的多个浏览器

  • 我的目标是:
  • 转到Google.ca
  • 快速搜索
  • 关闭浏览器
  • 使用不同的浏览器循环步骤1-3
我可以使用Watir使其工作,但不知道如何使用Rspec使其工作

Watir(工作代码):

Rspec(不工作):

以上代码就是这样的:

  • 加载Firefox
  • 去谷歌
  • 装载铬
  • 去谷歌
  • 在Chrome上搜索
似乎当我加入Rspec
descripe
时,循环并没有像我预期的那样工作。

最终找到了答案:)

以下代码适用于希望在不为每个浏览器制定不同规格的情况下进行多浏览器测试的任何人

require 'watir-webdriver'
require 'rspec'

      browsers = [:ff, :chrome]
      browsers.map do |x|

        describe 'Browser' do

        before(:all) do
          @browser = Watir::Browser.new x
        end

        it 'goes to Google.ca' do
          @browser.goto('http://www.google.ca')
        end

        it 'searches' do
          @browser.text_field(:id, 'gbqfq').when_present(3).set 'Juventus'
          @browser.send_keys :enter
          sleep 0.5 #roughly takes 0.5s for the images to load. 
        end

        it 'closes browser' do
          @browser.close
        end
      end #end describe
    end #end loop
我认为要使其正常工作,您需要在
descripe
之后初始化浏览器,而在
descripe
之前初始化浏览器

require 'watir-webdriver'
require 'rspec'

  browsers = [:ff, :chrome]
  browsers.map do |x|
  $browser = Watir::Browser.new x
  $browser.goto('http://www.google.ca')

  describe 'loop' do
    it 'does something' do
      $browser.text_field(:id, 'gbqfq').set 'Juventus'
      $browser.send_keys :enter
      $browser.close
    end
  end #End describe
end #End loop
require 'watir-webdriver'
require 'rspec'

      browsers = [:ff, :chrome]
      browsers.map do |x|

        describe 'Browser' do

        before(:all) do
          @browser = Watir::Browser.new x
        end

        it 'goes to Google.ca' do
          @browser.goto('http://www.google.ca')
        end

        it 'searches' do
          @browser.text_field(:id, 'gbqfq').when_present(3).set 'Juventus'
          @browser.send_keys :enter
          sleep 0.5 #roughly takes 0.5s for the images to load. 
        end

        it 'closes browser' do
          @browser.close
        end
      end #end describe
    end #end loop