[英]Using already opened Browser window in Robot framework
We are using Robot Framework for writing/automating acceptance test cases.我们正在使用 Robot Framework 来编写/自动化验收测试用例。
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.下一次运行将使用相同的浏览器窗口和下一个命令,之后它在最后一次运行中失败。
What you ask is not directly possible with Robot/Selenium, but from what you write, I can see room for some improvements: Robot/Selenium 不能直接实现您的要求,但是从您写的内容来看,我可以看到一些改进的空间:
Here is a geckodriver example for Firefox (win)这是 Firefox (win) 的 geckodriver 示例
Start your Firefox with marionette enabled (standard port is 2828)在启用木偶的情况下启动 Firefox(标准端口为 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}
In my case, I was setting off warning emails from the target website, about logging in from a new device, every time I logged in during testing.就我而言,每次在测试期间登录时,我都会从目标网站发出警告电子邮件,关于从新设备登录。 Instead, I wanted to log in a single time<\/strong> and then resume the same (authenticated) browser session during subsequent runs.相反,我想登录一次<\/strong>,然后在后续运行期间恢复相同的(经过身份验证的)浏览器会话。
To do this, the key is that you need to point the webdriver to the same user data directory so that subsequent runs can resume the browser session.为此,关键是您需要将 webdriver 指向相同的用户数据目录,以便后续运行可以恢复浏览器会话。 For my needs, I created a local directory called user-data<\/code> .
根据我的需要,我创建了一个名为
user-data<\/code>的本地目录。
I then defined:然后我定义:
Open Browser Profiled
[Arguments] ${url}
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${options} add_argument --user-data-dir\=${./user-data}
Create WebDriver Chrome chrome_options=${options}
Go To ${url}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.