Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Selenium Ruby Web Driver Example

Using Ruby Web Driver gem, we can develop automated tests.  We use Mahare ePorfolio site as test example application.

Test Case

Authorized users are able to login Mahara Demo site. Here are test steps.

Test Steps

1.Navigate to demo.mahara.org and verify that web page title "Home-Mahara" displays.
2.Enter "student2" in the Username filed.
3. Enter "Testing1" in the Password field.

4.Click on the Login button
5.Assert that Logout link is present.
6.Click on the Logout link
7.Wait for login button is displayed.

Test Implementation

Open a Ruby Programming IDE and write the code below.

require 'selenium-webdriver'
    #define driver for firefox webdriver
driver=Selenium::WebDriver.for :firefox
    #maximize the window
driver.manage.window.maximize

    #navigate to the test site
driver.navigate.to "http://demo.mahara.org"

    #define username field element
loginUserName=driver.find_element(:id,'login_login_username')
    #input user name
loginUserName.send_keys('Student2')

    #define password field element
loginPassword=driver.find_element(:id,'login_login_password')
    #input password
loginPassword.send_keys('Testing1')

    #define submit button element
loginSubmitButton=driver.find_element(:id,'login_submit')
    #click on submit button
loginSubmitButton.click

    #wait until the Logout link displays, timeout in 10 seconds
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until {driver.find_element(:link_text => "Logout") }

    #define logout link
logoutLink=driver.find_element(:link_text,'Logout')
    #if logout link is displayed
isLogoutLinkDisplayed=logoutLink.displayed?

puts isLogoutLinkDisplayed

    #quit the driver
driver.quit

Execute the unit test and see the result below

true

Process finished with exit code 0

Logout link display is true. The test passed. By following the pattern, you can add steps to run many tests sequentially without using unit test framework