简体   繁体   English

Robot Framework:在Robot框架中设置超时

[英]Robot Framework: Set Timeout in Robot framework

I have created a framework in which I have used Set Browser Implicit Wait 30 I have 50 suite that contains total of 700 test cases.我创建了一个框架,我在其中使用了Set Browser Implicit Wait 30我有 50 个套件,其中包含总共 700 个测试用例。 A few of the test cases (200 TC's) has steps to find if Element present and element not present.一些测试用例(200 个 TC)具有查找元素是否存在的步骤。 My Objective is that I do not want to wait until 30 seconds to check if Element Present or Element not Present.我的目标是我不想等到 30 秒才检查元素是否存在或元素不存在。 I tried using Wait Until Element Is Visible ${locator} timeout=10 , expecting to wait only 10 seconds for the Element, but it wait for 30 seconds.我尝试使用Wait Until Element Is Visible ${locator} timeout=10 ,期望只为元素等待 10 秒,但它等待了 30 秒。 Question: Can somebody help with the right approach to deal with such scenarios in my framework?问题:有人可以帮助以正确的方法处理我的框架中的此类情况吗? If I agree to wait until 30 seconds, the time taken to complete such test case will be more.如果我同意等到 30 秒,完成这样的测试用例所花费的时间将会更多。 I am trying to save 20*200 secs currently Please advise我目前正在尝试节省 20*200 秒 请指教

The simplest solution is to change the implicit wait right before checking that an element does not exist, and then changing it back afterwards. 最简单的解决方案是在检查元素不存在之前立即更改隐式等待,然后再将其更改回。 You can do this with the keyword set selenium implicit wait . 您可以使用关键字set selenium隐式等待来做到这一点。

For example, your keyword might look something like this: 例如,您的关键字可能看起来像这样:

*** Keywords ***
verify element is not on page
    [Arguments]  ${locator}
    ${old_wait}=  Set selenium implicit wait  10
    run keyword and continue on failure
    ...  page should not contain element  ${locator}
    set selenium implicit wait  ${old_wait}

You can simply add timeout="${Time}" next to the keyword you want to execute (Exp., Wait Until Page Contains Element ${locator} timeout=50)您可以简单地在要执行的关键字旁边添加 timeout="${Time}"(例如,等待页面包含元素 ${locator} timeout=50)

The problem you're running into deals with issue of " Implicit wait vs Explicit Wait ". 您遇到的问题涉及“ 隐式等待vs显式等待 ”问题。 Searching the internet will provide you with a lot of good explanations on why mixing is not recommended, but I think Jim Evans (Creator of IE Webdriver) explained it nicely in this stackoverflow answer . 在Internet上搜索将为您提供有关为什么不建议混合的很多很好的解释,但是我认为IE Webdriver的创建者Jim Evans在这个stackoverflow答案中很好地解释了它。

Improving the performance of your test run is typically done by utilizing one or both of these: 通常通过利用以下一项或两项来提高测试运行的性能:

  1. Shorten the duration of each individual test 缩短每次测试的时间
  2. Run test in parallel. 并行运行测试。

Shortening the duration of a test typically means being in complete control of the application under test resulting in the script knowing when the application has successfully loaded the moment it happens. 缩短测试持续时间通常意味着完全控制被测应用程序,从而使脚本知道应用程序在发生故障时已成功加载的时间。 This means having aa low or none Implicit wait and working exclusively with Fluent waits (waiting for a condition to occur). 这意味着隐式等待时间很短或没有,并且仅与Fluent等待(等待条件发生)一起使用。 This will result in your tests running at the speed your application allows. 这将使您的测试以应用程序允许的速度运行。

This may mean investing time understanding the application you test on a technical level. 这可能意味着需要花费时间来了解您在技术层面上测试的应用程序。 By using a custom locator you can still use all the regular SeleniumLibrary keywords and have a centralized waiting function. 通过使用自定义定位器,您仍然可以使用所有常规SeleniumLibrary关键字并具有集中式等待功能。

Running tests in parallel starts with having tests that run standalone and have no dependencies on other tests. 并行运行测试首先要使测试独立运行,并且不依赖于其他测试。 In Robot Framework this means having Test Suite Files that can run independently of each other. 在Robot Framework中,这意味着拥有可以彼此独立运行的Test Suite文件。 Most of us use Pabot to run our suites in parallel and merge the log file afterwards. 我们大多数人使用Pabot并行运行套件,然后合并日志文件。

Running several browser application tests in parallel means running more than 1 browser at the same time. 并行运行多个浏览器应用程序测试意味着同时运行多个浏览器。 If you test in Chrome, this can be done on a single host - though it's not always recommended. 如果您在Chrome中进行测试,则可以在单个主机上完成此操作-尽管并不总是建议这样做。 When you run IE then you require multiple boxes/sessions. 运行IE时,您需要多个框/会话。 Then you start to require a Selenium Grid type solution to distribute the execution load across multiple machines. 然后,您开始需要Selenium Grid类型的解决方案来在多台计算机之间分配执行负载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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