本文介绍了如何使用自动化测试同一个浏览器窗口中使用硒的webdriver(红宝石)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自动测试案例使用硒的webdriver和黄瓜红宝石网站。我需要在每个功能在一个特定的顺序运行,并使用相同的浏览器窗口。 ATM每个功能创建一个新的窗口中,虽然在某些情况下,测试这种行为是在许多情况下desired-它不运行测试。从我的研究,到目前为止,似乎有关于它是否可以驱动整个测试用例硒同一个浏览器窗口的混合答案。我所遇到的大多数的答案是对其他语言和具体针对浏览器变通(我发展我的测试,而测试的IE浏览器,但将有望运行在其他浏览器这些测试)。我在Ruby中工作,从我读它好像我不得不做出的页面一类?我很困惑,为什么我就必须这样做还是怎么没有什么帮助。

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. Atm each feature creates a new window to run test in. Though in some test cases this behavior is desired- in many cases it is not. From my research so far it seems there are mixed answers about whether or not it is possible to drive the same browser window with selenium throughout test cases. Most answers I have run into were for other languages and were work arounds specific to a browser (I am developing my test while testing IE but will be expected to run these test in other browsers). I am working in Ruby and from what I have read it seems as though I'd have to make a class for the page? I'm confused as to why I would have to do this or how that helps.

我env.rb文件:

require 'selenium-webdriver'
require 'rubygems'
require 'nokogiri'
require 'rspec/expectations'

Before do

    @driver ||= Selenium::WebDriver.for :ie
    @accept_next_alert = true
    @driver.manage.timeouts.implicit_wait = 30
    @driver.manage.timeouts.script_timeout = 30
    @verification_errors = []
  end

  After do
    #@driver.quit
    #@verification_errors.should == []
  end

某些信息到目前为止,我已经收集的人有类似的问题:

Is有什么办法可以一个已经运行的浏览器连接到硒的webdriver在Java?

请问我问题,如果对我的问题有什么不太明白。我有很多更多的测试来创建,但我不希望在创建测试,如果我的基础是草率和缺失的功能要求移动。 (如果你注意到我的code中的任何其他问题,请指出它们在评论)

Please ask me questions if anything about my question is not clear. I have many more test to create but I do not want to move on creating test if my foundation is sloppy and missing requested capabilities. (If you notice any other issues within my code please point them out in a comment)

推荐答案

之前 挂钩每个方案之前运行。这就是为什么新的浏览器每次都打开了。

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

执行以下操作来代替(在env.rb):

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.

这篇关于如何使用自动化测试同一个浏览器窗口中使用硒的webdriver(红宝石)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 10:06