Last active
May 30, 2023 19:39
-
-
Save 007bsd/38c8814fbb9576896053d89bb605532f to your computer and use it in GitHub Desktop.
Important robot commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. | |
| A: Rerun robot failed cases and Merge both them | |
| #-----First execute the robot tests which are under tests folder | |
| pybot -d results --output original.xml tests/mytest.robot | |
| #-------Rerun the failed tests | |
| pybot -d results --rerunfailed results/original.xml --output rerun.xml tests/mytest.robot | |
| #----Mergeboth the results | |
| rebot -d results --merge results/original.xml results/rerun.xml | |
| B: Include the tags while running | |
| pybot --i local -d results tests/mytest.robot | |
| C: Passing a variable from command line | |
| pybot --i local -v TESTENV:local -d results tests/mytest.robot | |
| 2. | |
| Scroll to Element | |
| [Documentation] Pass in a recognizable element selector; this keyword | |
| ... will scroll the pane to make it the top-most element. | |
| ... Optionally, change the ``vert_offset`` to another value | |
| ... to control how far "back" you want to scroll from the | |
| ... element (allows you to see elements above the element). | |
| [Arguments] ${the_element} #${vert_offset}=${23} | |
| Wait Until Page Contains Element ${the_element} timeout=5 seconds error=*HTML* <span style="color:red;font-weight:bold">φ</span> Scroll to Element:: unable to locate the element '${the_element}' | |
| ${vert_pos} = Get Vertical Position ${the_element} | |
| ${horz_pos} = Get Horizontal Position ${the_element} | |
| Execute JavaScript window.scrollTo(${horz_pos},${vert_pos} #- ${vert_offset}) | |
| 3: | |
| Execute javascript for xpath | |
| [Documentation] This keyword is to execute java script for xpah | |
| Execute Javascript window.document.evaluate("//li[contains(.,'Euro (EUR)')]"));", document, null,XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true); | |
| 4: | |
| Add downloaded files to download folder | |
| Set Global Variable ${global_downloadDir} ${CURDIR}${/}download | |
| ${chromeOptions}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| ${preferences} = Create Dictionary download.default_directory=${global_downloadDir} | |
| Call Method ${chromeOptions} add_experimental_option prefs ${preferences} | |
| Create Webdriver Chrome chrome_options=${chromeOptions} | |
| ####### | |
| Set Global Variable ${global_downloadDir} ${CURDIR}${/}download | |
| ${chrome options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| ${preferences} = Create Dictionary download.default_directory=${global_downloadDir} | |
| Call Method ${chrome options} add_argument headless | |
| Call Method ${chrome options} add_argument disable-gpu | |
| Call Method ${chromeOptions} add_experimental_option prefs ${preferences} | |
| Create Webdriver Chrome chrome_options=${chrome options} | |
| ######### | |
| 5. | |
| Running firefox in headless | |
| ${firefox options} = Evaluate sys.modules['selenium.webdriver'].firefox.webdriver.Options() sys, selenium.webdriver | |
| Call Method ${firefox options} add_argument -headless | |
| Create Webdriver Firefox firefox_options=${firefox options} | |
| 6. | |
| Running the tests in chrome headless | |
| ${chrome options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome options} add_argument headless | |
| Call Method ${chrome options} add_argument disable-gpu | |
| Create Webdriver Chrome chrome_options=${chrome options} | |
| 7. | |
| *** Settings *** | |
| Library Selenium2Library | |
| Suite Teardown Close All Browsers | |
| *** Test Cases *** | |
| Headless Chrome - Create Webdriver | |
| ${chrome options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome options} add_argument headless | |
| Call Method ${chrome options} add_argument disable-gpu | |
| ${options}= Call Method ${chrome_options} to_capabilities | |
| Create Webdriver Remote command_executor=http://localhost:4444/wd/hub desired_capabilities=${options} | |
| Go to http://cnn.com | |
| Maximize Browser Window | |
| Capture Page Screenshot | |
| 8. | |
| Headless Chrome - Open Browser | |
| ${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome_options} add_argument headless | |
| Call Method ${chrome_options} add_argument disable-gpu | |
| ${options}= Call Method ${chrome_options} to_capabilities | |
| Open Browser http://cnn.com browser=chrome remote_url=http://localhost:4444/wd/hub desired_capabilities=${options} | |
| Maximize Browser Window | |
| Capture Page Screenshot | |
| 9: | |
| Headless | |
| *** Settings *** | |
| Library SeleniumLibrary | |
| *** Variables *** | |
| ${URL} https://www.google.com/ | |
| ${BROWSER} Chrome | |
| *** Test Cases *** | |
| Test headless chrome | |
| Launch in chrome headless ${URL} | |
| Capture Page Screenshot | |
| *** Keywords *** | |
| Launch in chrome headless | |
| [Arguments] ${url} | |
| ${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome options} add_argument start-maximized | |
| Call Method ${chrome_options} add_argument --headless | |
| Call Method ${chrome_options} add_argument --disable-gpu | |
| Call Method ${chrome_options} add_argument --window-size\=1920,1080 | |
| Create Webdriver Chrome chrome_options=${chrome options} | |
| Go To ${url} | |
| 10: | |
| *** Settings *** | |
| Library Selenium2Library | |
| Suite Teardown Close All Browsers | |
| *** Test Cases *** | |
| Headless Chrome - Create Webdriver | |
| ${chrome options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome options} add_argument headless | |
| Call Method ${chrome options} add_argument disable-gpu | |
| ${options}= Call Method ${chrome_options} to_capabilities | |
| Create Webdriver Remote command_executor=http://localhost:4444/wd/hub desired_capabilities=${options} | |
| Go to http://cnn.com | |
| Maximize Browser Window | |
| Capture Page Screenshot | |
| Headless Chrome - Open Browser | |
| ${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome_options} add_argument headless | |
| Call Method ${chrome_options} add_argument disable-gpu | |
| ${options}= Call Method ${chrome_options} to_capabilities | |
| Open Browser http://cnn.com browser=chrome remote_url=http://localhost:4444/wd/hub desired_capabilities=${options} | |
| Maximize Browser Window | |
| Capture Page Screenshot | |
| 11. | |
| Chrome - without bar | |
| ${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver | |
| Call Method ${chrome_options} add_argument --disable-infobars | |
| Create Webdriver Chrome chrome_options=${chrome options} | |
| Go To http://cnn.com | |
| 12. | |
| Get authToken by Password Authentication | |
| RequestsLibrary.Create Session hook https://<url>/services/oauth2 verify=${True} | |
| ${data}= Create Dictionary grant_type=password client_id=1abc client_secret=2abc username=test@test.com password=keypass | |
| ${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded | |
| ${resp}= RequestsLibrary.Post Request hook /token data=${data} headers=${headers} | |
| Should Be Equal As Strings ${resp.status_code} 200 | |
| ${accessToken}= evaluate $resp.json().get(“access_token”) | |
| Log to Console ${accessToken} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment