我需要能够使用我的Hudson构建运行我的Ruby脚本,但不希望尝试打开浏览器窗口.我试过了:
batman:ETW cmiller$ ./createAccount.rb -b
Run Code Online (Sandbox Code Playgroud)
但这没用.
如何使用FireWatir无头运行我的Ruby脚本?
在Mac OSX上运行
Summary of tools: watir-webdriver 1.8.17 Mac OS X 10.7.3 Chrome 18.0.1025.151
我目前正在使用Watir WebDriver在多个网站上自动执行Chrome会话.我需要在整个会话中的某些点备份Web浏览器的状态(cookie,缓存等).最初,我认为我可以通过复制~/Library/Application Support/Google/Chrome/Default
必要的点来使用Ruby的文件IO库来做到这一点.但是,使用Watir WebDriver创建的Chrome会话似乎不会将所需信息存储在此默认位置.如何找到这些数据进行备份?这些信息是否存储在别处?除了Watir之外还有什么可以让这更容易吗?
我从一年开始使用黄瓜,而且几周之后我就在它中添加了page-object-gem.当我执行测试时,我收到消息:
DEPRECATION WARNING
您正在commentPage.rb中调用一个名为checkbox的方法:23:在`delete in delete_comment'中.
此方法在页面对象中不存在,因此它将传递给驱动程序.
此功能将在不久的将来删除.
请更改您的代码以调用正确的页面对象方法.
(我对其他案例也有同样的看法,但这个"琐碎"的例子应该更容易解释)
我试图避免这种情况,但这看起来很复杂.
对于测试,我正在检查一个页面,其中有一个表格.每行显示一行,我需要检查特定行的复选框.
我在pageObject中的代码:
table(:comment_list, :class => 'comments')
button(:delete, :text => "Delete")
def delete_comment (text)
self.comment_list_element.each do |row|
if row.text.include? "#{text}"
row.checkbox.set
self.delete
return true
end
end
false
end
Run Code Online (Sandbox Code Playgroud)
我是否需要对我的桌子进行预处理以在测试期间使用它?
只是想知道,如何使用watir获取隐藏元素的值?这是元素:
<input type="hidden" value="randomstringhere" id="elementid" name="elementname" />
Run Code Online (Sandbox Code Playgroud)
这是我的代码atm:
require "rubygems"
require "watir-webdriver"
$browser = Watir::Browser.new :ff
$browser.goto("http://www.site.com")
$grabelement = $browser.hiddens(:id, "elementid")
$blah = $grabelement.attribute_value("value")
puts $blah
Run Code Online (Sandbox Code Playgroud)
这会停留在它返回的最后一行
code.rb:6:in `<main>': undefined method `attribute_value' for #<Watir::HiddenCollection:0x8818adc> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
对不起基本问题,我有一个搜索,找不到任何东西.
提前致谢!
我有一个模块,我已经包含在我的主要课程中:
module GenericPage
def check_url=(page)
puts(page)
end
end
Run Code Online (Sandbox Code Playgroud)
我创建了一个我的类的新实例,我在Cucumber中调用它
require_relative '../../../support/helper_methods'
class FindYourDealerPage
include GenericPage
def initialize(browser)
@browser = browser
end
def search_location=(location)
@browser.text_field(:id, 'findDealerSearchField').set(location)
@browser.send_keys :tab, :enter
end
Run Code Online (Sandbox Code Playgroud)
黄瓜:
Given /^I am on the find your dealer page$/ do
@browser.goto 'www.google.com'
@dealer.check_url('www.google.com')
@dealer = FindYourDealerPage.new(@browser)
end
When /^I select a desired preference$/ do
end
Then /^my filtered selection should be submitted$/ do
end
Run Code Online (Sandbox Code Playgroud)
当这个运行时,我得到一个错误NoMethodError: undefined method
check_url'为nil:NilClass`我在哪里出错了,忘记方法中的内容我想知道为什么我收到这个错误
我是Watir WebDriver的新手.我正在玩这个框架,我包括下面的代码,但第二行不起作用
$b = Watir::Browser.new :ie #browser
$b.goto "www.yahoo.com"
$b.link(:text => "Sign up").when_present.click
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它没有得到注册链接.我看到雅虎的消息来源如下
<span class="tab-caption small y-txt-2">New here? <a href="http://hsrd.yahoo.com/_ylt=A2KLtVHgLNtQHnMBTk.bvZx4/SIG=13tjppi7u/EXP=1356627552/**https%3A//edit.yahoo.com/registration%3F.src=fpctx%26.intl=us%26.done=http%253A%252F%252Fwww.yahoo.com%252F" class="y-link-1">Sign Up</a></span>
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题?我也试过没有when_present
,它说元素是不可见的.
我是新来的红宝石,我似乎已经成功安装watir-webdriver
和webdriver-user-agent
宝石,但是当我试图按照指示在这里我已经迷迷糊糊.如何进行?
>> require 'watir-webdriver'
=> true
>> require 'webdriver-user-agent'
=> true
>> driver = UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
NameError: uninitialized constant UserAgent
from (irb):3
from /usr/bin/irb:12:in `<main>'
Run Code Online (Sandbox Code Playgroud) 我正在编写一个测试脚本,打开一个文件,其中包含一个没有"www"和"com"的URL列表.
我试图读取每一行并将该行放入URL.然后我检查它是否重定向甚至存在.
我的问题是当我从文件中读取行并将其分配给变量时.然后,我在加载后与URL中的内容进行比较,以及我最初放在那里的内容,但它似乎是在我的变量之后添加一个返回.
基本上它总是说重定向,因为它放了" http://www.line \n.com/".
我该如何摆脱"\n"?
counter = 1
file = File.new("Data/activeSites.txt", "r")
while (line = file.gets)
puts "#{counter}: #{line}"
counter = counter + 1
browser.goto("http://www." + line + ".com/")
if browser.url == "http://www." + line + ".com/"
puts "Did not redirect"
else
puts ("Redirected to " + browser.url)
#puts ("http://www." + line + ".com/")
puts "http://www.#{line}.com/"
end
Run Code Online (Sandbox Code Playgroud)
基本上它总是说重定向因为它放了http://www.line然后返回.com /
我怎样才能摆脱回报呢?
我正在尝试使用Cheezy的页面对象gem来保持一致.但是我无法找到如何向下钻取这样的元素.这里的情况是,所有相同的标签会有多个链接,因此您必须从可识别的东西向下钻取.
@browser.p(:text => /#{app_name}/i).link(:text => 'Add').click
Run Code Online (Sandbox Code Playgroud)
我正在寻找的代码是这样的,点击段落内的链接,但它不起作用.
p(:pgraph, id: => 'some-pgraph')
link(:lnk, text: => 'add')
self.pgraph.lnk
Run Code Online (Sandbox Code Playgroud)
有没有办法用页面对象做到这一点?
谢谢,亚当
当我尝试安装watir时,我有以下错误,任何人都可以指导我如何解决这个问题?
C:\>gem install watir -v 4.0.2
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNRESET: An existing connection was forcibly closed by the remote
host. - SSL_connect (https://api.rubygems.org/api/v1/dependencies?gems=watir-webdriver)
Run Code Online (Sandbox Code Playgroud)
我使用的是Ruby 2.1.5和WATIR 4.0.2.