简体   繁体   中英

Minimize browser Robot Framework keyword

I have installed Robot Framework and created some test cases. I used the keyword Maximize Browser Window to maximize the browser but now I need to minimize the browser. I see the official documentation but I don't find a specific keyword, now I'm use:

  Set Window Size        ${0}       ${0}

but that isn't what I want. I want to minimize or run the test in background. Does anybody know how.

thanks in advance.

Great question, my company actually managed to accomplish this, but not the way you're thinking.

The short version is that it's probably impossible within normal Robot Framework, but we set up a persistent Linux VM and installed Jenkins and Robot Framework on it. This was then connected to the GitHub repository where builds are uploaded and set to run a new test on every push.

However, if you want to get into the internals of your particular browser, I found a way to guarantee that Chrome is started by Robot Framework maximized, so it might be possible to do the same thing, but in reverse. Assuming none of your keywords rely on xy coordinates, it should be fine. Robot Framework works just fine when the browser it's controlling is minimized.

Here's the code for what I did to start with.

Open Chrome
    [Arguments]     ${HOMEPAGE}
    ${options}  Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()   sys
    Call Method     ${options}  add_argument    --start-maximized
    Create WebDriver    Chrome  chrome_options=${options}
    Go To   ${HOMEPAGE}

Edit: After further discussion with senior developers, the answer is no. It is not possible as asked because Selenium needs an available element to interact with. It might not necessarily be visible to the eye, but it needs to be available to the program, and that is not the case when the browser window is minimized. When I changed my above code to "--start-minimized", it opened minimized and then promptly ran visibly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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