Module: VanillaSeleniumWrapper::PageAction
- Defined in:
- lib/vanilla_selenium_wrapper/actions/page_actions.rb
Overview
class PageAction
Instance Method Summary collapse
-
#add_cookie(key, value) ⇒ Object
- add_cookie
- add cookie in browser session I/P
- (key,value) cookie key and value is added to brower session O/P
- adds the cookie to browser session usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.add_cookie(key,value).
-
#all_cookies ⇒ Object
- all_cookies
- get all cookies in current session O/P
- Returns the array of cookies usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.all_cookies.
-
#back ⇒ Object
- back performs sending backward action to opened browser button usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.back.
-
#checkbox_checked(element_name, be_selected = true) ⇒ Object
- checkbox_checked(element_name, be_selected=true)
- selecting and verifying check box is selected Input
- Element_name => element name defined in JSON / CSV file Output
-
true or false.
-
#clear_text(element_name) ⇒ Object
- clear_text
- clear value of text field or text area element name and text value I/P
- Parameter is defined “element name” in csv or json file Output
- clear value of text field or text area usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.clear_text(element_name).
-
#click_on_element(element_name) ⇒ Object
- click_on_element
- It click on defined element I/P
- Parameter is defined “element name” in csv or json file O/P
- It clicks on element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.click_on_element(element_name).
-
#close_browser ⇒ Object
- close_browser
- closes all browser windows, and quit the selenium session usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.close_browser.
-
#close_window ⇒ Object
- close_window
- closes the current browser windows, selenium session is still active usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.close_window.
-
#delete_all_cookies ⇒ Object
- delete_all_cookies
- It delete all cookies from browser O/P
- delete all cookies usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.delete_all_cookie.
-
#delete_cookie(name) ⇒ Object
- delete_cookie
- Delete particular cookie in Selenium session browser I/P
- parameter should be the name of cookie to be deleted O/P
- It deletes particular from browser usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.delete_cookie(cookie_name).
-
#double_click(element_name) ⇒ Object
- double_click
- double clicks on element I/P
- Parameter is defined “element name” in csv or json file Output
- double clicks on element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.double_click(element_name).
-
#drag_and_drop(source_element_, target_element) ⇒ Object
- drag_and_drop
- It drags the element from current location to target location I/P
- parameter(source_element)
- element name, Defined in object repository (csv or json), parameter(target_element)
- element name, Defined in object repository (csv or json) O/P
- drags the element name usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.drag_and_drop(source_element, target_element).
-
#el(element_name) ⇒ Object
- el(element_name) will grab the element from the defined CSV and JSON file custom method too find element O/P
- return the element usage
-
Other methods default uses to grab element from the defined object repository.
-
#element_attribute(element_name, attribute_type) ⇒ Object
- element_attribute
- Get the attribute of element I/P
- Parameter is defined “element name” in csv or json file Output
- return the attribute of element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.element_attribute(element_name, attribute_type).
-
#element_displayed(element_name) ⇒ Object
- element_displayed
- The element is displayed on web page I/P
- Parameter is defined “element name” in csv or json file Output
- return element is displayed on web page usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.element_displayed(element_name).
-
#element_enabled(element_name) ⇒ Object
- element_enabled : It verifies the element is enabled on webpage I/P
- Parameter is defined “element name” in csv or json file O/P
- return true if element is enabled to perform action in webpage else it will throw error usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.element_enabled(element_name).
-
#element_location(element_name) ⇒ Object
- element_location(element_type)
- gets the element location I/P
- Parameter is defined “element name” in csv or json file Output
- Gets the element location usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.element_location(element_name).
-
#element_size(element_name) ⇒ Object
- element_size
- get the size of element I/P
- Parameter is defined “element name” in csv or json file Output
- Gets the size of element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.element_size(element_name).
-
#forward ⇒ Object
- forward performs sending forward action to opened browser button usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.forward.
-
#get_text(element_name) ⇒ Object
- get_text
- ets the text value of the current element I/P
- Parameter is defined “element name” in csv or json file O/P
- gets the text from the element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.get_text(element_name).
-
#get_url(url = nil) ⇒ Object
- get_url
-
It opens the browser defined in config file and performs sending the URL and executing it on open web browser Input : URL String eg.
- #launch_selenium_webdriver ⇒ Object
-
#location_scroll(element_name) ⇒ Object
- location_scroll(element_type)
- scroll to element location I/P
- Parameter is defined “element name” in csv or json file Output
- scroll to location usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.location_scroll(element_name).
-
#move_to(element_name, right_by = nil, down_by = nil) ⇒ Object
- move_to element_name, right_by = nil, down_by = nil
- move the element from one location to other Input
- Element_name => element name defined in JSON / CSV file, right_by => value to shift right, down_by => value to move Output
- Move the element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.move_to(element_name, right_by = nil, down_by = nil).
-
#refresh ⇒ Object
- refresh
- it refresh current web page O/P
- refresh current web page, with current URL usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.get_text(element_name).
-
#select(element_name) ⇒ Object
- select
- Select the element, can be used with checkbox or radio Input
- Element_name => element name defined in JSON / CSV file Output
- select the element usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.select(element_name).
-
#select_option(element_name, how = nil, what = nil) ⇒ Object
- Usage
-
element_name = company_dropdown dropdown should be selected by “value” value is “afour” $browser = Vanilla::PageAction $browser.select_option(‘company_dropdown’, :value, ‘afour’).
-
#selected?(element_name) ⇒ Boolean
- checkbox_checked(element_name, be_selected=true)
- selecting and verifying check box is selected Input
- Element_name => element name defined in JSON / CSV file Output
- true or false usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.checkbox_checked(element_name, be_selected=true).
-
#send_keys_text(element_name, text) ⇒ Object
- send_keys_text
- sends the text value of text field or text area element name Input
- parameter(element name) defined in JSON / CSV file parameter(text) send the text value in text field and text area Output
- type the text value in text field and text area usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.send_keys_text(element_type, text).
-
#switch_default ⇒ Object
- switch_default
- switches back to default frame O/P
- Switch to the default frame usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.switch_default.
-
#switch_frame(frame_name) ⇒ Object
- switch_frame
- it switch the frame to given frame id or index I/P
- parameter(frame_name) : it requires the frame name or frame id O/P
- Switch to the given frame else return the error message usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.switch_frame(frame_name).
-
#title(expected_title) ⇒ Object
- title
- It verify the title I/P
- it takes input as expected title O/P
- return true if page title matches with expected title else return false Information
- This method uses a custom made rspec matchers usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.title(expected_title).
-
#value(element_name) ⇒ Object
- value
- Get the value of element I/P
- Parameter is defined “element name” in csv or json file O/P
- Get the element value usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.value(element_name).
-
#wait_and_find_element(element_name) ⇒ Object
- wait_and_find_element: will wait for element I/P
- Parameter is defined “element name” in csv or json file O/P
- return true if element is appears in webpage else it will throw error usage
-
create the object of PageAction class $browser = Vanilla::PageAction $browser.wait_and_find_element(element_name).
Instance Method Details
#add_cookie(key, value) ⇒ Object
- add_cookie
-
add cookie in browser session
- I/P
-
(key,value) cookie key and value is added to brower session
- O/P
-
adds the cookie to browser session
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.add_cookie(key,value)
234 235 236 237 238 239 240 241 242 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 234 def (key,value) #$LOG.info "adding cookie with key => #{key} and value => #{value}" begin $driver.manage.(:name => "#{key}", :value => "#{value}") rescue Exception => e #$LOG.error "Add Cookie can't be completed "+e.message raise "Add Cookie can't be completed "+e. end end |
#all_cookies ⇒ Object
- all_cookies
-
get all cookies in current session
- O/P
-
Returns the array of cookies
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.all_cookies
249 250 251 252 253 254 255 256 257 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 249 def $LOG.info "Return all cookies" begin $driver.manage. rescue Exception => e $LOG.error "get all cookies can't be completed\nerror :: "+e. raise "get all cookies can't be completed \nerror :: "+e. end end |
#back ⇒ Object
back performs sending backward action to opened browser button
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.back
46 47 48 49 50 51 52 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 46 def back begin $driver.navigate.back rescue Exception => e raise "Browser navigating backward error \n Error Message :: "+e. end end |
#checkbox_checked(element_name, be_selected = true) ⇒ Object
- checkbox_checked(element_name, be_selected=true)
-
selecting and verifying check box is selected
- Input
-
Element_name => element name defined in JSON / CSV file
- Output
-
true or false
530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 530 def checkbox_checked(element_name, be_selected=true) begin select_check = select(element_name) select_check unless be_selected == selected?(element_name) rescue Exception => e #$LOG.error "error in selecting check box on element \n element name : #{element_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in selecting check box on element \n element name : #{element_name} "+e. end end |
#clear_text(element_name) ⇒ Object
- clear_text
-
clear value of text field or text area element name and text value
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
clear value of text field or text area
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.clear_text(element_name)
312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 312 def clear_text(element_name) #$LOG.info "clear value of text field or text area : #{element_name}" wait_and_find_element(element_name) begin wait_and_find_element element_name clear_value = el element_name clear_value.clear rescue Exception => e #$LOG.error "Unable to clear value of text field or text area : #{element_name} "+e.message #$driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") #$webscreenshot = $webscreenshot+1 raise "Unable to clear value of text field or text area : #{element_name} "+e. end end |
#click_on_element(element_name) ⇒ Object
- click_on_element
-
It click on defined element
- I/P
-
Parameter is defined “element name” in csv or json file
- O/P
-
It clicks on element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.click_on_element(element_name)
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 182 def click_on_element(element_name) #$LOG.info "clicking on element #{element_name} " begin wait_and_find_element element_name click_ele = el(element_name) click_ele.click rescue Exception => e #$LOG.error "Can't click on element "+ e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Can't click on element test "+ e. end end |
#close_browser ⇒ Object
- close_browser
-
closes all browser windows, and quit the selenium session
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.close_browser
58 59 60 61 62 63 64 65 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 58 def close_browser #$LOG.info "Inside close browser method" begin $driver.quit rescue Exception => e raise "Error in quiting browser and ending session \n Error Message ::" + e. end end |
#close_window ⇒ Object
- close_window
-
closes the current browser windows, selenium session is still active
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.close_window
71 72 73 74 75 76 77 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 71 def close_window begin $driver.close rescue Exception => e raise "Error Close the current window \n Error Message :: "+e. end end |
#delete_all_cookies ⇒ Object
- delete_all_cookies
-
It delete all cookies from browser
- O/P
-
delete all cookies
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.delete_all_cookie
202 203 204 205 206 207 208 209 210 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 202 def #$LOG.info "deleting all cookies" begin $driver.manage. rescue Exception => e #$LOG.error "error in deleting cookies :: " +e.message raise "error in deleting cookies :: " +e. end end |
#delete_cookie(name) ⇒ Object
- delete_cookie
-
Delete particular cookie in Selenium session browser
- I/P
-
parameter should be the name of cookie to be deleted
- O/P
-
It deletes particular from browser
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.delete_cookie(cookie_name)
218 219 220 221 222 223 224 225 226 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 218 def (name) #$LOG.info "deleting cookie #{name}" begin $driver.manage. name rescue Exception => e #$LOG.error "error in deleting cookie #{name} "+e.message raise "Error in deleting cookie #{name} "+e. end end |
#double_click(element_name) ⇒ Object
- double_click
-
double clicks on element
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
double clicks on element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.double_click(element_name)
489 490 491 492 493 494 495 496 497 498 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 489 def double_click(element_name) begin $driver.action.double_click(el(element_name)).perform rescue Exception => e #$LOG.error "error in perform double click on element \n element name : #{element_name} "+e.message $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") $webscreenshot = $webscreenshot+1 raise "error in perform double click on element \n element name : #{element_name} "+e. end end |
#drag_and_drop(source_element_, target_element) ⇒ Object
- drag_and_drop
-
It drags the element from current location to target location
- I/P
- parameter(source_element)
-
element name, Defined in object repository (csv or json),
- parameter(target_element)
-
element name, Defined in object repository (csv or json)
- O/P
-
drags the element name
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.drag_and_drop(source_element, target_element)
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 268 def drag_and_drop(source_element_, target_element) #$LOG.info "draging and droping the element Source : #{source_element_} and Target : #{target_element}" begin wait_and_find_element(source_element_) wait_and_find_element(target_element) element = el(source_element_) target = el(target_element) $driver.action.drag_and_drop(element, target).perform rescue Exception => e #$LOG.error "Error in drag and drop \n source element :: #{source_element_} \n target element #{target_element}" #$LOG.error "Error Message :: " +e.message #$driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") #$webscreenshot = $webscreenshot+1 raise "Error in drag and drop \n source element :: #{source_element_} \n target element #{target_element} \n " + e. end end |
#el(element_name) ⇒ Object
el(element_name) will grab the element from the defined CSV and JSON file custom method too find element
- O/P
-
return the element
- usage
-
Other methods default uses to grab element from the defined object repository
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 84 def el(element_name) begin # raise "Element name not exist in object repository" unless element_name.class != "Hash" && element_name.length < 0 element_name.each do |k,v| if(k=='class' || k=='css' || k=='id' || k=='xpath' || k=='partial_link_text' || k=='tag_name') begin $elem = $driver.find_element(k.to_sym,v.to_s) rescue Exception => e raise "Element not found \n #{element_name} : #{k} => #{v} \n Error Message :: " + e. end $elem end $elem end $elem rescue raise "Element not present in object repository" end end |
#element_attribute(element_name, attribute_type) ⇒ Object
- element_attribute
-
Get the attribute of element
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
return the attribute of element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.element_attribute(element_name, attribute_type)
436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 436 def element_attribute(element_name, attribute_type) #$LOG.info "fetching attribute of Element \n element name : #{element_name} & Attribute type : #{attribute_type} " begin wait_and_find_element element_name el_attribute = el element_name el_attribute.attribute(attribute_type) rescue Exception => e #$LOG.error "error in fetching attribute of Element \n element name : #{element_name} & Attribute type : #{attribute_type} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in fetching Element"+e. end end |
#element_displayed(element_name) ⇒ Object
- element_displayed
-
The element is displayed on web page
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
return element is displayed on web page
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.element_displayed(element_name)
416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 416 def element_displayed(element_name) #$LOG.info "verify element displayed in current page #{element_name}" begin wait_and_find_element element_name el_disp = el element_name el_disp.display? rescue Exception => e #$LOG.error "error in displaying Element of element name : #{element_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in displaying Element of element name : #{element_name}"+e. end end |
#element_enabled(element_name) ⇒ Object
element_enabled : It verifies the element is enabled on webpage
- I/P
-
Parameter is defined “element name” in csv or json file
- O/P
-
return true if element is enabled to perform action in webpage else it will throw error
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.element_enabled(element_name)
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 162 def element_enabled(element_name) #$LOG.info "verifing enabled Element #{element_name}" begin raise "Element not found" unless wait_and_find_element(element_name) raise "Element not enabled" unless (expect(el(element_name).enabled?).to eql true) rescue Exception => e #$LOG.error "Element not Enabled "+ e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Element not Enabled "+ e. end end |
#element_location(element_name) ⇒ Object
- element_location(element_type)
-
gets the element location
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
Gets the element location
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.element_location(element_name)
355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 355 def element_location(element_name) #$LOG.info "getting element location #{element_name}" begin wait_and_find_element(element_name) el_loc = el element_name el_loc.location rescue Exception => e #$LOG.error "Error getting element location of element name : #{element_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Error getting element location of element name : #{element_name} "+e. end end |
#element_size(element_name) ⇒ Object
- element_size
-
get the size of element
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
Gets the size of element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.element_size(element_name)
396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 396 def element_size(element_name) #$LOG.info "getting element size of #{element_name}" begin wait_and_find_element element_name el_size = el element_name el_size.size rescue Exception => e #$LOG.error "Error in size of element of element name : #{element_name} \n Error Message :: "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Error in size of element of element name : #{element_name}\n Error Message ::"+e. end end |
#forward ⇒ Object
forward performs sending forward action to opened browser button
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.forward
34 35 36 37 38 39 40 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 34 def forward begin $driver.navigate.forward rescue Exception => e raise "Browser navigating forward error \n Error Message :: "+e. end end |
#get_text(element_name) ⇒ Object
- get_text
-
ets the text value of the current element
- I/P
-
Parameter is defined “element name” in csv or json file
- O/P
-
gets the text from the element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.get_text(element_name)
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 292 def get_text(element_name) #$LOG.info "getting text of an element #{element_name}" begin wait_and_find_element(element_name) ele_get_text = el(element_name) ele_get_text.text rescue Exception => e #$LOG.error "Error getting text value of element name : #{element_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Error getting text value of element name : #{element_name} "+e. end end |
#get_url(url = nil) ⇒ Object
- get_url
-
It opens the browser defined in config file and performs sending the URL and executing it on open web browser
Input : URL String eg. www.google.com It can be either passed using configuration file or using the default parameter
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.get_url(“www.google.com”)
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 17 def get_url(url=nil) begin if url.to_s.length == 0 url = get_browser = VanillaUtilityReader::VanillaFileReader::ConfigReader.configuration_reader $driver.navigate.to(configuration_reader['url'].to_s) else $driver.navigate.to(url) end rescue Exception => e raise "Error in getting URL \n Error Message ::"+e. end end |
#launch_selenium_webdriver ⇒ Object
5 6 7 8 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 5 def launch_selenium_webdriver $driver = Selenium::WebDriver.for configuration_reader['browser'].to_sym $driver.manage.window.maximize end |
#location_scroll(element_name) ⇒ Object
- location_scroll(element_type)
-
scroll to element location
- I/P
-
Parameter is defined “element name” in csv or json file
- Output
-
scroll to location
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.location_scroll(element_name)
376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 376 def location_scroll(element_name) #$LOG.info "getting location scroll for element : #{element_name}" begin wait_and_find_element element_name loc_scr = el element_name loc_scr.location_once_scrolled_into_view rescue Exception => e #$LOG.error "Error in scrolling to location of element name : #{element_name} " +e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Error in scrolling to location of element name : #{element_name} " +e. end end |
#move_to(element_name, right_by = nil, down_by = nil) ⇒ Object
- move_to element_name, right_by = nil, down_by = nil
-
move the element from one location to other
- Input
-
Element_name => element name defined in JSON / CSV file, right_by => value to shift right, down_by => value to move
- Output
-
Move the element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.move_to(element_name, right_by = nil, down_by = nil)
472 473 474 475 476 477 478 479 480 481 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 472 def move_to element_name, right_by = nil, down_by = nil begin $driver.action.move_to(el(element_name), right_by, down_by).perform rescue Exception => e #$LOG.error "error in moving element \n element name : #{element_name}, right: #{right_by} and down: #{down_by} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in moving element \n element name : #{element_name}, right: #{right_by} and down: #{down_by} "+e. end end |
#refresh ⇒ Object
- refresh
-
it refresh current web page
- O/P
-
refresh current web page, with current URL
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.get_text(element_name)
588 589 590 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 588 def refresh $driver.refresh end |
#select(element_name) ⇒ Object
- select
-
Select the element, can be used with checkbox or radio
- Input
-
Element_name => element name defined in JSON / CSV file
- Output
-
select the element
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.select(element_name)
506 507 508 509 510 511 512 513 514 515 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 506 def select(element_name) begin el(element_name).click rescue Exception => e #$LOG.error "error in selecting element \n element name : #{element_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in selecting element \n element name : #{element_name} "+e. end end |
#select_option(element_name, how = nil, what = nil) ⇒ Object
- Usage
-
element_name = company_dropdown dropdown should be selected by “value” value is “afour” $browser = Vanilla::PageAction $browser.select_option(‘company_dropdown’, :value, ‘afour’)
570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 570 def select_option(element_name, how=nil, what=nil) begin wait_and_find_element(element_name) el(element_name).click if how.nil? Selenium::WebDriver::Support::Select.new(el(element_name)).select_by(how, what) rescue Exception => e #$LOG.error "error in dropdown select option \n element name : #{element_name}, using #{how}, and #{what} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in dropdown select option \n element name : #{element_name}, using #{how}, and #{what} "+e. end end |
#selected?(element_name) ⇒ Boolean
- checkbox_checked(element_name, be_selected=true)
-
selecting and verifying check box is selected
- Input
-
Element_name => element name defined in JSON / CSV file
- Output
-
true or false
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.checkbox_checked(element_name, be_selected=true)
523 524 525 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 523 def selected?(element_name) el(element_name).selected? end |
#send_keys_text(element_name, text) ⇒ Object
- send_keys_text
-
sends the text value of text field or text area element name
- Input
-
parameter(element name) defined in JSON / CSV file parameter(text) send the text value in text field and text area
- Output
-
type the text value in text field and text area
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.send_keys_text(element_type, text)
334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 334 def send_keys_text(element_name, text) #$LOG.info "sending values of element name : #{element_name} and text_value : #{text} " wait_and_find_element(element_name) begin wait_and_find_element element_name send_value = el element_name send_value.send_keys text rescue Exception => e #$LOG.error "error in sending values of element name : #{element_name} and text_value : #{text} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "error in sending values element name : #{element_name} and text_value : #{text} "+e. end end |
#switch_default ⇒ Object
- switch_default
-
switches back to default frame
- O/P
-
Switch to the default frame
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.switch_default
614 615 616 617 618 619 620 621 622 623 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 614 def switch_default begin $driver.switch_to.default_content rescue Exception => e #$LOG.error " frame_name : #{frame_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "\n frame_name : #{frame_name} "+e. end end |
#switch_frame(frame_name) ⇒ Object
- switch_frame
-
it switch the frame to given frame id or index
- I/P
-
parameter(frame_name) : it requires the frame name or frame id
- O/P
-
Switch to the given frame else return the error message
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.switch_frame(frame_name)
598 599 600 601 602 603 604 605 606 607 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 598 def switch_frame(frame_name) begin $driver.switch_to.frame frame_name rescue Exception => e #$LOG.error " frame_name : #{frame_name} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "\n frame_name : #{frame_name} "+e. end end |
#title(expected_title) ⇒ Object
- title
-
It verify the title
- I/P
-
it takes input as expected title
- O/P
-
return true if page title matches with expected title else return false
- Information
-
This method uses a custom made rspec matchers
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.title(expected_title)
633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 633 def title(expected_title) #$LOG.info "Verifying the expected title #{expected_title}" #$driver.title begin expect($driver.title.to_s).to eq(expected_title) rescue Exception => e #$LOG.error "Error in getting the expected title #{expected_title} "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Error in getting the expected title #{expected_title} "+e. end end |
#value(element_name) ⇒ Object
- value
-
Get the value of element
- I/P
-
Parameter is defined “element name” in csv or json file
- O/P
-
Get the element value
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.value(element_name)
456 457 458 459 460 461 462 463 464 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 456 def value element_name begin el_attribute = el element_name el_attribute.attribute('value') rescue Exception => e #$LOG.error "error in getting element value \n element name : #{element_name} "+e.message raise "error in getting element value \n element name : #{element_name} "+e. end end |
#wait_and_find_element(element_name) ⇒ Object
wait_and_find_element: will wait for element
- I/P
-
Parameter is defined “element name” in csv or json file
- O/P
-
return true if element is appears in webpage else it will throw error
- usage
-
create the object of PageAction class
$browser = Vanilla::PageAction $browser.wait_and_find_element(element_name)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vanilla_selenium_wrapper/actions/page_actions.rb', line 136 def wait_and_find_element(element_name) #$LOG.info "Waiting for element #{element_name}" begin timeout = VanillaUtilityReader::VanillaFileReader::ConfigReader.configuration_reader timeout = timeout['wait'] if timeout == 0 timeout = 10 end wait_ele = el(element_name) wait = Selenium::WebDriver::Wait.new(timeout: timeout ) # seconds wait.until { wait_ele } rescue Exception => e #$LOG.error "Element is not displayed in specific time "+e.message # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png") # $webscreenshot = $webscreenshot+1 raise "Element is not displayed in specific time "+e. end end |