Watir基礎使用例項
HelloWorld
require 'watir'
test_site = 'http://blog.csdn.net/testing_is_believing/'
# open the IE browser
ie = Watir::IE.new
# print some comments
puts "## Beginning of test"
puts " "
puts "Step 1: go to the test site: " + test_site
ie.goto(test_site)
puts " Action: entered " + test_site + " in the address bar."
google 測試例子
require 'watir'
ie = Watir::IE.start("http://www.google.cn")
ie.text_field(:name,"q").set("Watir")
ie.button(:name,"btnG").click
link
require 'watir'
ie = Watir::IE.start("http://blog.csdn.net/testing_is_believing")
ie.link(:url , "http://blog.csdn.net/Testing_is_believing/category/647265.aspx").click
檢查點
contains_text
require 'watir'
ie = Watir::IE.start("http://blog.csdn.net/testing_is_believing")
ie.link(:url , "http://blog.csdn.net/Testing_is_believing/category/647265.aspx").click
if ie.contains_text("HelloWorld - Watir")
puts "Test passed. Page contains the text: HelloWorld - Watir"
else
puts "Test failed! Page didn't contain text: HelloWorld - Watir"
end
assert
require 'watir'
require 'test/unit'
class TC_myTest < Test::Unit::TestCase
def setup
puts "starting a testcase..."
end
def test_1_blog
ie = Watir::IE.new
ie.goto("http://blog.csdn.net/testing_is_believing")
ie.link(:url , "http://blog.csdn.net/Testing_is_believing/category/647265.aspx").click
assert(ie.contains_text("HelloWorld - Watir"))
end
def test_2_google
ie = Watir::IE.new
ie.goto("http://www.google.cn")
ie.text_field(:name,"q").set("Watir")
ie.button(:name,"btnG").click
end
def teardown
puts "just finish running a testcase!"
end
end
Why are my test cases running in the wrong order?
Subclassing Test::Unit::TestCase will make your tests run in alphabetical order. Therefore in the case of this code:
class SampleTest < Test::Unit::TestCase
def test_login
# login test code, etc
end
def test_account
# account test code, etc
end
end
The second test, test_account , will run before test_login .
To run the tests in the order they are defined in the suite, subclass Watir::TestCase instead.
class SampleTest < Watir::TestCase
def test_login
# login test code, etc
end
def test_account
# account test code, etc
end
end
How to run a specific test case?
ruby my_test_file.rb --name test_account
命令列執行
Running Tests With the Browser Not Visible
Run the tests with a "-b" option if you don't want the browser to be visible. ex. myTest.rb -b
WATIR supports command-line options:
-b (background) Run Internet Explorer invisibly -f (fast) By default, WATIR types slowly and pauses briefly between
actions.
This switch removes the delays and sets WATIR
to run at full speed.
The set_fast_speed method of the
IE object performs the same function; set_slow_speed
returns WATIR to its default behaviour.
視窗處理
require 'watir'
ie = Watir::IE.start("http://blog.csdn.net/testing_is_believing")
ie.link(:url , "http://hi.csdn.net/!s/wall/to/Testing_is_believing").click
sleep(2)
ie2 = Watir::IE.attach(:url,'http://hi.csdn.net/space.php?do=wall&view=me&username=Testing_is_believing')
if ie2.contains_text(" 給自己留言 ")
puts "Pass 1!"
end
ie.link(:url , "http://hi.csdn.net/!s/msg/to/Testing_is_believing").click
sleep(2)
#ie3 = Watir::IE.attach(:title," 陳能技 - CSDN 個人空間 - Powered by UCenter Home")
ie3 = Watir::IE.attach(:title,/ 陳能技 /)
if ie3.contains_text(" 內容 ")
puts "Pass 2!"
end
相關文章
- Python基礎——切片例項Python
- 三通基礎與例項
- android原生開發recyclerview基礎例項AndroidView
- Python入門基礎知識例項,Python
- 基礎python5個例項運用Python
- SpringBoot基礎系列之自定義配置源使用姿勢例項演示Spring Boot
- javascript訂閱模式淺析和基礎例項JavaScript模式
- python爬蟲之Beautiful Soup基礎知識+例項Python爬蟲
- PHP常見陣列函式與例項[基礎]]PHP陣列函式
- pinctrl使用例項
- expect使用例項
- msfvenom使用例項
- tunna工具使用例項
- awk命令使用例項
- restorecon 命令使用例項REST
- Tee命令使用例項
- 前端基礎功能,原生js實現輪播圖例項教程前端JS
- 零基礎學習 Python 之細說類屬性 & 例項Python
- C# IDispose使用例項C#
- docker-compose 使用例項Docker
- cut命令的使用例項
- 用例基礎知識
- Java基礎-單例模式Java單例模式
- ASP.NET Web Pages基礎知識---Razor 例項:顯示圖片ASP.NETWeb
- MyBatis基於Maven入門例項MyBatisMaven
- Linux中printf命令使用例項Linux
- Memcached安裝與使用例項
- iptables 常用規則使用例項
- Composer 使用 JWT 生成 TOKEN 例項JWT
- 【機器學習基礎】GBDT--梯度提升樹例項分析完全解讀機器學習梯度
- Python例項大全(基於Python3.7.4)Python
- 基於laravel的事件監聽例項Laravel事件
- Flutter繪製-12-動畫專項-基礎使用篇Flutter動畫
- ActiveMQ的使用及整合spring的使用例項MQSpring
- Linux 中的 JQ 命令使用例項Linux
- Linux 中 ss 命令的使用例項Linux
- Linux中ip命令的使用例項Linux
- Tee命令的幾個使用例項
- Linux中的basename命令使用例項Linux