简体   繁体   English

"在机器人框架中使用已经打开的浏览器窗口"

[英]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 不能直接实现您的要求,但是从您写的内容来看,我可以看到一些改进的空间:

  • "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). “在系统中创建大量重复记录”=> 您应该在测试中使用 Teardown,以便在测试完成后清理系统(即使出现故障也会运行拆卸)。 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.并且还考虑通过 REST 或 SOAP 接口而不是浏览器直接运行部分测试。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM