Watir web automated tests

Post on 06-May-2015

10.409 views 0 download

Tags:

description

Watir is an open-source Ruby libraries. It drives browsers the same way people do no matter what technology it is developed in. This video will guide you on how to write test scripts using Watir for web application testing using across different browsersThere are 6 test scenarios in this demo:- The 1st scenario is Test with Microsoft page -- launch some pages from this site and check Search functions.- The 2nd scenario is Test with Yahoo page -- Sending email- The 3rd scenario is Test with Apple page -- Online Shopping- The 4th scenario is Test with YouTube page -- Browse and Upload video- The 5th scenario is Test with SlideShare page -- Download and upload presentation- The last scenario is Test with Facebook page -- Share info and chatFor each scenario, we will present 'how to implement' in detail step. At the end of each case, the test script will be run to show test results.Any support, please contact us at http://www.nexlesoft.com

Transcript of Watir web automated tests

WATIR Web Automated

Tests Demo

Jun, 2012

TEST SCENARIOS

WATIR

Scenario 1

Scenario 2

Scenario 3

Scenario 4

Scenario 5

Scenario 6

SCENARIO OVERVIEW

Scenario Overview

• Scenario 1: Test on Microsoft page – launch some pages from this site and check Search function.

• Scenario 2: Test on Yahoo page – check Sending Mail.

• Scenario 3: Test on Apple page – check Online Shopping.

• Scenario 4: Test on Youtube page – check Browse and Upload videos.

• Scenario 5: Test on SlideShare page – check Download and Upload presentation.

• Scenario 6: Test on Facebook page – check Share info and Chat.

TEST SCENARIO 1

Test with Microsoft page

• Step 1: Open Internet Explorer

• Step 2: Go to http://www.microsoft.com/en-us/default.aspx

• Step 3: Launch Windows tab

• Step 4: Select an item in the dialog

• Step 5: Validate and make sure the selected item opens a new page

• Step 6: Repeat the same for other menu items

• Step 7: Get key words from data file (contains 10 key words) and put into the Search text box

• Step 8: Click on Search button or press Enter

• Step 9: Validate that results returned in the Search result page contain the input key word

• Step 10: Move on next result page to find other results

• Step 11: Repeat the test for Chrome and Firefox

TEST SCENARIO 1

How to implement? (START SCRIPT)

require "watir-webdriver" include Watir require 'logger‘ #path store file: script, data file, logs… path = File.dirname(__FILE__) #create log file name_log = 'TEST_Scenario_1' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file)

TEST SCENARIO 1

How to implement? (Step 1 -> Step 4)

Step 1: #Step 1: Open Internet Explorer browser = Watir::Browser.new :ie

Step 2: #Step 2: Go to http://www.microsoft.com/en-us/default.aspx test_site = 'http://www.microsoft.com/en-us/default.aspx' browser.goto(test_site)

Step 3: #Step 3: Launch Windows tab browser.li(:xpath, "//li[contains(@id, 'ctl00_ctl14_ItemsRepeater_ctl01_MenuItem')]").link(:xpath, "//a[contains(@href, 'mnui=1')]").click

Step 4: #Step 4: Select Windows Phone item in the dialog browser.ul(:id=>"ctl00_ctl14_ItemsRepeater_ctl01_Level2Columns_ctl00_Level2Repeater_ctl00_Level3List").link(:text=>"Windows Phone").click #Windows Phone item is clicked.

TEST SCENARIO 1

How to implement? (Step 5 -> Step 6)

Step 5: #Step 5: Validate and make sure the selected item opens a new page Wait.until {browser.title.include? "Windows Phone"} #Check window title include text logger.info ("=> PASS. Window title: ") + browser.title

Step 6: #Back to site http://www.microsoft.com/en-us/default.aspx browser.back #Launch Products tab browser.li(:xpath, "//li[contains(@id, 'ctl00_ctl14_ItemsRepeater_ctl00_MenuItem')]").link(:xpath, "//a[contains(@href, 'mnui=0')]").click #Select 'Windows Phone' item in the dialog browser.ul(:id=>"ctl00_ctl14_ItemsRepeater_ctl00_Level2Columns_ctl00_Level2Repeater_ctl00_Level3List").link(:text=>"Windows Phone").click #Validate and make sure the selected item opens a new page Wait.until {browser.title.include? "Windows Phone"} logger.info ("=> PASS. Window title: ") + browser.title #Window title: Windows Phone | Cell Phones, Mobile…

TEST SCENARIO 1

How to implement? (Step 7 -> Step 10)

Step 7 -> Step 10 # Step 7: Get key words from data file require path + '/Xls.rb' #Read data from excel file xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:B11', 'search_key') #pull data records from excel xlFile.close #Step 7, 8: Input data to Search textbox and click Search button myData.each do |record| if record['key'] != "“ # record key in data file is not blank. if browser.text_field(:id, /searchInput/).exists? browser.text_field(:id, /searchInput/).set(record['key']) #input search key browser.input(:id=>/searchButton/).click #click Search button else browser.text_field(:id, /boxResultsSearch/).set(record['key']) #input search key browser.input(:id=>/btResultsSearch/).click #click Search button end

TEST SCENARIO 1

How to implement? (Step 7 -> Step 10) cont.

Step 7 -> Step 10 (cont): #Step 9: Validate that results returned in the Search result page contain the input key word Wait.until {browser.title.include? "Search results page"} #Search result is displayed. Wait.until {browser.div(:id=>/ResultsArea/).exists?} #If search key has 2 words, need to separate word. Example: ‘Window Vista’ skey = record['key'].split(" ") fresult = false #Validate search result include search key or not skey.each do |key| if browser.div(:id=>/ResultsArea/).text.include? key fresult = true break end end if fresult #search results contain search key logger.info ("=> PASS. Search content contains input key word") else logger.info ("=> FAIL. Search content does NOT contain input key word") end

TEST SCENARIO 1

How to implement? (Step 7 -> Step 10) cont.

Step 7 -> Step 10 (cont): #Step 10: Move on next result page to find other results #check whether search result has more 1 page or note if browser.div(:id=>/ResultsArea/).link(:id=>/NavigationLink/,:text=>"2").exists? #If have more 1 page, click the 2nd page browser.div(:id=>/ResultsArea/).link(:id=>/NavigationLink/,:text=>"2").click Wait.until {browser.title.include? "Search results page"} Wait.until {browser.div(:id=>/ResultsArea/).exists?} #Check search result of next page is displayed. if browser.div(:id=>/ResultsArea/).text.include? '11-20 out of' logger.info ("=> PASS. Search result of next page is displayed") #If search key has 2 words, need to separate word. Example: ‘Window Vista’ skey = record['key'].split(" ") fresult = false #Validate search result include search key or not skey.each do |key| if browser.div(:id=>/ResultsArea/).text.include? key fresult = true break end end

TEST SCENARIO 1

How to implement? (Step 7 -> Step 10) cont.

Step 7 -> Step 10 (cont): #Step 10: Move on next result page to find other results (cont.) if fresult #search results contain search key #return message when search content of next page contains input key word logger.info ("=> PASS. Search content of next page contains input key word") else #return message when search content of next page does NOT contain input key word logger.info ("=> FAIL. Search content of next page does NOT contain input key word") end else #return message when search result of next page is NOT displayed logger.info ("=> FAIL. Search result of next page is NOT displayed") end else #return message when search result doesn’t have more 1 page logger.info ("=> Search result have NO the next page.") end end end

TEST SCENARIO 1

How to implement? (END SCRIPT)

RUN SCRIPT

TEST SCENARIO 2

Test with Yahoo page – Sending email

• Step 1: Open Internet Explorer

• Step 2: Navigate to http://mail.yahoo.com/

• Step 3: Login with a valid account.

• Step 4: Check “Keep me signed in ” checkbox

• Step 5: Click on Sign In button

• Step 6: Compose an sample email and click Sent

• Step 7: Navigate to Sent item and make sure the sent email is in this folder

• Step 8: Sign out

• Step 9: Repeat the test for Firefox and IE

TEST SCENARIO 2

How to implement? (START SCRIPT)

require "watir-webdriver" include Watir require 'logger‘ #path store file: script, data file, logs… path = File.dirname(__FILE__) #read data from source file (.xlsx file) xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:D3', 'login') #pull data records from excel xlFile.close #create log file name_log = 'TEST_Scenario_2' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file)

TEST SCENARIO 2

How to implement? (Step 1 -> Step 2)

Step 1: #Step 1: Open Internet Explorer logger.info "::::" + name_log + " | START TESTING on IE" logger.info ("Step 1: Open Internet Explorer") browser = Watir::Browser.new :ie

Step 2: #Step 2: Navigate to http://mail.yahoo.com/ logger.info ("Step 2: Navigate to http://mail.yahoo.com/") test_site = 'http://mail.yahoo.com/' browser.goto(test_site)

TEST SCENARIO 2

How to implement? (Step 3 -> Step 5)

Step 3: #Step 3: Login with a valid account. logger.info ("Step 3: Login with a valid account.") myData.each do |record| browser.div(:id => "inputs").text_field(:id, record['Element']).set(record['Input']) logger.info ("- " + record['FieldList'] + ": " + record['Input']) end

Step 4: #Step 4: Check 'Keep me signed in' checkbox logger.info ("Step 4: Check 'Keep me signed in' checkbox") browser.checkbox(:id, 'persistent').set? browser.checkbox(:id, 'persistent').set #'Keep me signed in' checkbox is checked.

Step 5: #Step 5: Click on Sign In button logger.info ("Step 5: Click on Sign In button") browser.button(:id, '.save').click #click Sign In button Wait.until {browser.span(:id=>"main-btn-new").a(:text=>"Compose Message").exist?}

TEST SCENARIO 2

How to implement? (Step 6)

Step 6: #Step 6: Compose an sample email and click Sent logger.info ("Step 6: Compose an sample email and click Sent") browser.span(:id=>"main-btn-new").a(:text=>"Compose Message").click #click Compose Message button Wait.until {browser.text_field(:id=>"to-field").exist?} input_to = "uyenntm@nexlesoft.com" input_subject = "Test mail yahoo" input_content = "Watir practice" browser.text_field(:id=>"to-field").set(input_to) #fill To address logger.info "- To: " + (input_to) browser.text_field(:id=>"subject-field").set(input_subject) #fill Subject logger.info "- Subject: " + (input_subject) browser.frame(:title=>"Message Body").send_keys input_content #fill Mail content logger.info "- Content: " + (input_content) browser.link(:text=>"Send").click #click Send button logger.info ("- Click 'Send' button.") Wait.until { browser.text.include? 'Email Sent' } #Email sent logger.info ("=> Email Sent")

TEST SCENARIO 2

How to implement? (Step 7)

Step 7: #Step 7: Navigate to Sent item and make sure the sent email is in this folder logger.info ("Step 7: Navigate to Sent item and make sure the sent email is in this folder") logger.info ("- Open Sent folder") browser.div(:id=>"nav-mailboxes").li(:id=>"Sent").click #open Sent folder Wait.until {browser.ul(:id=>"tablist").a(:id=>"tabinbox", :title=>/SENT/).exists?} logger.info ("=> Send folder is opened.") logger.info ("- Make sure the sent email is in Sent folder") #check email sent if ((browser.div(:id=>"msg-list").div(:class=>"list-view-items").divs[0].div(:class=>"from").text.include? input_to) && (browser.div(:id=>"msg-list").div(:class=>"list-view- items").divs[0].div(:class=>"subj").text.include? input_subject)) logger.info ("=> PASS“) else logger.info ("=> FAIL") end

TEST SCENARIO 2

How to implement? (Step 8)

Step 8: #Step 8: Sign out logger.info ("Step 8: Sign out") browser.li(:id=>"yuhead-me-signout").click #click Sign Out button Wait.until { browser.window(:url, "http://vn.yahoo.com/?p=us").exists? } logger.info ("=> The page is log out.") browser.close logger.info ("::::END TESTING.")

TEST SCENARIO 2

How to implement? (END SCRIPT)

RUN SCRIPT

TEST SCENARIO 3

Test with Apple page – Online Shopping

• Step 1: Open Internet Explorer

• Step 2: Navigate to http://store.apple.com/us

• Step 3: Launch Shop iPad on the left side

• Step 4: Click on Select an iPad button

• Step 5: Choose a color and a model

• Step 6: Click on Continue button on the left side

• Step 7: Click on Skip Engraving hyperlink

• Step 8: Add an iPad Smart Cover and Smart Case

• Step 9: Select Apple iPad Camera Connection Kit, iPad Dock, and wireless keyboard under Accessories

• Step 10: Click Add to Cart button

• Step 11: Repeat the test for Chrome and Firefox

TEST SCENARIO 3

How to implement? (START SCRIPT)

require "watir-webdriver" include Watir require 'logger‘ #path store file: script, data file, logs… path = File.dirname(__FILE__) #create log file name_log = 'TEST_Scenario_3' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file)

TEST SCENARIO 3

How to implement? (Step 1 -> Step 3)

Step 1: #Step 1: Open Internet Explorer logger.info "::::" + name_log + " | START TESTING on IE" logger.info ("Step 1: Open Internet Explorer") browser = Watir::Browser.new :ie

Step 2: #Step 2: Navigate to http://store.apple.com/us logger.info ("Step 2: Navigate to http://store.apple.com/us") test_site = 'http://store.apple.com/us' browser.goto(test_site) logger.info ("=> Window title: ") + browser.title

Step 3: #Step 3: Launch Shop iPad on the left side logger.info ("Step 3: Launch Shop iPad on the left side") browser.ul(:class=>"departments").link(:href, /shop_ipad/).click #Click link Shop iPad Wait.until {browser.title.include?"Apple iPad"} logger.info ("=> New window is opened. Title: ") + browser.title

