How to use same browser window for automated test using selenium-webdriver (ruby)?

后端 未结 3 690
孤城傲影
孤城傲影 2020-12-18 13:46

I am automating test cases for a website using selenium-webdriver and cucumber in ruby. I need each feature to run in a particular order and using the same browser window. A

3条回答
  •  太阳男子
    2020-12-18 14:12

    The Before hook is run before each scenario. This is why a new browser is opened each time.

    Do the following instead (in the env.rb):

    require "selenium-webdriver"
    
    driver = Selenium::WebDriver.for :ie
    accept_next_alert = true
    driver.manage.timeouts.implicit_wait = 30
    driver.manage.timeouts.script_timeout = 30
    verification_errors = []
    
    Before do
      @driver = driver
    end
    
    at_exit do
      driver.close
    end
    

    In this case, a browser will be opened at the start (before any tests). Then each test will grab that browser and continue using it.

    Note: While it is usually okay to re-use the browser across tests. You should be careful about tests that need to be run in a specific order (ie become dependent). Dependent tests can be hard to debug and maintain.

提交回复
热议问题