我正在编写一个watir脚本来测试上传表单.
但是脚本不会自动选择要从我的硬盘上传的文件.
相反,IE会在文件选择器对话框打开时停止.只要我在对话框中手动选择要上传的文件并单击"确定",watir就会根据需要继续.我想知道为什么它会停止.
这是我的watir脚本:
require 'test/unit'
require 'watir'
# runs on win3k, IE 6.0.3790; ruby 1.8.6, watir
class EpcHomePage < Test::Unit::TestCase
def test_upload
ie = @browser
htmlfile = "C:\\testing\\upload.html"
uploadfile = "C:\\testing\\upload.html"
ie.goto(htmlfile)
ie.file_field(:name,"file1").set(uploadfile)
assert_equal uploadfile, ie.file_field(:name,"file1").value
ie.button(:name, 'upload').click
end
def setup
@browser = Watir::IE.new
end
def teardown
@browser.close
end
end
Run Code Online (Sandbox Code Playgroud)
我从这个页面得到了代码:http://wiki.openqa.org/display/WTR/File+Uploads
这是形式:
<html><body>
<form name="form1" enctype="multipart/form-data" method="post" action="upload.html">
<input type="file" name="file1">
<input type="submit" name="upload" value="ok">
</form>
</body></html>
Run Code Online (Sandbox Code Playgroud)
我也找到了这本手册http://svn.openqa.org/svn/watir/trunk/watir/unittests/filefield_test.rb.我正在使用IE 6和IE 7进行测试.
编辑:我在这里上传了我的简单示例(3个文件位于我的机器上的c:\ testing \中,只需启动cmd文件): …
我正在评估Watir-webdriver,以决定我是否可以切换到使用它进行我的浏览器测试(主要来自Watir),其中一个关键的事情就是能够与TinyMCE WYSIWYG编辑器进行交互,作为一些应用程序我使用TinyMCE.我设法让以下解决方案工作 -
@browser = Watir::Browser.new(:firefox)
@browser.goto("http://tinymce.moxiecode.com/tryit/full.php")
autoit = WIN32OLE.new('AutoITX3.Control')
autoit.WinActivate('TinyMCE - TinyMCE - Full featured example')
@browser.frame(:index, 0).body.click
autoit.Send("^a") # CTRL + a to select all
autoit.Send("{DEL}")
autoit.Send("Some new text")
Run Code Online (Sandbox Code Playgroud)
这种方法的缺点是,通过使用autoit,我仍然依赖于Windows,并且跨平台运行测试的能力是webdriver的吸引力之一.
我注意到一些具体的webdriver解决方案,如从下面的主题:
String tinyMCEFrame = "TextEntryFrameName" // Replace as necessary
this.getDriver().switchTo().frame(tinyMCEFrame);
String entryText = "Testing entry\r\n";
this.getDriver().findElement(By.id("tinymce")).sendKeys(entryText);
//Replace ID as necessary
this.getDriver().switchTo().window(this.getDriver().getWindowHandle());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.getDriver().findElement(By.partialLinkText("Done")).click();
Run Code Online (Sandbox Code Playgroud)
看起来它可能跨平台工作,但我不知道是否可以从Watir-webdriver中访问相同的功能.我的问题是,有没有办法使用watir-webdriver编写,删除和提交到TinyMCE,这不会强制依赖特定支持的浏览器或操作系统?
我正在使用Watir-webdriver,我想知道是否有一个好方法来检查是否有新窗口打开.我已经google了一下,虽然感觉应该有一个简单的答案,但找不到任何东西.
我有一个打印机友好的链接,我想测试链接在新窗口或选项卡中打开,我想用ie,firefox,chrome和safari进行测试,如果可能的话.
谢谢!
我是Ruby的新手,非常感谢帮助理解这里发生了什么.
摘要:
宝石安装watir-webdriver
安装精细
启动irb
需要"watir-webdriver"
... LoadError:没有这样的文件加载--watir-webdriver
当然这应该回应
=> true
Run Code Online (Sandbox Code Playgroud)
为什么找不到宝石?或者我做错了什么?
我在win7上,Railsinstaller(Ruby 1.8.7).
我正在使用Teamcity 6.5.6,并寻找一种在构建代理上自动安装所需的ruby GEMS的方法.对于Ex:假设我在每个代理/远程(构建)机器上都需要两个宝石.例如:Watir和Selenium宝石.那么我想通过登录到这些机器来手动安装它们,或者我可以将它们保存在SVN中的公共库文件夹中,并在Teamcity中执行一些任务以在机器上不存在时安装它们.如果是这样,那么Teamcity中的任务是什么?
谢谢
我整天都在使用Cucumber,即使我没有更改任何文件,它也停止了工作.
它给出了一个错误,内容如下:
Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome (Selenium::WebDriver::Error::UnknownError)
有什么想法,发生了什么事?
非常积极的你必须使用.清楚,或者可能不是因为它似乎不适合我,也许我只是执行它错了我不确定.
例:
browser.div(:id => "formLib1").clear.type("input", "hi")
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何简单地清除一个字段然后输入一个新的字符串?
对于我正在处理的项目,我需要伪造一个IP地址,以显示我来自其他国家/地区.
基本上,如果检测到的IP来自英国,则显示弹出窗口A,如果检测到的IP来自英国以外,则显示弹出窗口B.
我希望能够实现自动化.目前我们所有的浏览器自动化测试都是用cucumber/watir编写的,我想得到一个使用相同框架的解决方案.
有谁知道这样做的可行方法?
谢谢!
如何使用watir保存网站图像,而无需使用open-uri或类似版本重新加载?
我:我不能用的原因
File.open(file_name, 'wb') do |f|
f.write open(img.src).read
end # file open
Run Code Online (Sandbox Code Playgroud)
是图像是在当前(登录)会话中生成的,只有一次,因此无法进行"外部"第二次访问.
II:
browser.images.save()
- 仅用于ie - 也没有帮助,它打开了保存对话框.所以它对自动化如此无用.
示例:http://wiki.openqa.org/display/WTR/Save+All+Images+on+a+Webpage
require 'watir'
browser = Watir::Browser.new :ie
browser.goto 'http://google.com'
idx = 0
browser.images.each do |x|
puts idx
idx += 1
location = 'c:\tmp\file-' + idx.to_s + '.jpg'
x.save(location)
end
Run Code Online (Sandbox Code Playgroud)
github来源:http://rubydoc.info/github/watir/watir-classic/Watir/Image
# File 'lib/watir-classic/image.rb', line 48
def save(path)
@container.goto(src)
begin
fill_save_image_dialog(path)
@container.document.execCommand("SaveAs")
ensure
@container.back
end
end
Run Code Online (Sandbox Code Playgroud)
我最好的想法是使用代理获取所有图像.但也许有一种"轮流方式".
环境:
# ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
# …
Run Code Online (Sandbox Code Playgroud) 我试图在网站上自动进行在线调查,但每次都会出现此错误:
Selenium::WebDriver::Error::UnknownError: unknown error: Element is not clickable at
point (561, 864). Other element would receive the click: a id="habla_oplink_a"
class="habla_oplink_a_normal hbl_pal_header_font_size hbl_pal_title_fg "
Run Code Online (Sandbox Code Playgroud)
我需要了解的是如何滚动到页面的某个点,以便我的脚本可以恢复填写页面上的调查.
这是我的代码,它设法填写调查的一部分,但是当它到达浏览器内部不在视图中的行(需要用户向下滚动到的行)时失败:
buttons = browser.elements(:class => "assessment-choice")
buttons.each do |button|
button.click
end
Run Code Online (Sandbox Code Playgroud)
我还希望能够更改我的代码,以便它只选择一个特定的选项,但页面上的HTML不是很友好.
这是我正在查看的网页:https://staging2.clearfit.com/assessment/assessment/95867fb272df436352a0bd5fbdd
调查中其中一个选项的HTML:
<a id="answers_79_0" class="assessment-choice" onmouseover="answerOver(this)" onmouseout="answerOut(this)" onclick="setAssessmentAnswer(this, 3, '0', '79', '#answers_49839163')">Strongly<br>Agree</a>
Run Code Online (Sandbox Code Playgroud)