TEST SCENARIO 3

How to implement? (Step 4 -> Step 5)

Step 4: #Step 4: Click on Select an iPad button logger.info ("Step 4: Click on Select an iPad button") browser.div(:id=>"hero-gallery").a(:href, /new_ipad/).click #Click on Select an iPad button Wait.until {browser.title.include?"New iPad"} logger.info ("=> New window is opened. Title: ") + browser.title

Step 5:

#Step 5: Choose a color and a model logger.info ("Step 5: Choose a color and a model") browser.div(:class=>"color-select").li(:class=>"option-1").click #Choose a color logger.info ("- Color: ") + browser.div(:class=>"color-select").li(:class=>"option-1").p(:class=>"color").text browser.div(:class=>"capacity-select selection-container").li(:class=>"option-2").click #Choose a model logger.info ("- Model: ") + browser.div(:class=>"capacity-select selection-container").li(:class=>"option-2").span(:class=>"title").text

TEST SCENARIO 3

How to implement? (Step 6 -> Step 8)

Step 6: #Step 6: Click on Continue button on the left side logger.info ("Step 6: Click on Continue button on the left side") browser.button(:name=>"proceed", :title=>"Continue").click Wait.until {browser.title.include? "iPad Engraving"} logger.info ("=> New window is opened. Title: ") + browser.title

Step 7: #Step 7: Click on Skip Engraving hyperlink logger.info ("Step 7: Click on Skip Engraving hyperlink") browser.span(:id=>"coherent_id_2").button(:type=>"submit").click #Click on Continue button browser.link(:text=>"Skip engraving").click Wait.until {browser.title.include? "Accessories"} logger.info ("=> New window is opened. Title: ") + browser.title

Step 8: #Step 8: Add an iPad Smart Cover and Smart Case logger.info ("Step 8: Add an iPad Smart Cover and Smart Case") #----Add Smart Cover: Dark Gray browser.radio(:name=>"composite-group-featured-content", :value=>"MD306LL/A").set

TEST SCENARIO 3

How to implement? (Step 8) cont.

Step 8 (cont.): #----Get value of selected Smart Cover, then put to log file radios = browser.radios(:name=>"composite-group-featured-content") radio_check = "NOT CHECK" radios.each do |rdo|

if rdo.set? radio_check = rdo.value

end end logger.info ("- Smart Cover: ") + radio_check #----Add Smart Case: Green browser.radio(:name=>"ao.smartcase_polyurethane", :value=>"MD457LL/A").set

TEST SCENARIO 3

How to implement? (Step 8) cont.

Step 8 (cont.): #----Get value of selected Smart Case, then put to log file radios = browser.radios(:name=>"ao.smartcase_polyurethane") radios.each do |rdo|

if rdo.set? radio_check = rdo.value

end end logger.info ("- Smart Case: ") + radio_check

TEST SCENARIO 3

How to implement? (Step 9)

Step 9: #Step 9: Select Apple iPad Camera Connection Kit, iPad Dock, and wireless keyboard under Accessories logger.info ("Step 9: Select Apple iPad Camera Connection Kit, iPad Dock, and wireless keyboard under Accessories") #----Select Apple iPad Camera Connection Kit browser.radio(:name=>"ao.camera_connection_kit", :value=>"MC531ZM/A").set #----Get value of selected value, then put to log file radios = browser.radios(:name=>"ao.camera_connection_kit") radios.each do |rdo|

if rdo.set? radio_check = rdo.value

end end logger.info ("- iPad Camera Connection Kit: ") + radio_check #----Select Apple iPad Dock browser.radio(:name=>"ao.ipad_doc", :value=>"MC940ZM/A").set

TEST SCENARIO 3

How to implement? (Step 9) cont.

Step 9 (cont.): #----Get value of selected value, then put to log file radios = browser.radios(:name=>"ao.ipad_doc") radios.each do |rdo|

if rdo.set? radio_check = rdo.value

end end logger.info ("- iPad Dock: ") + radio_check #----Select Apple Wireless Keyboard - English browser.radio(:name=>"ao.wireless_keyboard", :value=>"MC184LL/B").set #----Get value of selected value, then put to log file radios = browser.radios(:name=>"ao.wireless_keyboard") radios.each do |rdo|

if rdo.set? radio_check = rdo.value

end end logger.info ("- Apple Wireless Keyboard: ") + radio_check

TEST SCENARIO 3

How to implement? (Step 10)

Step 10: #Step 10: Click Add to Cart button logger.info ("Step 10: Click Add to Cart button") browser.ul(:id=>"purchase-info-primary").span(:id=>"proceed-button").button.click #click Add to Cart button logger.info ("=> New window is opened. Title: ") + browser.title logger.info ("::::END TESTING") browser.close

