4.3. Getting Started

简介:

Quick Start

create a testing script

4.3.1. firewatir

例 4.1. watir firewatir example

				
$ cat google.rb
require 'rubygems'
require 'watir'
require 'firewatir'

browser = Watir::Browser.new
browser.goto 'http://google.com'
browser.text_field(:name, 'q').set 'Ruby'
browser.button(:name, 'btnG').click
if browser.text.include? 'Ruby Programming Language'
  puts 'Text was found'
else
  puts 'Text was not found'
end
				
				

run test

				
$ irb google.rb

google.rb(main):001:0> require 'rubygems'
=> true
google.rb(main):002:0> require 'watir'
=> true
google.rb(main):003:0> require 'firewatir'
=> true
google.rb(main):004:0>
google.rb(main):005:0* browser = Watir::Browser.new
=> #<FireWatir::Firefox:0x7f797dd2b880 url="http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=1440&bih=660&q=Ruby&btnG=Google+%E6%90%9C%E7%B4%A2&aq=f&aqi=g10&aql=&oq=" title="Ruby - Google \346\220\234\347\264\242">
google.rb(main):006:0> browser.goto 'http://google.com'
=> #<FireWatir::Firefox:0x7f797dd2b880 url="http://www.google.com.hk/" title="Google">
google.rb(main):007:0> browser.text_field(:name, 'q').set 'Ruby'
=> 0
google.rb(main):008:0> browser.button(:name, 'btnG').click
=> 0
google.rb(main):009:0> if browser.text.include? 'Ruby Programming Language'
google.rb(main):010:1>   puts 'Text was found'
google.rb(main):011:1> else
google.rb(main):012:1*   puts 'Text was not found'
google.rb(main):013:1> end
Text was found
=> nil
				
				

4.3.2. watir-webdriver

例 4.2. watir-webdriver example

require 'watir-webdriver'

browser = Watir::Browser.new
browser.goto 'http://www.google.com.hk'
browser.text_field(:name => 'q').set 'netkiller'
browser.button(:name => 'btnK').click

if browser.text.include? 'Neo'
  puts 'Text was found'
else
  puts 'Text was not found'
end
browser.close()
				

例 4.3. watir-webdriver remote

require 'watir-webdriver'

browser = Watir::Browser.new :remote, :url => "http://192.168.2.44:4444/wd/hub", :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome

browser.goto 'http://www.google.com.hk'
browser.text_field(:name => 'q').set 'netkiller'
browser.button(:name => 'btnK').click

if browser.text.include? 'Neo'
  puts 'Text was found'
else
  puts 'Text was not found'
end
browser.close()
				

comments powered by Disqus


原文出处:Netkiller 系列 手札

本文作者:陈景峯

转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。


目录
相关文章
|
安全 Ubuntu 测试技术
l4re Getting started
l4re Getting started
365 0
|
6月前
|
负载均衡 Java 应用服务中间件
Client not connected, current status:STARTING
Client not connected, current status:STARTING
549 1
Veloce 之 Getting Started
Veloce 之所以能够加速仿真,原因是Veloce把DUT(Design Under Test) 和 TB(TestBench) 一起综合成实际的电路,然后下载到Veloce硬件中,在硬件上跑,所以是比软件仿真快得多。 那么怎样才能把Veloce用起来,让它来加速我们的仿真呢?
Veloce 之 Getting Started
|
XML Android开发 数据格式
MPAndroidChart 教程:开始 Getting Started
入门 本章介绍使用此库的基本设置。 添加依赖 首先,将此库的依赖项添加到项目中。如何执行此操作在此存储库的用法部分中进行了描述。
1928 0
|
JavaScript Linux 前端开发
|
网络安全 开发工具
|
Linux 网络安全