SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
WATIR Web Automated
    Tests Demo


             Jun, 2012
TEST SCENARIOS


           Scenario
              1
Scenario              Scenario
   6                     2

           WATIR

Scenario              Scenario
   5                     3
           Scenario
              4
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:PracticeWatir PracticeassignmentvideoPractice1_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 Documentstest_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
Watir web automated tests

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksAddy Osmani
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLaurence Svekis ✔
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFesttomdale
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudJonghyun Park
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsLudmila Nesvitiy
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)Addy Osmani
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 

Was ist angesagt? (20)

jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
SproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFestSproutCore is Awesome - HTML5 Summer DevFest
SproutCore is Awesome - HTML5 Summer DevFest
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
 
Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet Protractor Training in Pune by QuickITDotnet
Protractor Training in Pune by QuickITDotnet
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Selenium
SeleniumSelenium
Selenium
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
BDD with cucumber
BDD with cucumberBDD with cucumber
BDD with cucumber
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Test automation
Test  automationTest  automation
Test automation
 
Selenium for-ops
Selenium for-opsSelenium for-ops
Selenium for-ops
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 

Andere mochten auch

Keyword Driven Framework using WATIR
Keyword Driven Framework using WATIRKeyword Driven Framework using WATIR
Keyword Driven Framework using WATIRNivetha Padmanaban
 
Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyJohn Ferguson Smart Limited
 
Hybrid framework for test automation
Hybrid framework for test automationHybrid framework for test automation
Hybrid framework for test automationsrivinayak
 
Test Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comTest Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comIdexcel Technologies
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework DesignsSauce Labs
 

Andere mochten auch (9)

Watir
WatirWatir
Watir
 
Keyword Driven Framework using WATIR
Keyword Driven Framework using WATIRKeyword Driven Framework using WATIR
Keyword Driven Framework using WATIR
 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
 
Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_ugly
 
Hybrid framework for test automation
Hybrid framework for test automationHybrid framework for test automation
Hybrid framework for test automation
 
Test Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.comTest Automation Framework Design | www.idexcel.com
Test Automation Framework Design | www.idexcel.com
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 

Ähnlich wie Watir web automated tests

Rf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareRf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareMika Tavi
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...Ho Chi Minh City Software Testing Club
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
PHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabusPHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabusKavithaK23
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliRebecca Eloise Hogg
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAravindharamanan S
 
BDD, ATDD, Page Objects: The Road to Sustainable Web Testing
BDD, ATDD, Page Objects: The Road to Sustainable Web TestingBDD, ATDD, Page Objects: The Road to Sustainable Web Testing
BDD, ATDD, Page Objects: The Road to Sustainable Web TestingJohn Ferguson Smart Limited
 
Green Lantern Framework with Selenium IDE
Green Lantern Framework with Selenium IDEGreen Lantern Framework with Selenium IDE
Green Lantern Framework with Selenium IDESrilu Balla
 

Ähnlich wie Watir web automated tests (20)

Keyword driven testing in qtp
Keyword driven testing in qtpKeyword driven testing in qtp
Keyword driven testing in qtp
 
Rf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareRf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere share
 
Jquery
JqueryJquery
Jquery
 
Javascript projects Course
Javascript projects CourseJavascript projects Course
Javascript projects Course
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
jQuery
jQueryjQuery
jQuery
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Qtp day 3
Qtp day 3Qtp day 3
Qtp day 3
 
PHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabusPHP Lab template for lecturer log book- and syllabus
PHP Lab template for lecturer log book- and syllabus
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codes
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
BDD, ATDD, Page Objects: The Road to Sustainable Web Testing
BDD, ATDD, Page Objects: The Road to Sustainable Web TestingBDD, ATDD, Page Objects: The Road to Sustainable Web Testing
BDD, ATDD, Page Objects: The Road to Sustainable Web Testing
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
Tutorial asp.net
Tutorial  asp.netTutorial  asp.net
Tutorial asp.net
 
Android search
Android searchAndroid search
Android search
 
Android search
Android searchAndroid search
Android search
 
Green Lantern Framework with Selenium IDE
Green Lantern Framework with Selenium IDEGreen Lantern Framework with Selenium IDE
Green Lantern Framework with Selenium IDE
 

Kürzlich hochgeladen

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Kürzlich hochgeladen (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

Watir web automated tests

  • 1. WATIR Web Automated Tests Demo Jun, 2012
  • 2. TEST SCENARIOS Scenario 1 Scenario Scenario 6 2 WATIR Scenario Scenario 5 3 Scenario 4
  • 3. 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.
  • 4. 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
  • 5. 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)
  • 6. 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.
  • 7. 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…
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. TEST SCENARIO 1 How to implement? (END SCRIPT) RUN SCRIPT
  • 13. 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
  • 14. 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)
  • 15. 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)
  • 16. 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?}
  • 17. 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")
  • 18. 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
  • 19. 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.")
  • 20. TEST SCENARIO 2 How to implement? (END SCRIPT) RUN SCRIPT
  • 21. 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
  • 22. 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)
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. TEST SCENARIO 3 How to implement? (END SCRIPT) RUN SCRIPT
  • 32. 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
  • 33. 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)
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 42. 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:PracticeWatir PracticeassignmentvideoPractice1_ff_(6-18-2012 8-52-35 AM).mp4") win.button(:value=>"&Open").click logger.info ("=> URL: ") + browser.url logger.info "::::END TESTING"
  • 43. TEST SCENARIO 4 How to implement? (END SCRIPT) RUN SCRIPT
  • 44. 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
  • 45. 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)
  • 46. 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
  • 47. 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
  • 48. 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")
  • 49. 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
  • 50. 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
  • 51. 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
  • 52. 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
  • 53. 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
  • 54. 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 Documentstest_watir.pptx") logger.info ("- File path: ") + win.text_field.value win.button(:value=>"&Open").click logger.info ("=> File uploaded.") logger.info ("::::END TESTING")
  • 55. TEST SCENARIO 5 How to implement? (END SCRIPT) RUN SCRIPT
  • 56. 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
  • 57. 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
  • 58. 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
  • 59. 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)
  • 60. 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
  • 61. 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
  • 62. TEST SCENARIO 6 How to implement? (END SCRIPT) RUN SCRIPT