TEST SCENARIO 3

How to implement? (END SCRIPT)

RUN SCRIPT

TEST SCENARIO 4

Test with YouTube page – Browse and Upload video

• Step 1: Open Internet Explorer

• Step 2: Navigate to http://www.youtube.com/

• Step 3: Sign in YouTube

• Step 4: Get key words from data file (contains 10 key words), put into the Browse text box, and click on Browse button.

• Step 5: Validate that results returned in the Search result page contain the input key word

• Step 6: Select an video from this page and play it

• Step 7: Post a comment for this video

• Step 8: Select Video Manager tab and click on Upload button

• Step 9: Select an video file from your computer and upload it to YouTube

• Step 10: Repeat the test for Chrome and Firefox

TEST SCENARIO 4

How to implement? (START SCRIPT)

require "watir-webdriver" require "rautomation" include Watir require 'logger' #path store file: script, data file, logs… path = File.dirname(__FILE__) #create log file name_log = 'TEST_Scenario_4' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file)

TEST SCENARIO 4

How to implement? (Step 1 -> Step 2)

Step 1: #Step 1: Open Internet Explorer logger.info "::::" + name_log + " | START TESTING on IE" logger.info ("Step 1: Open Internet Explorer") browser = Watir::Browser.new :ie

Step 2: #Step 2: Navigate to http://www.youtube.com/ logger.info ("Step 2: Navigate to http://www.youtube.com/") test_site = 'http://www.youtube.com/' browser.goto(test_site) logger.info ("=> Window title: ") + browser.title logger.info ("=> URL: ") + browser.url

TEST SCENARIO 4

How to implement? (Step 3)

Step 3: #Step 3: Sign in YouTube logger.info ("Step 3: Sign in YouTube") #----read username/password from data file for login form require path + '/Xls.rb' #Read data from excel file xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:C3', 'login_youtube') #pull data records from excel xlFile.close #----input username/password logger.info ("1. Login in: ") browser.link(:text=>"Sign In").click myData.each do |record| browser.div(:class=>"signin-box").text_field(:id, record['Element']).set(record['Input']) logger.info ("- " + record['FieldList'] + ": " + record['Input']) end

TEST SCENARIO 4

How to implement? (Step 3) cont.

Step 3 (cont.): #----click Sign in button logger.info ("2. Click Sign in button ") browser.checkbox(:id=>"PersistentCookie").set? browser.checkbox(:id=>"PersistentCookie").clear browser.button(:id=>"signIn").send_keys :enter #Wait.until {browser.link(:text=>"Sign in to another account...").exist?} logger.info ("=> Window title: ") + browser.title logger.info ("=> URL: ") + browser.url

TEST SCENARIO 4

How to implement? (Step 4 -> Step 7)

Step 4 -> Step 7: #Step 4 -> Step 7: logger.info ("Step 4 -> Step 7") logger.info ("- Step 4: Get key words from data file (contains 10 key words), put into the Browse text box, and click on Browse button.") logger.info ("- Step 5: Validate that results returned in the Search result page contain the input key word") logger.info ("- Step 6: Select an video from this page and play it") logger.info ("- Step 7: Post a comment for this video") #Step 4: Get key words from data file (contains 10 key words), put into the Browse text box, and click on Browse button. #Step 5: Validate that results returned in the Search result page contain the input key word #----read data from data file xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:B11', 'search_youtube') #pull data records from excel xlFile.close

TEST SCENARIO 4

How to implement? (Step 4 -> Step 7) cont.

Step 4 -> Step 7 (cont.): #----input key word, then click Search button sleep 4 myData.each do |record| if record['key'] != "" browser.input(:type=>"text", :name=>"search_query").to_subtype.focus browser.input(:type=>"text", :name=>"search_query").to_subtype.set(record['key']) browser.button(:id=>"search-btn").click sleep 4 #----validate search result logger.info ("SEARCH KEY #") + record['#'] + (": ") + record['key'] if browser.div(:id=>"results-main-content").text.upcase.include? record['key'].upcase logger.info ("- Search result included key word.") else logger.info ("- Search result NOT included key word.") end

TEST SCENARIO 4

How to implement? (Step 4 -> Step 7) cont.

Step 4 -> Step 7 (cont.): #Step 6: Select an video from this page and play it browser.div(:id=>"results-main-content").link.click Wait.until {browser.textarea(:name=>"comment").exists?} logger.info ("- Video is played. => Title: ") + browser.title sleep 4 #Step 7: Post a comment for this video logger.info ("- Post a comment for video.") browser.textarea(:name=>"comment").send_keys :enter browser.textarea(:name=>"comment").set "Like." browser.button(:class=>/comments-post yt-uix-button yt-uix-button-default/).click sleep 4

