Best Selenium code snippet using Selenium.WebDriver.perform
Class - Jobs Resource.rb
Source:Class - Jobs Resource.rb
...220 frameloopcount = 10221 select_customer = @driver.find_element(CUSTOMER_SEARCH_FIELD)222 select_customer.send_keys(selectcustomer)223 sleep(1)224 @driver.action.send_keys(:enter).perform225 sleep(1)226 select_customer_next = @driver.find_element(CUSTOMER_NEXT_BTN)227 select_customer_next.click228 loop do229 i += 1230 loop do231 f += 1232 begin233 @driver.switch_to.default_content234 @driver.switch_to.frame(0)235 rescue Selenium::WebDriver::Error::NoSuchFrameError236 false237 end238 break239 if f == frameloopcount240 raise FrameError241 end242 end243 begin244 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)245 wait2.until {@driver.find_element(NAME_FIELD).displayed?}246 rescue Selenium::WebDriver::Error::TimeoutError247 false248 end249 if250 begin251 @driver.find_element(NAME_FIELD).displayed? == true252 rescue Selenium::WebDriver::Error::NoSuchElementError253 false254 end255 break256 end257 if i == loopcount258 raise FrameError259 end260 end261 end262 def dev_select_customer(selectcustomer)263 i = 0264 loopcount = 5265 f = 0266 frameloopcount = 10267 select_customer = @driver.find_element(CUSTOMER_SEARCH_FIELD)268 select_customer.send_keys(selectcustomer)269 sleep(2)270 @driver.action.send_keys(:enter).perform271 sleep(2)272 select_customer_next = @driver.find_element(CUSTOMER_NEXT_BTN)273 select_customer_next.click274 loop do275 i += 1276 loop do277 f += 1278 begin279 @driver.switch_to.default_content280 @driver.switch_to.frame(0)281 rescue Selenium::WebDriver::Error::NoSuchFrameError282 false283 end284 break285 if f == frameloopcount286 raise FrameError287 end288 end289 begin290 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)291 wait2.until {@driver.find_element(NAME_FIELD).displayed?}292 rescue Selenium::WebDriver::Error::TimeoutError293 false294 end295 if296 begin297 @driver.find_element(NAME_FIELD).displayed? == true298 rescue Selenium::WebDriver::Error::NoSuchElementError299 false300 end301 break302 end303 if i == loopcount304 raise FrameError305 end306 end307 end308 def top()309 top_record = @driver.find_element(TOP_JOB)310 end311 def top_refnumber()312 top_refnumber = @driver.find_element(TOP_REFNUMBER)313 end314 def top_status()315 top_refnumber = @driver.find_element(TOP_STATUS)316 end317 def top_type()318 top_refnumber = @driver.find_element(TOP_TYPE)319 end320 def top_open()321 i = 0322 loopcount = 5323 wait = Selenium::WebDriver::Wait.new(:timeout => 5)324 wait.until {@driver.find_element(TOP_REFNUMBER).displayed?}325 top_refnumber = @driver.find_element(TOP_REFNUMBER)326 top_refnumber.click327 loop do328 i += 1329 @driver.switch_to.frame(0)330 begin331 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)332 wait2.until {@driver.find_element(NAME_FIELD).displayed?}333 rescue Selenium::WebDriver::Error::TimeoutError334 false335 end336 if337 begin338 @driver.find_element(NAME_FIELD).displayed? == true339 rescue Selenium::WebDriver::Error::NoSuchElementError340 false341 end342 break343 end344 if i == loopcount345 raise FrameError346 end347 end348 end349 def top_actions()350 wait = Selenium::WebDriver::Wait.new(:timeout => 5)351 wait.until {@driver.find_element(TOP_JOB_ACTIONS).displayed?}352 top_actions = @driver.find_element(TOP_JOB_ACTIONS)353 top_actions.click354 end355 def actions_createactivity()356 i = 0357 loopcount = 5358 wait = Selenium::WebDriver::Wait.new(:timeout => 5)359 wait.until {@driver.find_element(ACTIONS_CREATEACTIVITY).displayed?}360 top_createactivity = @driver.find_element(ACTIONS_CREATEACTIVITY)361 top_createactivity.click362 loop do363 i += 1364 @driver.switch_to.frame(0)365 begin366 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)367 wait2.until {@driver.find_element(ACTIVITY_REASON_DROPDOWN).displayed?}368 rescue Selenium::WebDriver::Error::TimeoutError369 false370 end371 if372 begin373 @driver.find_element(ACTIVITY_REASON_DROPDOWN).displayed? == true374 rescue Selenium::WebDriver::Error::NoSuchElementError375 false376 end377 break378 end379 if i == loopcount380 raise FrameError381 end382 end383 end384 def actions_createinvoice()385 i = 0386 loopcount = 5387 wait = Selenium::WebDriver::Wait.new(:timeout => 5)388 wait.until {@driver.find_element(ACTIONS_CREATEINVOICE).displayed?}389 top_createinvoice = @driver.find_element(ACTIONS_CREATEINVOICE)390 top_createinvoice.click391 @driver.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError392 loop do393 i += 1394 @driver.switch_to.frame(0)395 begin396 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)397 wait2.until {@driver.find_element(INVOICE_PONUMBER_FIELD).displayed?}398 rescue Selenium::WebDriver::Error::TimeoutError399 false400 end401 if402 begin403 @driver.find_element(INVOICE_PONUMBER_FIELD).displayed? == true404 rescue Selenium::WebDriver::Error::NoSuchElementError405 false406 end407 break408 end409 if i == loopcount410 raise FrameError411 end412 end413 end414 def actions_documents()415 #Only available in grid actions416 i = 0417 loopcount = 5418 wait = Selenium::WebDriver::Wait.new(:timeout => 5)419 wait.until {@driver.find_element(ACTIONS_DOCUMENTS).displayed?}420 top_documents = @driver.find_element(ACTIONS_DOCUMENTS)421 top_documents.click422 loop do423 i += 1424 @driver.switch_to.frame(0)425 begin426 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)427 wait2.until {@driver.find_element(DOCUMENTS_SHOWHIDE_UPLOADER).displayed?}428 rescue Selenium::WebDriver::Error::TimeoutError429 false430 end431 if432 begin433 @driver.find_element(DOCUMENTS_SHOWHIDE_UPLOADER).displayed? == true434 rescue Selenium::WebDriver::Error::NoSuchElementError435 false436 end437 break438 end439 if i == loopcount440 raise FrameError441 end442 end443 end444 def actions_printemail()445 i = 0446 loopcount = 5447 wait = Selenium::WebDriver::Wait.new(:timeout => 5)448 wait.until {@driver.find_element(ACTIONS_PRINTEMAIL).displayed?}449 top_printemail = @driver.find_element(ACTIONS_PRINTEMAIL)450 top_printemail.click451 loop do452 i += 1453 @driver.switch_to.frame(0)454 begin455 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)456 wait2.until {@driver.find_element(PRINTEMAIL_PDF_CHECKBOX).displayed?}457 rescue Selenium::WebDriver::Error::TimeoutError458 false459 end460 if461 begin462 @driver.find_element(PRINTEMAIL_PDF_CHECKBOX).displayed? == true463 rescue Selenium::WebDriver::Error::NoSuchElementError464 false465 end466 break467 end468 if i == loopcount469 raise FrameError470 end471 end472 end473 def actions_duplicatejob()474 i = 0475 loopcount = 5476 wait = Selenium::WebDriver::Wait.new(:timeout => 5)477 wait.until {@driver.find_element(ACTIONS_DUPLICATEJOB).displayed?}478 top_duplicate = @driver.find_element(ACTIONS_DUPLICATEJOB)479 top_duplicate.click480 loop do481 i += 1482 @driver.switch_to.frame(0)483 begin484 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)485 wait2.until {@driver.find_element(NAME_FIELD).displayed?}486 rescue Selenium::WebDriver::Error::TimeoutError487 false488 end489 if490 begin491 @driver.find_element(NAME_FIELD).displayed? == true492 rescue Selenium::WebDriver::Error::NoSuchElementError493 false494 end495 break496 end497 if i == loopcount498 raise FrameError499 end500 end501 end502 def actions_makeinactive()503 currenttopref = @driver.find_element(TOP_REFNUMBER).text504 wait = Selenium::WebDriver::Wait.new(:timeout => 5)505 wait.until {@driver.find_element(ACTIONS_MAKEINACTIVE).displayed?}506 top_makeinactive = @driver.find_element(ACTIONS_MAKEINACTIVE)507 top_makeinactive.click508 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)509 wait2.until {@driver.find_element(PUSH_CONFIRM).displayed?}510 confirm = @driver.find_element(PUSH_CONFIRM)511 confirm.click512 wait3 = Selenium::WebDriver::Wait.new(:timeout => 5)513 wait3.until {@driver.find_element(TOP_REFNUMBER).text != currenttopref}514 end515 def search_job(searchname)516 wait = Selenium::WebDriver::Wait.new(:timeout => 5)517 wait.until {@driver.find_element(SEARCH_FIELD).displayed?}518 job_search = @driver.find_element(SEARCH_FIELD)519 job_search.send_keys(searchname)520 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)521 wait2.until {@driver.find_element(SEARCH_BTN).displayed?}522 search_confirm = @driver.find_element(SEARCH_BTN)523 search_confirm.click524 wait3 = Selenium::WebDriver::Wait.new(:timeout => 10)525 wait3.until {@driver.find_element(TOP_JOB).text.downcase.include?(searchname.downcase)}526 end527 def search_jobid(searchname)528 i = 0529 loopcount = 5530 loop do531 wait = Selenium::WebDriver::Wait.new(:timeout => 5)532 if533 begin534 wait.until {@driver.find_element(ID_COLUMN).displayed?} == true535 rescue Selenium::WebDriver::Error::StaleElementReferenceError536 false537 end538 break539 if i == loopcount540 raise StaleError541 end542 end543 end544 job_search = @driver.find_element(ID_COLUMN)545 job_search.send_keys(searchname)546 @driver.action.send_keys(:enter).perform547 wait2 = Selenium::WebDriver::Wait.new(:timeout => 10)548 wait2.until {@driver.find_element(TOP_REFNUMBER).text.include?(searchname)}549 end550 def search_jobid_field()551 field = @driver.find_element(ID_COLUMN)552 end553 def search_jobname(searchname)554 i = 0555 loopcount = 5556 loop do557 wait = Selenium::WebDriver::Wait.new(:timeout => 5)558 if559 begin560 wait.until {@driver.find_element(NAME_COLUMN).displayed?} == true561 rescue Selenium::WebDriver::Error::StaleElementReferenceError562 false563 end564 break565 if i == loopcount566 raise StaleError567 end568 end569 end570 job_search = @driver.find_element(NAME_COLUMN)571 job_search.send_keys(searchname)572 @driver.action.send_keys(:enter).perform573 wait2 = Selenium::WebDriver::Wait.new(:timeout => 10)574 wait2.until {@driver.find_element(TOP_JOB).text.downcase.include?(searchname.downcase)}575 end576 def search_jobname_field()577 field = @driver.find_element(NAME_COLUMN)578 end579 def search_reset()580 currentrecords = @driver.find_element(class: "Counter_Message").text581 wait = Selenium::WebDriver::Wait.new(:timeout => 5)582 wait.until {@driver.find_element(RESET_BTN).displayed?}583 search_reset = @driver.find_element(RESET_BTN)584 search_reset.click585 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)586 wait2.until {@driver.find_element(class: "Counter_Message").text != currentrecords}587 end588 def grid_options()589 wait = Selenium::WebDriver::Wait.new(:timeout => 5)590 wait.until {@driver.find_element(GRID_OPTIONS_DROPDOWN).displayed?}591 grid_options = @driver.find_element(GRID_OPTIONS_DROPDOWN)592 grid_options.click593 end594 def export_jobs()595 wait = Selenium::WebDriver::Wait.new(:timeout => 5)596 wait.until {@driver.find_element(EXPORT_JOBS).displayed?}597 export_jobs = @driver.find_element(EXPORT_JOBS)598 export_jobs.click599 sleep(2)600 end601 def show_inactives()602 wait = Selenium::WebDriver::Wait.new(:timeout => 5)603 wait.until {@driver.find_element(SHOW_INACTIVES).displayed?}604 show_inactives = @driver.find_element(SHOW_INACTIVES)605 show_inactives.click606 end607 def grid_total()608 gridtotal = @driver.find_element(GRID_TOTAL)609 end610 def resource_performance()611 navigationStart = @driver.execute_script("return window.performance.timing.navigationStart")612 responseStart = @driver.execute_script("return window.performance.timing.responseStart")613 domComplete = @driver.execute_script("return window.performance.timing.domComplete")614 loadPerformance = domComplete - navigationStart615 wait = Selenium::WebDriver::Wait.new(:timeout => 20)616 wait.until {@driver.find_element(GRID_TOTAL).text != "0 records"}617 jobs_records = @driver.find_element(GRID_TOTAL)618 jobs_count = jobs_records.text619 print "Jobs: \n"620 print "%s \n" % jobs_count621 print "Load Time: %s ms \n\n" % loadPerformance622 end623 #CSS Methods: Popup624 def name(jobname)625 job_name = @driver.find_element(NAME_FIELD)626 job_name.send_keys(jobname)627 end628 def location(locationselect)629 dropdown_list = @driver.find_element(LOCATION_DROPDOWN)630 options = dropdown_list.find_elements(tag_name: 'option')631 options.each {|option| option.click if option.text == (locationselect)}632 end633 def type(typeselect)634 dropdown_list = @driver.find_element(TYPE_DROPDOWN)635 options = dropdown_list.find_elements(tag_name: 'option')636 options.each {|option| option.click if option.text == (typeselect)}637 end638 def customer(customername)639 customer_name = @driver.find_element(CUSTOMER_FIELD)640 customer_name.send_keys(customername)641 end642 def patrol(patrolname)643 patrol_name = @driver.find_element(PATROL_FIELD)644 patrol_name.send_keys(patrolname)645 end646 def estimate(estimatename)647 estimate_name = @driver.find_element(ESTIMATE_FIELD)648 estimate_name.send_keys(estimatename)649 end650 def po_number(ponumber)651 po_number = @driver.find_element(PONUMBER_FIELD)652 po_number.send_keys(ponumber)653 end654 def account_executive(accountexecutive)655 dropdown_list = @driver.find_element(ACCOUNT_EXECUTIVE_DROPDOWN)656 options = dropdown_list.find_elements(tag_name: 'option')657 options.each {|option| option.click if option.text == (accountexecutive)}658 end659 def nte(ntefield)660 po_number = @driver.find_element(NTE_FIELD)661 po_number.send_keys(ntefield)662 end663 def cancel()664 wait = Selenium::WebDriver::Wait.new(:timeout => 5)665 wait.until {@driver.find_element(CANCEL_BTN).displayed?}666 cancel_popup = @driver.find_element(CANCEL_BTN)667 cancel_popup.click668 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)669 wait2.until {@driver.find_element(TOP_PONUMBER).displayed?}670 end671 def actions()672 #Use actions_(action) methods from here673 wait = Selenium::WebDriver::Wait.new(:timeout => 5)674 wait.until {@driver.find_element(ACTIONS_BTN).displayed?}675 actions_popup = @driver.find_element(ACTIONS_BTN)676 actions_popup.click677 end678 def save()679 wait = Selenium::WebDriver::Wait.new(:timeout => 5)680 wait.until {@driver.find_element(SAVE_BTN).displayed?}681 save = @driver.find_element(SAVE_BTN)682 save.click683 end684 def save_close()685 wait = Selenium::WebDriver::Wait.new(:timeout => 5)686 wait.until {@driver.find_element(SAVE_AND_CLOSE_BTN).displayed?}687 save_and_close = @driver.find_element(SAVE_AND_CLOSE_BTN)688 save_and_close.click689 @driver.switch_to.default_content690 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)691 wait2.until {@driver.find_element(TOP_REFNUMBER).displayed?}692 end693 #CSS Methods: Popup (Lines)694 def lines_tab()695 wait = Selenium::WebDriver::Wait.new(:timeout => 5)696 wait.until {@driver.find_element(LINES_TAB).displayed?}697 lines_tab = @driver.find_element(LINES_TAB)698 lines_tab.click699 end700 def line1_service_date(servicedate1)701 wait = Selenium::WebDriver::Wait.new(:timeout => 5)702 wait.until {@driver.find_element(LINE1_SERVICE_DATE_SPAN).displayed?}703 span_field = @driver.find_element(LINE1_SERVICE_DATE_SPAN)704 span_field.click705 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)706 wait2.until {@driver.find_element(LINE1_SERVICE_DATE).displayed?}707 servicedate_field = @driver.find_element(LINE1_SERVICE_DATE)708 servicedate_field.send_keys(servicedate1)709 end710 def line1_item(item1)711 wait = Selenium::WebDriver::Wait.new(:timeout => 5)712 wait.until {@driver.find_element(LINE1_ITEM_SPAN).displayed?}713 span_field = @driver.find_element(LINE1_ITEM_SPAN)714 span_field.click715 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)716 wait2.until {@driver.find_element(LINE1_ITEM).displayed?}717 item_field = @driver.find_element(LINE1_ITEM)718 item_field.send_keys(item1)719 sleep(1)720 @driver.action.send_keys(:enter).perform721 sleep(1)722 end723 def line1_description(description1)724 wait = Selenium::WebDriver::Wait.new(:timeout => 5)725 wait.until {@driver.find_element(LINE1_DESCRIPTION).displayed?}726 span_field = @driver.find_element(LINE1_DESCRIPTION)727 span_field.click728 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)729 wait2.until {@driver.find_element(LINE1_DESCRIPTION_TEXTAREA).displayed?}730 item_field = @driver.find_element(LINE1_DESCRIPTION_TEXTAREA)731 item_field.send_keys(description1)732 sleep(1)733 @driver.action.send_keys(:enter).perform734 sleep(1)735 end736 def line1_quantity(quantity1)737 wait = Selenium::WebDriver::Wait.new(:timeout => 5)738 wait.until {@driver.find_element(LINE1_QUANTITY_SPAN).displayed?}739 span_field = @driver.find_element(LINE1_QUANTITY_SPAN)740 span_field.click741 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)742 wait2.until {@driver.find_element(LINE1_QUANTITY).displayed?}743 item_field = @driver.find_element(LINE1_QUANTITY)744 @driver.action.double_click(item_field).perform745 @driver.action.send_keys(:backspace)746 item_field.send_keys(quantity1)747 sleep(1)748 @driver.action.send_keys(:tab).perform749 sleep(1)750 end751 def line1_total(total1)752 wait = Selenium::WebDriver::Wait.new(:timeout => 5)753 wait.until {@driver.find_element(LINE1_TOTAL_SPAN).displayed?}754 span_total = @driver.find_element(LINE1_TOTAL_SPAN)755 span_total.click756 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)757 wait2.until {@driver.find_element(LINE1_TOTAL).displayed?}758 total = @driver.find_element(LINE1_TOTAL)759 total.send_keys(total1)760 end761 def line1_gettotal762 total = @driver.find_element(LINE1_TOTAL_SPAN).text.to_f763 end764 def line1_delete()765 wait = Selenium::WebDriver::Wait.new(:timeout => 5)766 wait.until {@driver.find_element(LINE1_DELETE).displayed?}767 trashcan = @driver.find_element(LINE1_DELETE)768 trashcan.click769 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)770 wait2.until {@driver.find_element(AJAX).displayed? == false}771 sleep(2)772 end773 def line2_service_date(servicedate2)774 wait = Selenium::WebDriver::Wait.new(:timeout => 5)775 wait.until {@driver.find_element(LINE2_SERVICE_DATE_SPAN).displayed?}776 span_field = @driver.find_element(LINE2_SERVICE_DATE_SPAN)777 span_field.click778 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)779 wait2.until {@driver.find_element(LINE2_SERVICE_DATE).displayed?}780 servicedate_field = @driver.find_element(LINE2_SERVICE_DATE)781 servicedate_field.send_keys(servicedate2)782 end783 def line2_item(item2)784 wait = Selenium::WebDriver::Wait.new(:timeout => 5)785 wait.until {@driver.find_element(LINE2_ITEM_SPAN).displayed?}786 span_field = @driver.find_element(LINE2_ITEM_SPAN)787 span_field.click788 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)789 wait2.until {@driver.find_element(LINE2_ITEM).displayed?}790 item_field = @driver.find_element(LINE2_ITEM)791 item_field.send_keys(item2)792 sleep(1)793 @driver.action.send_keys(:enter).perform794 sleep(1)795 end796 def line2_description(description2)797 wait = Selenium::WebDriver::Wait.new(:timeout => 5)798 wait.until {@driver.find_element(LINE2_DESCRIPTION).displayed?}799 span_field = @driver.find_element(LINE2_DESCRIPTION)800 span_field.click801 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)802 wait2.until {@driver.find_element(LINE2_DESCRIPTION_TEXTAREA).displayed?}803 item_field = @driver.find_element(LINE2_DESCRIPTION_TEXTAREA)804 item_field.send_keys(description2)805 sleep(1)806 @driver.action.send_keys(:enter).perform807 sleep(1)808 end809 def line2_quantity(quantity2)810 wait = Selenium::WebDriver::Wait.new(:timeout => 5)811 wait.until {@driver.find_element(LINE2_QUANTITY_SPAN).displayed?}812 span_field = @driver.find_element(LINE2_QUANTITY_SPAN)813 span_field.click814 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)815 wait2.until {@driver.find_element(LINE2_QUANTITY).displayed?}816 item_field = @driver.find_element(LINE2_QUANTITY)817 @driver.action.double_click(item_field).perform818 @driver.action.send_keys(:backspace)819 item_field.send_keys(quantity2)820 sleep(1)821 @driver.action.send_keys(:tab).perform822 sleep(1)823 end824 def line2_total(total2)825 wait = Selenium::WebDriver::Wait.new(:timeout => 5)826 wait.until {@driver.find_element(LINE2_TOTAL_SPAN).displayed?}827 span_total = @driver.find_element(LINE2_TOTAL_SPAN)828 span_total.click829 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)830 wait2.until {@driver.find_element(LINE2_TOTAL).displayed?}831 total = @driver.find_element(LINE2_TOTAL)832 total.send_keys(total2)833 end834 def line2_gettotal835 total = @driver.find_element(LINE2_TOTAL_SPAN).text.to_f836 end837 def line2_delete()838 wait = Selenium::WebDriver::Wait.new(:timeout => 5)839 wait.until {@driver.find_element(LINE2_DELETE).displayed?}840 trashcan = @driver.find_element(LINE2_DELETE)841 trashcan.click842 end843 def line3_service_date(servicedate3)844 wait = Selenium::WebDriver::Wait.new(:timeout => 5)845 wait.until {@driver.find_element(LINE3_SERVICE_DATE_SPAN).displayed?}846 span_field = @driver.find_element(LINE3_SERVICE_DATE_SPAN)847 span_field.click848 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)849 wait2.until {@driver.find_element(LINE3_SERVICE_DATE).displayed?}850 servicedate_field = @driver.find_element(LINE3_SERVICE_DATE)851 servicedate_field.send_keys(servicedate3)852 end853 def line3_item(item3)854 wait = Selenium::WebDriver::Wait.new(:timeout => 5)855 wait.until {@driver.find_element(LINE3_ITEM_SPAN).displayed?}856 span_field = @driver.find_element(LINE3_ITEM_SPAN)857 span_field.click858 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)859 wait2.until {@driver.find_element(LINE3_ITEM).displayed?}860 item_field = @driver.find_element(LINE3_ITEM)861 item_field.send_keys(item3)862 sleep(1)863 @driver.action.send_keys(:enter).perform864 sleep(1)865 end866 def line3_description(description3)867 wait = Selenium::WebDriver::Wait.new(:timeout => 5)868 wait.until {@driver.find_element(LINE3_DESCRIPTION).displayed?}869 span_field = @driver.find_element(LINE3_DESCRIPTION)870 span_field.click871 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)872 wait2.until {@driver.find_element(LINE3_DESCRIPTION_TEXTAREA).displayed?}873 item_field = @driver.find_element(LINE3_DESCRIPTION_TEXTAREA)874 item_field.send_keys(description3)875 sleep(1)876 @driver.action.send_keys(:enter).perform877 sleep(1)878 end879 def line3_quantity(quantity3)880 wait = Selenium::WebDriver::Wait.new(:timeout => 5)881 wait.until {@driver.find_element(LINE3_QUANTITY_SPAN).displayed?}882 span_field = @driver.find_element(LINE3_QUANTITY_SPAN)883 span_field.click884 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)885 wait2.until {@driver.find_element(LINE3_QUANTITY).displayed?}886 item_field = @driver.find_element(LINE3_QUANTITY)887 @driver.action.double_click(item_field).perform888 @driver.action.send_keys(:backspace)889 item_field.send_keys(quantity3)890 sleep(1)891 @driver.action.send_keys(:tab).perform892 sleep(1)893 end894 def line3_total(total3)895 wait = Selenium::WebDriver::Wait.new(:timeout => 5)896 wait.until {@driver.find_element(LINE3_TOTAL_SPAN).displayed?}897 span_total = @driver.find_element(LINE3_TOTAL_SPAN)898 span_total.click899 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)900 wait2.until {@driver.find_element(LINE3_TOTAL).displayed?}901 total = @driver.find_element(LINE3_TOTAL)902 total.send_keys(total3)903 end904 def line3_gettotal905 total = @driver.find_element(LINE3_TOTAL_SPAN).text.to_f...
Class - Invoices Resource.rb
Source:Class - Invoices Resource.rb
...177 frameloopcount = 10178 select_job = @driver.find_element(JOB_SEARCH_FIELD)179 select_job.send_keys(selectjob)180 sleep(1)181 @driver.action.send_keys(:enter).perform182 sleep(1)183 select_job_next = @driver.find_element(JOB_NEXT_BTN)184 select_job_next.click185 loop do186 i += 1187 loop do188 f += 1189 begin190 @driver.switch_to.default_content191 @driver.switch_to.frame(0)192 rescue Selenium::WebDriver::Error::NoSuchFrameError193 false194 end195 break196 if f == frameloopcount197 raise FrameError198 end199 end200 begin201 wait2 = Selenium::WebDriver::Wait.new(:timeout => 8)202 wait2.until {@driver.find_element(INVOICE_DATE_FIELD).displayed?}203 rescue Selenium::WebDriver::Error::TimeoutError204 false205 end206 if207 begin208 @driver.find_element(INVOICE_DATE_FIELD).displayed? == true209 rescue Selenium::WebDriver::Error::NoSuchElementError210 false211 end212 break213 end214 if i == loopcount215 raise FrameError216 end217 end218 end219 def select_jobdev(selectjob)220 i = 0221 loopcount = 5222 select_job = @driver.find_element(JOB_SEARCH_FIELD)223 select_job.send_keys(selectjob)224 sleep(1)225 @driver.action.send_keys(:enter).perform226 sleep(1)227 select_job_next = @driver.find_element(JOB_NEXT_BTN)228 select_job_next.click229 wait = Selenium::WebDriver::Wait.new(:timeout => 10)230 wait.until {@driver.find_element(FRAME).displayed?}231 loop do232 i += 1233 @driver.switch_to.frame(0)234 begin235 wait2 = Selenium::WebDriver::Wait.new(:timeout => 8)236 wait2.until {@driver.find_element(INVOICE_DATE_FIELD).displayed?}237 rescue Selenium::WebDriver::Error::TimeOutError238 false239 end240 if241 begin242 @driver.find_element(INVOICE_DATE_FIELD).displayed? == true243 rescue Selenium::WebDriver::Error::NoSuchElementError244 false245 end246 break247 end248 if i == loopcount249 raise FrameError250 end251 end252 end253 def top()254 top_record = @driver.find_element(TOP_INVOICE)255 end256 def top_jobname()257 top_record = @driver.find_element(TOP_JOBNAME)258 end259 def top_refnumber()260 top_refnumber = @driver.find_element(TOP_REFNUMBER)261 end262 def top_qbid()263 top_qbid = @driver.find_element(TOP_QBID)264 end265 def top_nsid()266 top_qbid = @driver.find_element(TOP_NSID)267 end268 def top_ponumber()269 top_ponumber = @driver.find_element(TOP_PONUMBER)270 end271 def top_open()272 i = 0273 loopcount = 5274 wait = Selenium::WebDriver::Wait.new(:timeout => 10)275 wait.until {@driver.find_element(TOP_REFNUMBER).displayed?}276 top_refnumber = @driver.find_element(TOP_REFNUMBER)277 top_refnumber.click278 loop do279 i += 1280 @driver.switch_to.frame(0)281 begin282 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)283 wait2.until {@driver.find_element(INVOICE_DATE_FIELD).displayed?}284 rescue Selenium::WebDriver::Error::TimeOutError285 false286 end287 if288 begin289 @driver.find_element(INVOICE_DATE_FIELD).displayed? == true290 rescue Selenium::WebDriver::Error::NoSuchElementError291 false292 end293 break294 end295 if i == loopcount296 raise FrameError297 end298 end299 end300 def top_actions()301 wait = Selenium::WebDriver::Wait.new(:timeout => 10)302 wait.until {@driver.find_element(TOP_INVOICE_ACTIONS).displayed?}303 top_actions = @driver.find_element(TOP_INVOICE_ACTIONS)304 top_actions.click305 end306 def actions_createactivity()307 i = 0308 loopcount = 5309 wait = Selenium::WebDriver::Wait.new(:timeout => 5)310 wait.until {@driver.find_element(ACTIONS_CREATEACTIVITY).displayed?}311 top_createactivity = @driver.find_element(ACTIONS_CREATEACTIVITY)312 top_createactivity.click313 loop do314 i += 1315 @driver.switch_to.frame(0)316 begin317 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)318 wait2.until {@driver.find_element(ACTIVITY_REASON_DROPDOWN).displayed?}319 rescue Selenium::WebDriver::Error::TimeOutError320 false321 end322 if323 begin324 @driver.find_element(ACTIVITY_REASON_DROPDOWN).displayed? == true325 rescue Selenium::WebDriver::Error::NoSuchElementError326 false327 end328 break329 end330 if i == loopcount331 raise FrameError332 end333 end334 end335 def actions_documents()336 i = 0337 loopcount = 5338 wait = Selenium::WebDriver::Wait.new(:timeout => 5)339 wait.until {@driver.find_element(ACTIONS_DOCUMENTS).displayed?}340 top_documents = @driver.find_element(ACTIONS_DOCUMENTS)341 top_documents.click342 loop do343 i += 1344 @driver.switch_to.frame(0)345 begin346 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)347 wait2.until {@driver.find_element(DOCUMENTS_SHOWHIDE_UPLOADER).displayed?}348 rescue Selenium::WebDriver::Error::TimeOutError349 false350 end351 if352 begin353 @driver.find_element(DOCUMENTS_SHOWHIDE_UPLOADER).displayed? == true354 rescue Selenium::WebDriver::Error::NoSuchElementError355 false356 end357 break358 end359 if i == loopcount360 raise FrameError361 end362 end363 end364 def actions_printemail()365 i = 0366 loopcount = 5367 wait = Selenium::WebDriver::Wait.new(:timeout => 5)368 wait.until {@driver.find_element(ACTIONS_PRINTEMAIL).displayed?}369 top_printemail = @driver.find_element(ACTIONS_PRINTEMAIL)370 top_printemail.click371 loop do372 i += 1373 @driver.switch_to.frame(0)374 begin375 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)376 wait2.until {@driver.find_element(PRINTEMAIL_PDF_CHECKBOX).displayed?}377 rescue Selenium::WebDriver::Error::TimeOutError378 false379 end380 if381 begin382 @driver.find_element(PRINTEMAIL_PDF_CHECKBOX).displayed? == true383 rescue Selenium::WebDriver::Error::NoSuchElementError384 false385 end386 break387 end388 if i == loopcount389 raise FrameError390 end391 end392 end393 def search_invoice(searchname)394 wait = Selenium::WebDriver::Wait.new(:timeout => 5)395 wait.until {@driver.find_element(SEARCH_FIELD).displayed?}396 job_search = @driver.find_element(SEARCH_FIELD)397 job_search.send_keys(searchname)398 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)399 wait2.until {@driver.find_element(SEARCH_BTN).displayed?}400 search_confirm = @driver.find_element(SEARCH_BTN)401 search_confirm.click402 wait3 = Selenium::WebDriver::Wait.new(:timeout => 10)403 wait3.until {@driver.find_element(TOP_JOBNAME).text.downcase.include?(searchname.downcase)}404 end405 def search_invoiceid(searchname)406 i = 0407 loopcount = 5408 loop do409 wait = Selenium::WebDriver::Wait.new(:timeout => 5)410 if411 begin412 wait.until {@driver.find_element(ID_COLUMN).displayed?} == true413 rescue Selenium::WebDriver::Error::StaleElementReferenceError414 false415 end416 break417 if i == loopcount418 raise StaleError419 end420 end421 end422 invoice_search = @driver.find_element(ID_COLUMN)423 invoice_search.send_keys(searchname)424 @driver.action.send_keys(:enter).perform425 wait2 = Selenium::WebDriver::Wait.new(:timeout => 10)426 wait2.until {@driver.find_element(TOP_REFNUMBER).text.include?(searchname)}427 end428 def search_invoiceid_field()429 field = @driver.find_element(ID_COLUMN)430 end431 def search_invoicename(searchname)432 i = 0433 loopcount = 5434 loop do435 wait = Selenium::WebDriver::Wait.new(:timeout => 5)436 if437 begin438 wait.until {@driver.find_element(NAME_COLUMN).displayed?} == true439 rescue Selenium::WebDriver::Error::StaleElementReferenceError440 false441 end442 break443 if i == loopcount444 raise StaleError445 end446 end447 end448 invoice_search = @driver.find_element(NAME_COLUMN)449 invoice_search.send_keys(searchname)450 @driver.action.send_keys(:enter).perform451 wait2 = Selenium::WebDriver::Wait.new(:timeout => 10)452 wait2.until {@driver.find_element(TOP_INVOICE).text.downcase.include?(searchname.downcase)}453 end454 def search_invoicename_field()455 field = @driver.find_element(NAME_COLUMN)456 end457 def search_reset()458 currentrecords = @driver.find_element(class: "Counter_Message").text459 wait = Selenium::WebDriver::Wait.new(:timeout => 5)460 wait.until {@driver.find_element(RESET_BTN).displayed?}461 search_reset = @driver.find_element(RESET_BTN)462 search_reset.click463 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)464 wait2.until {@driver.find_element(class: "Counter_Message").text != currentrecords}465 end466 def grid_options()467 wait = Selenium::WebDriver::Wait.new(:timeout => 5)468 wait.until {@driver.find_element(GRID_OPTIONS_DROPDOWN).displayed?}469 grid_options = @driver.find_element(GRID_OPTIONS_DROPDOWN)470 grid_options.click471 end472 def export_invoices()473 wait = Selenium::WebDriver::Wait.new(:timeout => 5)474 wait.until {@driver.find_element(EXPORT_INVOICES).displayed?}475 export_jobs = @driver.find_element(EXPORT_INVOICES)476 export_jobs.click477 sleep(2)478 end479 def show_inactives()480 wait = Selenium::WebDriver::Wait.new(:timeout => 5)481 wait.until {@driver.find_element(SHOW_INACTIVES).displayed?}482 show_inactives = @driver.find_element(SHOW_INACTIVES)483 show_inactives.click484 end485 def qbo_verify()486 wait = Selenium::WebDriver::Wait.new(:timeout => 10)487 wait.until {@driver.find_element(TOP_QBID).displayed?}488 qbid = @driver.find_element(TOP_QBID)489 qbid_display = qbid.text490 expect(qbid_display).not_to eq("")491 print "QBID: %s" % qbid_display492 end493 def ns_verify()494 wait = Selenium::WebDriver::Wait.new(:timeout => 10)495 wait.until {@driver.find_element(TOP_NSID).displayed?}496 nsid = @driver.find_element(TOP_NSID)497 nsid_display = nsid.text498 expect(qbid_display).not_to eq("")499 print "NS Invoice Number: %s" % nsid_display500 end501 def grid_total()502 gridtotal = @driver.find_element(GRID_TOTAL)503 end504 def resource_performance()505 navigationStart = @driver.execute_script("return window.performance.timing.navigationStart")506 responseStart = @driver.execute_script("return window.performance.timing.responseStart")507 domComplete = @driver.execute_script("return window.performance.timing.domComplete")508 loadPerformance = domComplete - navigationStart509 wait = Selenium::WebDriver::Wait.new(:timeout => 20)510 wait.until {@driver.find_element(GRID_TOTAL).text != "0 records"}511 invoices_records = @driver.find_element(GRID_TOTAL)512 invoices_count = invoices_records.text513 print "Invoices: \n"514 print "%s \n" % invoices_count515 print "Load Time: %s ms \n\n" % loadPerformance516 end517 #CSS Methods: Popup518 def invoice_date(invoicedate)519 wait = Selenium::WebDriver::Wait.new(:timeout => 10)520 wait.until {@driver.find_element(INVOICE_DATE_FIELD).displayed?}521 invoice_date = @driver.find_element(INVOICE_DATE_FIELD)522 invoice_date.send_keys(jobname)523 end524 def terms(termsselect)525 wait = Selenium::WebDriver::Wait.new(:timeout => 10)526 wait.until {@driver.find_element(TERMS_DROPDOWN).displayed?}527 dropdown_list = @driver.find_element(TERMS_DROPDOWN)528 options = dropdown_list.find_elements(tag_name: 'option')529 options.each {|option| option.click if option.text == (termsselect)}530 end531 def due_date(duedate)532 wait = Selenium::WebDriver::Wait.new(:timeout => 10)533 wait.until {@driver.find_element(DUE_DATE_FIELD).displayed?}534 duedate = @driver.find_element(DUE_DATE_FIELD)535 duedate.send_keys(duedate)536 end537 def location(locationselect)538 dropdown_list = @driver.find_element(LOCATION_DROPDOWN)539 options = dropdown_list.find_elements(tag_name: 'option')540 options.each {|option| option.click if option.text == (locationselect)}541 end542 def class(classselect)543 wait = Selenium::WebDriver::Wait.new(:timeout => 10)544 wait.until {@driver.find_element(CLASS_DROPDOWN).displayed?}545 dropdown_list = @driver.find_element(CLASS_DROPDOWN)546 options = dropdown_list.find_elements(tag_name: 'option')547 options.each {|option| option.click if option.text == (classselect)}548 end549 def line_business(lineofbusiness)550 wait = Selenium::WebDriver::Wait.new(:timeout => 10)551 wait.until {@driver.find_element(LINE_OF_BUSINESS_DROPDOWN).displayed?}552 dropdown_list = @driver.find_element(LINE_OF_BUSINESS_DROPDOWN)553 options = dropdown_list.find_elements(tag_name: 'option')554 options.each {|option| option.click if option.text == (lineofbusiness)}555 end556 def po_number(ponumber)557 wait = Selenium::WebDriver::Wait.new(:timeout => 10)558 wait.until {@driver.find_element(PONUMBER_FIELD).displayed?}559 po_number = @driver.find_element(PONUMBER_FIELD)560 po_number.send_keys(ponumber)561 end562 def account_executive(accountexecutive)563 wait = Selenium::WebDriver::Wait.new(:timeout => 10)564 wait.until {@driver.find_element(ACCOUNT_EXECUTIVE_DROPDOWN).displayed?}565 dropdown_list = @driver.find_element(ACCOUNT_EXECUTIVE_DROPDOWN)566 options = dropdown_list.find_elements(tag_name: 'option')567 options.each {|option| option.click if option.text == (accountexecutive)}568 end569 def commission(comissionschedule)570 wait = Selenium::WebDriver::Wait.new(:timeout => 10)571 wait.until {@driver.find_element(COMMISSION_SCHEDULE_DROPDOWN).displayed?}572 dropdown_list = @driver.find_element(COMMISSION_SCHEDULE_DROPDOWN)573 options = dropdown_list.find_elements(tag_name: 'option')574 options.each {|option| option.click if option.text == (comissionschedule)}575 end576 def cancel()577 wait = Selenium::WebDriver::Wait.new(:timeout => 5)578 wait.until {@driver.find_element(CANCEL_BTN).displayed?}579 cancel_popup = @driver.find_element(CANCEL_BTN)580 cancel_popup.click581 @driver.switch_to.default_content582 end583 def actions()584 #Use actions_(action) methods from here585 wait = Selenium::WebDriver::Wait.new(:timeout => 5)586 wait.until {@driver.find_element(ACTIONS_BTN).displayed?}587 actions_popup = @driver.find_element(ACTIONS_BTN)588 actions_popup.click589 end590 def actions_viewjob()591 #Only accessible in popup actions592 i = 0593 loopcount = 5594 wait = Selenium::WebDriver::Wait.new(:timeout => 5)595 wait.until {@driver.find_element(ACTIONS_VIEWJOB).displayed?}596 viewjob = @driver.find_element(ACTIONS_VIEWJOB)597 viewjob.click598 loop do599 i += 1600 @driver.switch_to.frame(0)601 begin602 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)603 wait2.until {@driver.find_element(JOB_NAME_FIELD).displayed?}604 rescue Selenium::WebDriver::Error::TimeOutError605 false606 end607 if608 begin609 @driver.find_element(JOB_NAME_FIELD).displayed? == true610 rescue Selenium::WebDriver::Error::NoSuchElementError611 false612 end613 break614 end615 if i == loopcount616 raise FrameError617 end618 end619 end620 def actions_viewcustomer()621 #Only accessible in popup actions622 i = 0623 loopcount = 5624 wait = Selenium::WebDriver::Wait.new(:timeout => 5)625 wait.until {@driver.find_element(ACTIONS_VIEWCUSTOMER).displayed?}626 viewcustomer = @driver.find_element(ACTIONS_VIEWCUSTOMER)627 viewcustomer.click628 loop do629 i += 1630 @driver.switch_to.frame(0)631 begin632 wait2 = Selenium::WebDriver::Wait.new(:timeout => 2)633 wait2.until {@driver.find_element(CUSTOMER_NAME_FIELD).displayed?}634 rescue Selenium::WebDriver::Error::TimeOutError635 false636 end637 if638 begin639 @driver.find_element(CUSTOMER_NAME_FIELD).displayed? == true640 rescue Selenium::WebDriver::Error::NoSuchElementError641 false642 end643 break644 end645 if i == loopcount646 raise FrameError647 end648 end649 end650 def actions_pushtoqbo()651 #Only accessible in popup actions652 wait = Selenium::WebDriver::Wait.new(:timeout => 5)653 wait.until {@driver.find_element(ACTIONS_PUSHTOQBO).displayed?}654 pushtoqbo = @driver.find_element(ACTIONS_PUSHTOQBO)655 pushtoqbo.click656 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)657 wait2.until {@driver.find_element(PUSH_CONFIRM).displayed?}658 confirm = @driver.find_element(PUSH_CONFIRM)659 confirm.click660 wait3 = Selenium::WebDriver::Wait.new(:timeout => 5)661 wait3.until {@driver.find_element(CANCEL_BTN).displayed?}662 end663 def actions_pushtons()664 #Only accessible in popup actions665 wait = Selenium::WebDriver::Wait.new(:timeout => 5)666 wait.until {@driver.find_element(ACTIONS_PUSHTONS).displayed?}667 pushtons = @driver.find_element(ACTIONS_PUSHTONS)668 pushtons.click669 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)670 wait2.until {@driver.find_element(PUSH_CONFIRM).displayed?}671 confirm = @driver.find_element(PUSH_CONFIRM)672 confirm.click673 wait3 = Selenium::WebDriver::Wait.new(:timeout => 5)674 wait3.until {@driver.find_element(CANCEL_BTN).displayed?}675 end676 def actions_pullfromqbo()677 #Only accessible in popup actions678 wait = Selenium::WebDriver::Wait.new(:timeout => 5)679 wait.until {@driver.find_element(ACTIONS_PULLFROMQBO).displayed?}680 pullfromqbo = @driver.find_element(ACTIONS_PULLFROMQBO)681 pullfromqbo.click682 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)683 wait2.until {@driver.find_element(CANCEL_BTN).displayed?}684 end685 def actions_viewinqbo()686 #Only accessible in popup actions687 wait = Selenium::WebDriver::Wait.new(:timeout => 5)688 wait.until {@driver.find_element(ACTIONS_VIEWINQBO).displayed?}689 viewqbo = @driver.find_element(ACTIONS_VIEWINQBO)690 viewqbo.click691 end692 def save()693 wait = Selenium::WebDriver::Wait.new(:timeout => 5)694 wait.until {@driver.find_element(SAVE_BTN).displayed?}695 save = @driver.find_element(SAVE_BTN)696 save.click697 end698 def save_close()699 wait = Selenium::WebDriver::Wait.new(:timeout => 5)700 wait.until {@driver.find_element(SAVE_AND_CLOSE_BTN).displayed?}701 save_and_close = @driver.find_element(SAVE_AND_CLOSE_BTN)702 save_and_close.click703 @driver.switch_to.default_content704 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)705 wait2.until {@driver.find_element(TOP_REFNUMBER).displayed?}706 end707 #CSS Methods: Popup (Lines)708 def lines_tab()709 wait = Selenium::WebDriver::Wait.new(:timeout => 5)710 wait.until {@driver.find_element(LINES_TAB).displayed?}711 lines_tab = @driver.find_element(LINES_TAB)712 lines_tab.click713 end714 def line1_service_date(servicedate1)715 wait = Selenium::WebDriver::Wait.new(:timeout => 5)716 wait.until {@driver.find_element(LINE1_SERVICE_DATE_SPAN).displayed?}717 span_field = @driver.find_element(LINE1_SERVICE_DATE_SPAN)718 span_field.click719 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)720 wait2.until {@driver.find_element(LINE1_SERVICE_DATE).displayed?}721 servicedate_field = @driver.find_element(LINE1_SERVICE_DATE)722 servicedate_field.send_keys(servicedate1)723 end724 def line1_item(item1)725 wait = Selenium::WebDriver::Wait.new(:timeout => 5)726 wait.until {@driver.find_element(LINE1_ITEM_SPAN).displayed?}727 span_field = @driver.find_element(LINE1_ITEM_SPAN)728 span_field.click729 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)730 wait2.until {@driver.find_element(LINE1_SERVICE_DATE).displayed?}731 item_field = @driver.find_element(LINE1_SERVICE_DATE)732 item_field.send_keys(item1)733 sleep(1)734 @driver.action.send_keys(:enter).perform735 sleep(1)736 end737 def line1_description(description1)738 wait = Selenium::WebDriver::Wait.new(:timeout => 5)739 wait.until {@driver.find_element(LINE1_DESCRIPTION).displayed?}740 span_field = @driver.find_element(LINE1_DESCRIPTION)741 span_field.click742 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)743 wait2.until {@driver.find_element(LINE1_DESCRIPTION_TEXTAREA).displayed?}744 item_field = @driver.find_element(LINE1_DESCRIPTION_TEXTAREA)745 item_field.send_keys(description1)746 sleep(1)747 @driver.action.send_keys(:enter).perform748 sleep(1)749 end750 def line1_delete()751 wait = Selenium::WebDriver::Wait.new(:timeout => 5)752 wait.until {@driver.find_element(LINE1_DELETE).displayed?}753 trashcan = @driver.find_element(LINE1_DELETE)754 trashcan.click755 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)756 wait2.until {@driver.find_element(AJAX).displayed? == false}757 sleep(1)758 end759 def line2_service_date(servicedate2)760 wait = Selenium::WebDriver::Wait.new(:timeout => 5)761 wait.until {@driver.find_element(LINE2_SERVICE_DATE_SPAN).displayed?}762 span_field = @driver.find_element(LINE2_SERVICE_DATE_SPAN)763 span_field.click764 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)765 wait2.until {@driver.find_element(LINE2_SERVICE_DATE).displayed?}766 servicedate_field = @driver.find_element(LINE2_SERVICE_DATE)767 servicedate_field.send_keys(servicedate2)768 end769 def line2_item(item2)770 wait = Selenium::WebDriver::Wait.new(:timeout => 5)771 wait.until {@driver.find_element(LINE2_ITEM_SPAN).displayed?}772 span_field = @driver.find_element(LINE2_ITEM_SPAN)773 span_field.click774 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)775 wait2.until {@driver.find_element(LINE2_SERVICE_DATE).displayed?}776 item_field = @driver.find_element(LINE2_SERVICE_DATE)777 item_field.send_keys(item2)778 sleep(1)779 @driver.action.send_keys(:enter).perform780 sleep(1)781 end782 def line2_description(description2)783 wait = Selenium::WebDriver::Wait.new(:timeout => 5)784 wait.until {@driver.find_element(LINE2_DESCRIPTION).displayed?}785 span_field = @driver.find_element(LINE2_DESCRIPTION)786 span_field.click787 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)788 wait2.until {@driver.find_element(LINE2_DESCRIPTION_TEXTAREA).displayed?}789 item_field = @driver.find_element(LINE2_DESCRIPTION_TEXTAREA)790 item_field.send_keys(description2)791 sleep(1)792 @driver.action.send_keys(:enter).perform793 sleep(1)794 end795 def line2_delete()796 wait = Selenium::WebDriver::Wait.new(:timeout => 5)797 wait.until {@driver.find_element(LINE2_DELETE).displayed?}798 trashcan = @driver.find_element(LINE2_DELETE)799 trashcan.click800 wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)801 wait2.until {@driver.find_element(AJAX).displayed? == false}802 sleep(1)803 end804 def add_lines()805 wait = Selenium::WebDriver::Wait.new(:timeout => 5)806 wait.until {@driver.find_element(ADD_LINES).displayed?}...
action_builder.rb
Source:action_builder.rb
1module Selenium2 module WebDriver3 #4 # The ActionBuilder provides the user a way to set up and perform5 # complex user interactions.6 #7 # This class should not be instantiated directly, but is created by8 # Selenium::WebDriver::DriverExtensions::HasInputDevices#action, which9 # is available on Driver instances that support the user interaction API.10 #11 # @example12 #13 # driver.action.key_down(:shift).14 # click(element).15 # click(second_element).16 # key_up(:shift).17 # drag_and_drop(element, third_element).18 # perform19 #20 class ActionBuilder21 #22 # @api private23 #24 def initialize(mouse, keyboard)25 @devices = {26 :mouse => mouse,27 :keyboard => keyboard28 }29 @actions = []30 end31 #32 # Performs a modifier key press. Does not release33 # the modifier key - subsequent interactions may assume it's kept pressed.34 # Note that the modifier key is never released implicitly - either35 # #key_up(key) or #send_keys(:null) must be called to release the modifier.36 #37 # Equivalent to:38 # driver.action.click(element).send_keys(key)39 # # or40 # driver.action.click.send_keys(key)41 #42 # @example Press a key43 #44 # driver.action.key_down(:control).perform45 #46 # @example Press a key on an element47 #48 # el = driver.find_element(:id, "some_id")49 # driver.action.key_down(el, :shift).perform50 #51 # @param [:shift, :alt, :control, :command, :meta] The key to press.52 # @param [Selenium::WebDriver::Element] element An optional element53 # @raise [ArgumentError] if the given key is not a modifier54 # @return [ActionBuilder] A self reference.55 #56 def key_down(*args)57 if args.first.kind_of? Element58 @actions << [:mouse, :click, [args.shift]]59 end60 @actions << [:keyboard, :press, args]61 self62 end63 #64 # Performs a modifier key release.65 # Releasing a non-depressed modifier key will yield undefined behaviour.66 #67 # @example Release a key68 #69 # driver.action.key_up(:shift).perform70 #71 # @example Release a key from an element72 #73 # el = driver.find_element(:id, "some_id")74 # driver.action.key_up(el, :alt).perform75 #76 # @param [:shift, :alt, :control, :command, :meta] The modifier key to release.77 # @param [Selenium::WebDriver::Element] element An optional element78 # @raise [ArgumentError] if the given key is not a modifier key79 # @return [ActionBuilder] A self reference.80 #81 def key_up(*args)82 if args.first.kind_of? Element83 @actions << [:mouse, :click, [args.shift]]84 end85 @actions << [:keyboard, :release, args]86 self87 end88 #89 # Sends keys to the active element. This differs from calling90 # Element#send_keys(keys) on the active element in two ways:91 #92 # * The modifier keys included in this call are not released.93 # * There is no attempt to re-focus the element - so send_keys(:tab) for switching elements should work.94 #95 # @example Send the text "help" to an element96 #97 # el = driver.find_element(:id, "some_id")98 # driver.action.send_keys(el, "help").perform99 #100 # @example Send the text "help" to the currently focused element101 #102 # driver.action.send_keys("help").perform103 #104 # @param [Selenium::WebDriver::Element] element An optional element105 # @param [String] keys The keys to be sent.106 # @return [ActionBuilder] A self reference.107 #108 def send_keys(*args)109 if args.first.kind_of? Element110 @actions << [:mouse, :click, [args.shift]]111 end112 @actions << [:keyboard, :send_keys, args]113 self114 end115 #116 # Clicks (without releasing) in the middle of the given element. This is117 # equivalent to:118 #119 # driver.action.move_to(element).click_and_hold120 #121 # @example Clicking and holding on some element122 #123 # el = driver.find_element(:id, "some_id")124 # driver.action.click_and_hold(el).perform125 #126 # @param [Selenium::WebDriver::Element] element the element to move to and click.127 # @return [ActionBuilder] A self reference.128 #129 def click_and_hold(element = nil)130 @actions << [:mouse, :down, [element]]131 self132 end133 #134 # Releases the depressed left mouse button at the current mouse location.135 #136 # @example Releasing an element after clicking and holding it137 #138 # el = driver.find_element(:id, "some_id")139 # driver.action.click_and_hold(el).release.perform140 #141 # @return [ActionBuilder] A self reference.142 #143 def release(element = nil)144 @actions << [:mouse, :up, [element]]145 self146 end147 #148 # Clicks in the middle of the given element. Equivalent to:149 #150 # driver.action.move_to(element).click151 #152 # When no element is passed, the current mouse position will be clicked.153 #154 # @example Clicking on an element155 #156 # el = driver.find_element(:id, "some_id")157 # driver.action.click(el).perform158 #159 # @example Clicking at the current mouse position160 #161 # driver.action.click.perform162 #163 # @param [Selenium::WebDriver::Element] element An optional element to click.164 # @return [ActionBuilder] A self reference.165 #166 def click(element = nil)167 @actions << [:mouse, :click, [element]]168 self169 end170 #171 # Performs a double-click at middle of the given element. Equivalent to:172 #173 # driver.action.move_to(element).double_click174 #175 # @example Double click an element176 #177 # el = driver.find_element(:id, "some_id")178 # driver.action.double_click(el).perform179 #180 # @param [Selenium::WebDriver::Element] element An optional element to move to.181 # @return [ActionBuilder] A self reference.182 #183 def double_click(element = nil)184 @actions << [:mouse, :double_click, [element]]185 self186 end187 #188 # Moves the mouse to the middle of the given element. The element is scrolled into189 # view and its location is calculated using getBoundingClientRect. Then the190 # mouse is moved to optional offset coordinates from the element.191 #192 # Note that when using offsets, both coordinates need to be passed.193 #194 # @example Scroll element into view and move the mouse to it195 #196 # el = driver.find_element(:id, "some_id")197 # driver.action.move_to(el).perform198 #199 # @example200 #201 # el = driver.find_element(:id, "some_id")202 # driver.action.move_to(el, 100, 100).perform203 #204 # @param [Selenium::WebDriver::Element] element to move to.205 # @param [Integer] right_by Optional offset from the top-left corner. A negative value means206 # coordinates right from the element.207 # @param [Integer] down_by Optional offset from the top-left corner. A negative value means208 # coordinates above the element.209 # @return [ActionBuilder] A self reference.210 #211 def move_to(element, right_by = nil, down_by = nil)212 if right_by && down_by213 @actions << [:mouse, :move_to, [element, right_by, down_by]]214 else215 @actions << [:mouse, :move_to, [element]]216 end217 self218 end219 #220 # Moves the mouse from its current position (or 0,0) by the given offset.221 # If the coordinates provided are outside the viewport (the mouse will222 # end up outside the browser window) then the viewport is scrolled to223 # match.224 #225 # @example Move the mouse to a certain offset from its current position226 #227 # driver.action.move_by(100, 100).perform228 #229 # @param [Integer] right_by horizontal offset. A negative value means moving the230 # mouse left.231 # @param [Integer] down_by vertical offset. A negative value means moving the mouse232 # up.233 # @return [ActionBuilder] A self reference.234 # @raise [MoveTargetOutOfBoundsError] if the provided offset is outside235 # the document's boundaries.236 #237 def move_by(right_by, down_by)238 @actions << [:mouse, :move_by, [right_by, down_by]]239 self240 end241 #242 # Performs a context-click at middle of the given element. First performs243 # a move_to to the location of the element.244 #245 # @example Context-click at middle of given element246 #247 # el = driver.find_element(:id, "some_id")248 # driver.action.context_click(el).perform249 #250 # @param [Selenium::WebDriver::Element] element An element to context click.251 # @return [ActionBuilder] A self reference.252 #253 def context_click(element = nil)254 @actions << [:mouse, :context_click, [element]]255 self256 end257 #258 # A convenience method that performs click-and-hold at the location of the259 # source element, moves to the location of the target element, then260 # releases the mouse.261 #262 # @example Drag and drop one element onto another263 #264 # el1 = driver.find_element(:id, "some_id1")265 # el2 = driver.find_element(:id, "some_id2")266 # driver.action.drag_and_drop(el1, el2).perform267 #268 # @param [Selenium::WebDriver::Element] source element to emulate button down at.269 # @param [Selenium::WebDriver::Element] target element to move to and release the270 # mouse at.271 # @return [ActionBuilder] A self reference.272 #273 def drag_and_drop(source, target)274 click_and_hold source275 move_to target276 release target277 self278 end279 #280 # A convenience method that performs click-and-hold at the location of281 # the source element, moves by a given offset, then releases the mouse.282 #283 # @example Drag and drop an element by offset284 #285 # el = driver.find_element(:id, "some_id1")286 # driver.action.drag_and_drop_by(el, 100, 100).perform287 #288 # @param [Selenium::WebDriver::Element] source Element to emulate button down at.289 # @param [Integer] right_by horizontal move offset.290 # @param [Integer] down_by vertical move offset.291 # @param [Selenium::WebDriver::Element] target Element to move to and release the292 # mouse at.293 # @return [ActionBuilder] A self reference.294 #295 def drag_and_drop_by(source, right_by, down_by)296 click_and_hold source297 move_by right_by, down_by298 release299 self300 end301 #302 # Executes the actions added to the builder.303 #304 def perform305 @actions.each { |receiver, method, args|306 @devices.fetch(receiver).__send__(method, *args)307 }308 nil309 end310 end # ActionBuilder311 end # WebDriver312end # Selenium...
chrome_node.rb
Source:chrome_node.rb
...54 super55 end56 end57private58 def perform_legacy_drag(element)59 return super if chromedriver_fixed_actions_key_state? || !w3c? || element.obscured?60 # W3C Chrome/chromedriver < 77 doesn't maintain mouse button state across actions API performs61 # https://bugs.chromium.org/p/chromedriver/issues/detail?id=298162 browser_action.release.perform63 browser_action.click_and_hold(native).move_to(element.native).release.perform64 end65 def file_errors66 @file_errors = ::Selenium::WebDriver.logger.suppress_deprecations do67 [::Selenium::WebDriver::Error::ExpectedError]68 end69 end70 def w3c?71 (defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||72 capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)73 end74 def browser_version(to_float = true)75 caps = capabilities76 ver = (caps[:browser_version] || caps[:version])77 ver = ver.to_f if to_float...
action_builder_spec.rb
Source:action_builder_spec.rb
...10 keyboard.should_receive(:send_keys).with("abc")11 keyboard.should_receive(:release).with(:control)12 builder.key_down(:shift).13 send_keys("abc").14 key_up(:control).perform15 end16 it "should pass an element to keyboard actions" do17 mouse.should_receive(:click).with(element)18 keyboard.should_receive(:press).with(:shift)19 builder.key_down(element, :shift).perform20 end21 it "should allow supplying individual elements to keyboard actions" do22 element2 = Selenium::WebDriver::Element.new(bridge, 'element2')23 element3 = Selenium::WebDriver::Element.new(bridge, 'element3')24 mouse.should_receive(:click).with(element)25 keyboard.should_receive(:press).with(:shift)26 mouse.should_receive(:click).with(element2)27 keyboard.should_receive(:send_keys).with("abc")28 mouse.should_receive(:click).with(element3)29 keyboard.should_receive(:release).with(:control)30 builder.key_down(element, :shift ).31 send_keys(element2, "abc").32 key_up(element3, :control).perform33 end34 it "should create all mouse actions" do35 mouse.should_receive(:down).with(element)36 mouse.should_receive(:up).with(element)37 mouse.should_receive(:click).with(element)38 mouse.should_receive(:double_click).with(element)39 mouse.should_receive(:move_to).with(element)40 mouse.should_receive(:context_click).with(element)41 builder.click_and_hold(element).42 release(element).43 click(element).44 double_click(element).45 move_to(element).46 context_click(element).perform47 end48 it "should drag and drop" do49 source = element50 target = Selenium::WebDriver::Element.new(bridge, 'element2')51 mouse.should_receive(:down).with(source)52 mouse.should_receive(:move_to).with(target)53 mouse.should_receive(:up)54 builder.drag_and_drop(source, target).perform55 end56 it "should drag and drop with offsets" do57 source = element58 mouse.should_receive(:down).with(source)59 mouse.should_receive(:move_by).with(-300, 400)60 mouse.should_receive(:up)61 builder.drag_and_drop_by(source, -300, 400).perform62 end63 it "can move the mouse by coordinates" do64 mouse.should_receive(:down).with(element)65 mouse.should_receive(:move_by).with(-300, 400)66 mouse.should_receive(:up)67 builder.click_and_hold(element).68 move_by(-300, 400).69 release.perform70 end71 it 'can click, hold and release at the current location' do72 mouse.should_receive(:down).with(nil)73 mouse.should_receive(:up)74 builder.click_and_hold.release.perform75 end76end...
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'btnG').click13driver.find_element(:name, 'q').send_keys "Selenium WebDriver"14driver.find_element(:name,
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'btnG').click
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'q').submit3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'q').submit5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'q').submit7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'q').submit9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'q').submit11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'q').submit
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'btnG').click
perform
Using AI Code Generation
1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')4element = driver.find_element(:name, 'q')5element = driver.find_element(:name, 'q')6element = driver.find_element(:name, 'q')
perform
Using AI Code Generation
1element = driver.find_element(:name, 'q')2wait = Selenium::WebDriver::Wait.new(:timeout => 10)3wait.until { driver.title.downcase.start_with? "selenium webdriver" }
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'btnG').click
perform
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'q').submit3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'q').submit5driver.find_element(:name, 'q').send_keys "Selenium WebDriver"6driver.find_element(:name, 'q').submit7driver.find_element(:name, 'q').send_keys "Selenium WebDriver"8driver.find_element(:name, 'q').submit9driver.find_element(:name, 'q').send_keys "Selenium WebDriver"10driver.find_element(:name, 'q').submit11driver.find_element(:name, 'q').send_keys "Selenium WebDriver"12driver.find_element(:name, 'q').submit
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!