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
- 三通基礎與例項
- Python入門基礎知識例項,Python
- android原生開發recyclerview基礎例項AndroidView
- Oracle PL/SQL 程式設計基礎 例項OracleSQL程式設計
- 基礎知識1——例項程式結構
- 閃回查詢(基礎例項講解)
- 基礎python5個例項運用Python
- javascript訂閱模式淺析和基礎例項JavaScript模式
- 閃回資料庫(基礎例項講解)資料庫
- 閃回事務查詢(基礎例項講解)
- 如何在多例項基礎上再新增一個mysql的例項MySql
- SpringBoot基礎系列之自定義配置源使用姿勢例項演示Spring Boot
- PHP常見陣列函式與例項[基礎]]PHP陣列函式
- 基礎知識1——例項記憶體結構記憶體
- python爬蟲之Beautiful Soup基礎知識+例項Python爬蟲
- 3節點rac基礎上配置goldengate(單例項)Go單例
- 分享交換機 VLAN 配置基礎及例項探討(轉)
- pinctrl使用例項
- 前端基礎功能,原生js實現輪播圖例項教程前端JS
- RAC 例項 遷移到 單例項 -- 使用RMAN Duplicate單例
- tunna工具使用例項
- Tee命令使用例項
- awk命令使用例項
- flex的使用例項Flex
- DHTML Tree 使用例項HTML
- 【機器學習基礎】GBDT--梯度提升樹例項分析完全解讀機器學習梯度
- Expression Blend例項中文教程(7) - 動畫基礎快速入門AnimationExpress動畫
- Java基礎-單例模式Java單例模式
- 用例基礎知識
- 基於MySQL的Apache使用者認證例項(轉)MySqlApache
- Flutter繪製-12-動畫專項-基礎使用篇Flutter動畫
- 零基礎學習 Python 之細說類屬性 & 例項Python
- ASP.NET Web Pages基礎知識---Razor 例項:顯示圖片ASP.NETWeb
- [.net 物件導向程式設計基礎] (9) 類和類的例項物件程式設計
- Android Studio1.4.x JNI開發基礎 - 簡單例項Android單例
- cut命令的使用例項
- restorecon 命令使用例項REST