TEST SCENARIO 4

How to implement? (Step 4 -> Step 7) cont.

Step 4 -> Step 7 (cont.): if browser.text.include? "Error, try again" logger.info ("=> You have recently posted several comments. So cannot post comment anymore.") else logger.info ("=> Comment is posted.") end sleep 4 end end

TEST SCENARIO 4

How to implement? (Step 8)

Step 8: #Step 8: Select Video Manager tab and click on Upload button logger.info ("Step 8: Select Video Manager tab and click on Upload button") browser.button(:id=>"masthead-user-button").focus browser.button(:id=>"masthead-user-button").fire_event("onclick") sleep 4 browser.link(:text=>"Video Manager").focus browser.link(:text=>"Video Manager").click browser.div(:id=>"content").button(:text=>/Upload/).click logger.info ("=> URL: ") + browser.url Thread.new { sleep 4 browser.div(:id=>"upload-prompt-box").button(:id=>"start-upload-button-single").click } sleep 4

TEST SCENARIO 4

How to implement? (Step 9)

Step 9: #Step 9: Select an video file from your computer and upload it to YouTube logger.info ("Step 9: Select an video file from your computer and upload it to YouTube") win = RAutomation::Window.new(:title => /Select file/i) win.text_field.set ("D:\\Practice\\Watir Practice\\assignment\\video\\Practice1_ff_(6-18-2012 8-52-35 AM).mp4") win.button(:value=>"&Open").click logger.info ("=> URL: ") + browser.url logger.info "::::END TESTING"

TEST SCENARIO 4

How to implement? (END SCRIPT)

RUN SCRIPT

TEST SCENARIO 5

Test with SlideShare page – Download and upload presentation

• Step 1: Open Internet Explorer

• Step 2: Navigate to http://www.slideshare.net/ and sign in

• Step 3: Get key words from data file (contains 5 key words), put into the Search text box, and click on Search button.

• Step 4: Validate that results returned in the Search result page contain the input key word

• Step 5: Select a presentation from this page and open it.

• Step 6: Post a comment for this presentation

• Step 7: Download this presentation

• Step 8: Email this presentation

• Step 9: Click on Upload button

• Step 10: Select presentation files from your computer and upload it to SlideShare

• Step 11: Repeat the test for Chrome and Firefox

TEST SCENARIO 5

How to implement? (START SCRIPT)

require "watir-webdriver" require "rautomation" include Watir require 'logger' #path store file: script, data file, logs… path = File.dirname(__FILE__) #create log file name_log = 'TEST_Scenario_5' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file)

TEST SCENARIO 5

How to implement? (Step 1 -> Step 2)

Step 1: #Step 1: Open Internet Explorer logger.info "::::" + name_log + " | START TESTING on IE" logger.info ("Step 1: Open IE") browser = Watir::Browser.new :ie

Step 2: #Step 2: Navigate to http://www.slideshare.net/ and sign in logger.info ("Step 2: Navigate to http://www.slideshare.net/") test_site = 'http://www.slideshare.net/' browser.goto(test_site) logger.info ("=> Window title: ") + browser.title #----Read username/password from data file for login form require path + '/Xls.rb' #Read data from excel file xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:C3', 'login_slideshare') #pull data records from excel

TEST SCENARIO 5

How to implement? (Step 2) cont.

Step 2 (cont.): #----Input username/password logger.info ("1. Login in: ") browser.ul(:id=>"login_link").link(:text=>"Login").click Wait.until {browser.text.include? "Login to SlideShare"} myData.each do |record| browser.text_field(:id, record['Element']).focus browser.text_field(:id, record['Element']).set(record['Input']) logger.info ("- " + record['FieldList'] + ": " + browser.text_field(:id, record['Element']).value) end #----Clear checkbox Remember me browser.checkbox(:id=>"remember").set? browser.checkbox(:id=>"remember").clear #----Click Sign in button logger.info ("2. Click Sign in button ") browser.button(:id=>"login_from_loginpage").focus browser.button(:id=>"login_from_loginpage").click Wait.until{browser.title.include? "Newsfeed"} logger.info ("=> Sign in successfully. Title: ") + browser.title

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8)

Step 3 -> Step 8: #Step 3 -> Step 8 #Step 3: Get key words from data file (contains 5 key words), put into the Search text box, and click on Search button. #Step 4: Validate that results returned in the Search result page contain the input key word #Step 5: Select a presentation from this page and open it. #Step 6: Post a comment for this presentation #Step 7: Download this presentation logger.info ("Step 3 -> Step 8") logger.info ("- Step 3: Get key words from data file (contains 5 key words), put into the Search text box, and click on Search button.") logger.info ("- Step 4: Validate that results returned in the Search result page contain the input key word") logger.info ("- Step 5: Select a presentation from this page and open it.") logger.info ("- Step 6: Post a comment for this presentation") logger.info ("- Step 7: Download this presentation") logger.info ("- Step 8: Email this presentation")

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8) cont.

Step 3 -> Step 8 (cont.): #----Read from data file myData = xlFile.getRowRecords('A1:B6', 'search_slideshare') #pull data records from excel xlFile.close #----input key word, then click Search button myData.each do |record| if record['key'] != "" browser.input(:type=>"text",:id=>/search_query_top/).to_subtype.focus browser.input(:type=>"text",:id=>/search_query_top/).to_subtype.set(record['key']) if (browser.div(:class=>"advancedSearch").link(:text=>"Filter results").exist?)

browser.div(:class=>"advancedSearch").link(:text=>"Filter results").click browser.div(:class=>"advancedSearch").link(:text=>"Filter results").click

end browser.input(:type=>"text",:id=>/search_query_top/).to_subtype.set(record['key']) browser.input(:type=>"text",:id=>/search_query_bottom/).to_subtype.set(record['key']) browser.input(:type=>"submit",:value=>/Search/).click

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8) cont.

Step 3 -> Step 8 (cont.): #----validate search result logger.info ("SEARCH KEY #") + record['#'] + (": ") + record['key'] if browser.span(:class=>"search-term").text.upcase.include? record['key'].upcase logger.info ("- Search result included key word.") else logger.info ("- Search result NOT included key word.") end sleep 4 #Step 5: Select a presentation from this page and open it. id = browser.link(:class=>"download-link").id logger.info ("- Open link.") browser.link(:id=>id).focus browser.link(:id=>id).click logger.info ("=> Presentation page is displayed. Title: ") + browser.title

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8) cont.

Step 3 -> Step 8 (cont.): #Step 6: Post a comment for this presentation Wait.until {browser.link(:class=>/sprite iconEmail j-tooltip/,:text=>/Email/) .exists?} if (browser.text.include? "Comments are closed.") logger.info ("=> Comments are closed, cannot post more comment.") else Wait.until {browser.link(:class=>"postCommentLink").exists?} browser.link(:class=>"postCommentLink").click browser.textarea(:class=>/post-comment/).set("cool!!!") logger.info ("- Post comment. Content: ") + browser.textarea(:class=>/post-comment/).value browser.input(:type=>"submit",:value=>/Post Comment/).click end

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8) cont.

Step 3 -> Step 8 (cont.): #Step 7: Download this presentation if browser.span(:class=>/sprite iconNoDownload j-tooltip/,:text=>/Download/).exist? logger.info ("- Download is disabled by the author, so cannot download this file.") else browser.link(:class=>/sprite iconDownload j-tooltip/,:text=>/Download/).focus Thread.new { browser.link(:class=>/sprite iconDownload j-tooltip/,:text=>/Download/).click } sleep 4 wrauto = RAutomation::Window.new(:title => /File Download/i) wrauto.button(:value=>"&Save").click wrauto = RAutomation::Window.new(:title => /Save As/i) wrauto.button(:value=>"&Save").click logger.info ("- Start downloading.") sleep 80 #time wait for file downloading end

TEST SCENARIO 5

How to implement? (Step 3 -> Step 8) cont.

Step 3 -> Step 8 (cont.): #Step 8: Email this presentation browser.back browser.link(:class=>/sprite iconEmail j-tooltip/,:text=>/Email/).click Wait.until {browser.text.include? "to friends"} logger.info ("- Send email") browser.textarea(:id=>/message_to/).send_keys :enter browser.textarea(:id=>/message_to/).set ("watirt@gmail.com") logger.info ("-- To: ") + browser.textarea(:id=>"message_to").value browser.textarea(:id=>/message_body/).send_keys :enter browser.textarea(:id=>/message_body/).set ("I think you will find this useful. Pls refer.") logger.info ("-- Message: ") + browser.textarea(:id=>"message_body").value browser.input(:id=>"send-button", :type=>"submit").focus browser.input(:id=>"send-button", :type=>"submit").click logger.info ("-- Click 'Send' button.") Wait.until {browser.text.include? "Email sent."} logger.info ("=> Email sent.") end end

TEST SCENARIO 5

How to implement? (Step 9 -> Step 10)

Step 9: #Step 9: Click on Upload button logger.info ("Step 9: Click on Upload button") browser.link(:class=>"btn btn-primary", :text=>"Upload").focus browser.link(:class=>"btn btn-primary", :text=>"Upload").click logger.info ("=> Upload page is displayed.") logger.info ("=> Title: ") + browser.title

Step 10: #Step 10: Select presentation files from your computer and upload it to SlideShare logger.info ("Step 10: Select presentation files from your computer and upload it to SlideShare") browser.div(:class=>"upload_button nonprivate_button nonprivate_buttonExp").object(:id=>"SWFUpload_0").click win = RAutomation::Window.new(:title => /Select file/i) win.text_field.set ("D:\\Training Documents\\test_watir.pptx") logger.info ("- File path: ") + win.text_field.value win.button(:value=>"&Open").click logger.info ("=> File uploaded.") logger.info ("::::END TESTING")

TEST SCENARIO 5

How to implement? (END SCRIPT)

RUN SCRIPT

TEST SCENARIO 6

Test with Facebook page – Share info and chat

• Step 1: Open Internet Explorer

• Step 2: Navigate to http://www.facebook.com/ and sign in

• Step 3: Write a comment on your post

• Step 4: View Activity Log.

• Step 5: Click on Messages

• Step 6: Find an online friend and initialize a chat

• Step 7: Sign out

• Step 8: Repeat the test for Chrome and Firefox

TEST SCENARIO 6

How to implement? (START SCRIPT)

require "watir-webdriver" include Watir require 'logger' require File.dirname(__FILE__) + "/Xls“ #path store file: script, data file, logs… path = File.dirname(__FILE__) #create log file name_log = 'TEST_Scenario_6' file = File.open(path + '/logs/' + name_log + '_logFile.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file) #read data from data file xlFile = XLS.new(path + '/data/data_file.xlsx') #grab the data file in the same directory myData = xlFile.getRowRecords('A1:D3', 'login_fb') #pull data records from excel xlFile.close

TEST SCENARIO 6

How to implement? (Step 1 -> Step 2)

Step 1: #Step 1: Open Internet Explorer logger.info "::::" + name_log logger.info ("Step 1: Open Internet Explorer") browser = Watir::Browser.new :ie

Step 2: #Step 2: Navigate to http://www.facebook.com/ and sign in #----navigate to http://www.facebook.com/ logger.info ("Step 2: Navigate to http://www.facebook.com/ and sign in") test_site = 'http://www.facebook.com/' browser.goto(test_site) logger.info ("=> Window title: ") + browser.title #----sign in logger.info ("- Log in") myData.each do |record| browser.text_field(:id=>record['Element']).set(record['Input']) end browser.button(:text=>"Log In").click logger.info ("=> Window title: ") + browser.title

TEST SCENARIO 6

How to implement? (Step 4 -> Step 5)

Step 3: #Step 3: Write a comment on your post logger.info ("Step 4: Write a comment on your post") #----comment on the post browser. button(:value=>/Comment/).send_keys :enter #click Comment link sleep 4 browser.textarea(:name=>"add_comment_text_text").set("Hi!") #input comment browser.textarea(:name=>"add_comment_text_text").send_keys :enter #press enter key logger.info ("=> URL: " + browser.url)

Step 4: #Step 4: View Activity Log. logger.info ("Step 4: View Activity Log.") browser.send_keys :space browser.element.wd.location_once_scrolled_into_view browser.div(:class=>"mtm mlm").link(:href=>/allactivity/).click logger.info ("=> URL: " + browser.url)

TEST SCENARIO 6

How to implement? (Step 6 -> Step 7)

Step 5: #Step 5: Click on Messages logger.info ("Step 5: Click on Messages") browser.div(:id=>"fbMessagesJewel").click browser.div(:id=>"MercuryJewelFooter").click logger.info ("=> URL: " + browser.url)

Step 6: #Step 6: Find an online friend and initialize a chat logger.info ("Step 6: Find an online friend and initialize a chat") browser.div(:id=>"fbDockChatBuddylistNub").click online = browser.li(:class=>"item active") if online.exists? online.click browser.textarea(:class=>"uiTextareaAutogrow input").set("Hello") browser.textarea(:class=>"uiTextareaAutogrow input").send_keys :enter logger.info ("=> Chat with " + browser.div(:class=>"clearfix fbNubFlyoutTitlebar titlebar").text) else logger.info ("=> No one is available to chat.") end

TEST SCENARIO 6

How to implement? (Step 8)

Step 7: #Step 7: Sign out logger.info ("Step 8: Sign out") browser.link(:id=>"navAccountLink").click browser.button(:value=>"Log Out").click Wait.until {browser.text.include? "Sign Up"} logger.info ("=> Log out successfully.") logger.info "::::END TESTING" browser.close

TEST SCENARIO 6

How to implement? (END SCRIPT)

RUN SCRIPT