如何使用 selenium-webdriver (ruby) 使用相同的浏览器窗口进行自动化测试?

本文介绍了如何使用 selenium-webdriver (ruby) 使用相同的浏览器窗口进行自动化测试?的处理方法,对大家解决问题具有一定的参考价值

问题描述

我正在使用 ruby​​ 中的 selenium-webdriver 和 cucumber 为网站自动化测试用例.我需要每个功能以特定的顺序运行并使用相同的浏览器窗口.Atm 每个功能都会创建一个新窗口来运行测试.尽管在某些测试用例中这种行为是需要的——在许多情况下它不是.到目前为止,从我的研究来看,关于是否可以在整个测试用例中使用 selenium 驱动相同的浏览器窗口,似乎有不同的答案.我遇到的大多数答案都是针对其他语言的,并且是特定于浏览器的解决方法(我在测试 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 文件:

my env.rb file:

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

到目前为止,我收集了一些关于有类似问题的人的信息:https://code.google.com/p/selenium/issues/详细信息?id=18有吗有什么方法可以将已经运行的浏览器附加到 java 中的 selenium webdriver?

Some information I've gathered so far of people with similar problems: https://code.google.com/p/selenium/issues/detail?id=18 Is there any way to attach an already running browser to selenium webdriver in java?

如果我的问题不清楚,请向我提问.我有更多的测试要创建,但如果我的基础草率且缺少请求的功能,我不想继续创建测试.(如果您在我的代码中发现任何其他问题,请在评论中指出)

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)

推荐答案

Before 钩子在每个场景之前运行.这就是每次打开新浏览器的原因.

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.

这篇关于如何使用 selenium-webdriver (ruby) 使用相同的浏览器窗口进行自动化测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

在SketchUp中需要rubygems

我一直试图在网上搜索如何在SketchUp中使用rubygems,但一直没有找到具体的方法。下面是我在C:programfilesgoogle SketchUp 8中的插件插件宝石.rb:$: (eval):14C:/Ruby186/lib/ruby/1.8/thread.rb:5C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems.rb:11:in require\"C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems.rb:11(eval)...

日期:2021-06-29 00:00:03 浏览:710

用rubyapi计算Sketchup中阴影面积的问题

有人能帮我吗?现在我正在Sketchup中开发一个关于构建模拟的插件。可以显示阴影,但如何使用ruby API计算其面积。阴影通常描述不完整的照明(半阴影),如曲面侧面的阴影渐变。如果要测量一个区域,可能需要完整的阴影。阴影不是SketchUp实体或绘图元素。它们正在渲染输出,不能(直接)通过API访问。请参阅此处的解决方案50,将阴影绘制为面(但是会修改用户模型),然后对这些面的面积求和。请记住,嵌套组件可以按比例缩小/变换(或向上),因此面区域看起来比实际大小更大(更小)。在这种情况下,使用第二个参数来...

日期:2021-08-19 22:00:05 浏览:780

如何在rubyonrails应用程序中集成谷歌SketchUp

嗨,我是一个RubyonRails应用程序,我想在我的应用程序中集成sketchup。如果可能,请分享这些步骤或一些文档链接。不完全可能。谷歌SketchUp(Google SketchUp)在2012已不复存在,不再受支持。(谷歌把它卖给Trimble Navigation,Inc.)SketchUp、SketchUp Make和SketchUp Pro(由@Last、谷歌和Trimble发布)的所有版本都是桌面应用程序。这些版本的EULA 1禁止在服务器环境中使用,并明确禁止将SketchUp转授给其他...

日期:2021-08-28 11:00:05 浏览:928

保存从Sketchup模型中的非内置ruby类创建的实例

我正在尝试为室内设计师和家具制造商编写一个插件来维护橱柜数据库。所有关于橱柜的信息都将存储在MySql数据库中。在将它们插入模型之前,将根据我编写的适当类在Ruby中创建它们的实例。其思想是:要在Ruby中创建文件柜的实例,在那里处理它们,并且只在Sketchup中绘制为类:Sketchup::Group。当然,我需要Ruby中的实例和Sketchup中的绘图之间的链接。我的问题是:如何/在哪里存储用Ruby创建的实例,以便在重新加载模型后可用和创建。您做过类似的事情吗??在Ruby中创建的实例已经存储在模...

日期:2021-09-17 13:00:03 浏览:537

如何在sketchup中使用ruby知道两个组件相互接触?

如果任何两个组件相互接触,那么我可以使用哪个功能来检查它??对于API没有精确的冲突检测方法。这在过去被要求……- Ruby API类别搜索:\"冲突检测\"请参阅这些找到的主题以讨论解决方法。qwertyuiop:相互接触可能您还应该指定更确切地说,哪一个意思是\"触摸\"?图像603×545 12.1 KB...

日期:2021-09-19 19:00:05 浏览:614

如何使用 selenium-webdriver (ruby) 使用相同的浏览器窗口进行自动化测试?

本文介绍了如何使用 selenium-webdriver (ruby) 使用相同的浏览器窗口进行自动化测试?的处理方法,对大家解决问题具有一定的参考价值 问题描述 我正在使用 ruby​​ 中的 selenium-webdriver 和 cucumber 为网站自动化测试用例.我需要每个功能以特定的顺序运行并使用相同的浏览...

日期:2022-06-28 02:00:31 浏览:534

使用 ruby​​ 生成格式为/etc/shadow 的 SHA512 crypt-style hashes?

本文介绍了使用 ruby​​ 生成格式为/etc/shadow 的 SHA512 crypt-style hashes?的处理方法,对大家解决问题具有一定的参考价值 问题描述 I want to generate SHA512 hashed passwords for inclusion directly into a /...

日期:2022-07-11 04:00:26 浏览:521

therubyracer 安装错误

本文介绍了therubyracer 安装错误的处理方法,对大家解决问题具有一定的参考价值 问题描述 如下所示,libv8 可以正常安装,但 ruby​​racer 不能.我使用的是 Mac 10.7.4.As you can see below, libv8 installs fine, but therubyracer ...

日期:2022-07-19 06:00:35 浏览:670

“在任何存储库中都找不到有效的 gem"(rubygame 等)

本文介绍了“在任何存储库中都找不到有效的 gem"(rubygame 等)的处理方法,对大家解决问题具有一定的参考价值 问题描述 我一直在尝试安装这个rubygame"gem,但每当我使用命令时I've been trying to install this 'rubygame' gem for some time, bu...

日期:2022-07-25 11:00:26 浏览:596

安装 pg gem 失败,“mkmf.rb 找不到 ruby​​ 的头文件"(Mac OSX 10.6.5)

本文介绍了安装 pg gem 失败,“mkmf.rb 找不到 ruby​​ 的头文件"(Mac OSX 10.6.5)的处理方法,对大家解决问题具有一定的参考价值 问题描述 我刚刚升级到 Rails 3,在 MacPorts、gem 和数据库方面有些混乱需要整理.我扔掉了所有的宝石并重新安装它们.除了 pg gem 的要求...

日期:2022-08-12 21:00:35 浏览:777