'Using already opened Browser window in Robot framework
We are using Robot Framework for writing/automating acceptance test cases.
Every time i need to run the whole script to check the last lines of code of my script, That Wastes lot of time and creates lots of duplicate records in the system, i just wanted to avoid re-running whole script to check last lines of code and resume the execution from the point where it erred in previous run.
That is to say;If the test run throws error; it will not just close the browser window; And next run will use the same browser window with next command in sequence after which it had failed in last run.
Solution 1:[1]
What you ask is not directly possible with Robot/Selenium, but from what you write, I can see room for some improvements:
- "creates lots of duplicate records in the system" => you should have Teardown in your tests that clean the system when the tests are finished (and teardown are run even when there is a failure). So next time you run the tests, the system starts clean
- "That Wastes lot of time" => if your tests are too long to run, maybe you should consider splitting them in smaller chunks. And also consider running part of your tests directly via the REST or SOAP interface instead of the browser.
Solution 2:[2]
Here is a geckodriver example for Firefox (win)
Start your Firefox with marionette enabled (standard port is 2828)
"C:\Program Files\Mozilla Firefox\firefox.exe" --marionette
Robot example script
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${BROWSER} Firefox
${GECKODRIVER EXE} c:/MY_GECKODRIVER_PATH/geckodriver.exe
${GECKODRIVER LOG} C:/MY_GECKODRIVER_LOG_PATH/log.txt
*** Test Cases ***
Firefox Browser Test
Init Webdriver
Go To https://www.google.com
*** Keywords ***
Init Webdriver
${service_args}= Create List --connect-existing --marionette-port=2828 --marionette-host=127.0.0.1
Create Webdriver ${BROWSER} executable_path=${GECKODRIVER EXE} service_args=${service_args} service_log_path=${GECKODRIVER LOG}
-- Chrome example --
Start Chrome with remote debugging enabled (port is 9222)
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
Robot example script
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Variables ***
${BROWSER} Chrome
${CHROMEDRIVER EXE} c:/MY_CHROMEDRIVER_PATH/chromedriver93.exe
${CHROMEDRIVER LOG} c:/MY_CHROMEDRIVER_LOG_PATH/chromedriver_log.txt
*** Test Cases ***
Chrome Browser Test
Init Webdriver
Go To https://stackoverflow.com
*** Keywords ***
Init Webdriver
${service_args}= Create List --log-path=${CHROMEDRIVER LOG} --verbose
${chromeOptions}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys,selenium.webdriver
${chromeCapabilities}= Call Method ${chromeOptions} to_capabilities
Set To Dictionary ${chromeCapabilities["goog:chromeOptions"]} debuggerAddress 127.0.0.1:9222
Create WebDriver ${BROWSER} desired_capabilities=${chromeCapabilities} executable_path=${CHROMEDRIVER EXE} service_args=${service_args}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurent Bristiel |
| Solution 2 |
