Watir Syntax学习笔记

Ruby: object-oriented scripting language.

Watir: Web Application Testing in Ruby.

 

Require the Watir Tool:

require ‘watir’

 

Create a Test Instance of Internet Explorer:

ie = Watir::IE.new

 

Create an instance of Internet Explorer and navigate to the site with one statement:

ie = Watir :: IE.start(“http://www.google.com”)

 

Site Navigation:

ie.goto(“http://www.google.com”)

 

Text Fields:

<input type = “text”  id = “one”  name = “typeinme”>

 

id Attribute:

ie.text_field(:id, “one”).set (“Ruby”)

ie.text_field(:id, “one”).clear

 

name Attribute:

ie.text_field(:name, “typeinme”).set “Ruby”

ie.text_field(:name, “typeinme”).clear

 

Tips and Tricks:

Running Tests With the Browser Not Visible:

my_test.rb –b

 

$HIDE_IE =true

ie = Watir::IE.new()

 

How do I get the version numbers of Ruby and Watir?

Go to command prompt.

ruby version: ruby –v

watir version: ruby –e ‘require “watir”; puts Watir::IE::VERSION’

 

How to keep command prompt window open after tests are finished?

Do not run your Watir script by double clicking it. Instead, open command prompt, navigate to folder where script is located and execute the script from there.

你可能感兴趣的:(watir)