Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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 Don';t在MiniTest中为每个测试重新加载无头webdriver_Ruby_Watir Webdriver_Minitest_Headless Browser - Fatal编程技术网

Ruby Don';t在MiniTest中为每个测试重新加载无头webdriver

Ruby Don';t在MiniTest中为每个测试重新加载无头webdriver,ruby,watir-webdriver,minitest,headless-browser,Ruby,Watir Webdriver,Minitest,Headless Browser,我正在使用headless watir webdriver和MiniTest进行浏览器测试。那很好。然而,有一件事让我不满意。在每次测试之前,我反复加载无头浏览器。我更喜欢加载一次并一直使用它 有可能吗 下面是一个简短的例子: require 'watir-webdriver' require 'headless' require 'minitest/autorun' class TestMe < MiniTest::Test def setup $headless = H

我正在使用headless watir webdriver和MiniTest进行浏览器测试。那很好。然而,有一件事让我不满意。在每次测试之前,我反复加载无头浏览器。我更喜欢加载一次并一直使用它

有可能吗

下面是一个简短的例子:

require 'watir-webdriver'
require 'headless'
require 'minitest/autorun'

class TestMe < MiniTest::Test

  def setup
    $headless = Headless.new
    $headless.start
    $b = Watir::Browser.new :firefox
    $b.goto  'http://www.google.com'
    puts "Browser loaded"
  end

  def teardown
    $b.close
    $headless.destroy
  end

  def test_that_page_is_google
    assert_equal "Google", $b.title
  end

  def test_something
    assert ( $b.span(:id => 'gbqfsa').exists?), ">>Fail Google search button exists"
  end

end
需要“watir webdriver”
要求“无头”
需要“微型测试/自动运行”
类TestMe'gbqfsa')。是否存在?“>>谷歌搜索失败按钮是否存在”
结束
结束
您将看到“已加载浏览器”打印了两次


欢迎任何意见,谢谢

设置和拆卸方法在MiniTest中的每个测试前后运行。 您所寻找的是在整个测试套件之前和之后运行的东西

请在此处查看答案: