Skip to content

Instantly share code, notes, and snippets.

@sakhtar-git
Created January 16, 2019 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakhtar-git/cc58d28e3113d59991c54e80af9c1ff4 to your computer and use it in GitHub Desktop.
Save sakhtar-git/cc58d28e3113d59991c54e80af9c1ff4 to your computer and use it in GitHub Desktop.
Assignment
#!/usr/bin/env ruby
require 'watir'
require 'test/unit/assertions'
include Test::Unit::Assertions
# Web Automation Test:
# *******************
# [1]. Go to www.bing.com
# [2]. Assert page title, header, search bar.
# [3]. Scroll page and assert “Image of the Day”, “On This Day In History” sections.
# [4]. Search for Google Documents
# [5]. Assert the following elements on the search page results:
# [5.a] Return how many results were found
# [5.b] Verify complementary result section is available (informational box on the side)
# [5.c] Grab title of the first result in the News section and save it for later.
# [5.d] Return count and result names from the first page of results.
# Submitted by Sharique Akhtar - Jan 15,2019
browser = Watir::Browser.new
#[1]
browser.goto 'www.bing.com'
#[2] title
assert(browser.title=="Bing", msg = "Title of the page - Bing was not returned")
search_box = browser.text_field(class: ['b_searchbox'])
title = search_box.title
#[2] #search bar
assert(title=="Enter your search term",
msg = "Input box search with Title-Enter your search term was not found ")
#[3]
div_day = browser.div(id: 'vs_cont')
div_day.wait_until(&:present?).wd.location_once_scrolled_into_view
div_day_image = div_day.div(id: 'vert_iotd').wait_until
div_day_image.hover
h2 = div_day_image.h2
assert( h2.text=="IMAGE OF THE DAY",
msg = "Text for the heading was not found incorrect ")
# [4]
search_box.set "Google Documents"
browser.send_keys :enter
result = browser.span(class: ['sb_count']).wait_until
result = result.text.to_i
#[5.a]
assert( result != 0 ,
msg = "Search results count for Google Doc are not zero")
first_page = browser.element(css: "#b_results > li").wait_until
complementary = browser.ol(id: 'b_context').wait_until
#[5.b]
assert(complementary.exist?, msg= "complementary section was not found" )
#[5.c]
first_news_ans = browser.element(css: 'div.itm_tlt_snp > p.na_t')
first_news_ans_text = first_news_ans.text
puts "Here is the first result inside news section::" + first_news_ans.text
#[5.d]
all_results = browser.elements(css: '#b_results > li >h2')
count_all_results = all_results.size
results_name =[]
all_results.each{|x| results_name << x.text}
puts "Count for total results:::"
puts count_all_results
puts "Following are the results returned:::"
puts results_name.inspect
#[6]
browser.link(href: /news\/search/).click
main = browser.div(id: 'mainid').wait_until(&:present?)
news = main.div(class: [/newsitem/]).element(class: ['title']).wait_until
assert( first_news_ans_text == news.text ,
msg = "Search results count for Google Doc are not zero")
browser.close
#------end of the test-----------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment