How to reduce Script run time

Hi, I have developed an automation script using Python-Robot Framework-Selenium.
The script takes around 30 mins to run. My client wants it to run in 10 mins. Is there any way to reduce the script run time. I have added Sleep at many places as page/locator takes time to load. Will *wait until element is visible* works in this case?
Any suggestions?

Yes, avoid explicit Sleep statements at all cost.
Use some of the Wait Until... Keywords of SeleniumLibrary instead to wait implicitely.
Also try Wait Until Keyword Suceeds from the BuiltIn Library for cases where you can’t find other solutions.

Also try to avoid UI/Webbrowser usage in general, where it is not absolutely needed.
Like: Do you really need to assert or set up everything in the WebBrowser? Is there maybe a Webservice that you can use instead? Especially when setting up preconditions, like the testdata there are often shortcuts by using the backend.

Is your script a single test case or multiple test cases in a test suites?
If they are multiple test cases, you can try running them in parallel using Pabot.

Using other Libraries like the “Browser Library” might also lead to some improved runtime, but would require a re-write of your tests.

2 Likes

Thanks for this. I am trying using pabot.
I have first test script for login and then it flows through different steps and final test script is of logout. When I run with pabot it logins and then close the browser.
One more thing

*** Settings ***
Suite Setup    Open Browser    ${URL}    chrome

*** Test Cases ***
Test Case 1
    [Tags]    Chrome
    Test1.robot

Test Case 2
    [Tags]    Chrome
    Test2.robot

It is not identifying the script names like Test2.robot.

Any suggestions

You cannot call a .robot suite from within a Test Case.
You can only run Keywords in a Test Case.

Here is the User Guide Chapter about the Test Case Syntax:
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-case-syntax

There is a short an official Tutorial on the Robot Framework Basics by the creator.
Maybe it is helpful to you

I recommend to NOT have a separate test case for the Login.
This will create an unneeded dependency between the Test Cases.
If the first Test Case - the Login - fails, everything else will fail.

Instead, if the Login is required by every Test Case in the beginning, set it up as a Test Setup.
That way you ensure that it is executed for every Test Case in the beginning.
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown

Also for the following Test Cases:
Try to avoid dependencies between them.
Do not make a
Test Case A created Customer
Test Case B updates that Customer
Test Case C deletes that Custumer

It will give you a lot of trouble when you want to parallelize and speed up the execution.

GitHub - MarketSquare/robotframework-seleniumtestability: Extension for SeleniumLibrary that provides manual and automatic waiting for asyncronous events like fetch, xhr, etc. - point of this plugin for SeleniumLibrary has always been to eliminate unnecessary sleeps. It does this by instrumenting the SUT (your page) with some javascript which then can be used to query the state of the page and prevent any UI actions while;

  • any api calls are being made to the server (fetch/ajax and stuff like that)
  • css animations/transitions

However, the project is not maintained anymore and probably wont even install on python 3.11 / 3.12 due to some issues.