26

I want to reduce the speed for execution of script so that I can view the execution properly on browser. I want do this in webdriver.

11 Answers 11

9

You can try setting implicit wait time. (Documentation)

// 5 seconds implicit wait (C# code)
IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
  • 6
    How does this help to reduce execution speed?? This still takes actions as soon as the element is found. – FDM Aug 16 '17 at 7:36
  • 3
    This doesn't slow down the execution, as per it's declaration: "Specifies the amount of time the driver should wait when searching for an element if it is not immediately present" – Chris Aug 17 '17 at 14:58
9

This is how I would debug a Selenium session to find out what is happening:

Step-by-step debugging: Most IDE's allow you todo step-by-step debugging, you could set a break point just before the point you want to investigate. This will pause the execution of the test and lets you examine the browser with its own tools. You can step thru each line of code one by one and monitor the behavior. See this video for example

Video recording: Record the test session with a screen-recorder or use one of the online Selenium grids like Sauce labs or TestingBot, both offer to record of the test session by default and give enough free minutes to analyze most issues. After the recording, you can playback frame by frame.

Sleeps: Like others suggest, you can add a sleep or increase the default wait-times. Personally, I am not a fan of this because you might need to rerun the test a couple of times if the sleep is not long enough.

1

You could put a sleep after every instruction - or around the instructions you are interested in.

  • I can use sleep that is not something which I am looking for. I want to slow the execution. I don't want to pause it. In Selenium IDE we were having option to control it. Is there any property in selenium web driver for this? – Ashwani Raj Apr 29 '14 at 12:29
  • 3
    Why do you want to slow the execution??? – Phil Kirkham Apr 29 '14 at 13:32
  • 2
    Just to view on browser that whatever I wrote in script is performing well on browser. – Ashwani Raj May 1 '14 at 11:45
1

Some tools allow for defining before scenario, after scenario, before step, after step - hooks, which are called as a setup or teardown for a scenario or even for a separate step in it. If you do have such hooks, then add a delay into an "after step" hook and you'll be fine.

1

The easiest way to do that in selenium webDriver is to extend your preferred WebDriver (e.g. FirefoxDriver) and override the execute methods.

Write a Thread.sleep(yourWaitTime) in every execute method before return.

Voila there is your speed reduce:

@Override
protected Response execute(String driverCommand, Map<String, ?> parameters) {
    try {
        // wait 500 millis and after that run command
        Thread.sleep(500);
    } catch (InterruptedException ex) {}
    return super.execute(driverCommand, parameters);
}
  • 1
    Whats the added value over using the accepted answer? ImplicitlyWait setting does the same, not? – Niels van Reijmersdal Jun 8 '15 at 10:08
  • @NielsvanReijmersdal No, at least according to its documentation (Selenium 3.0.1): Specifies the amount of time the driver should wait when searching for an element if it is not immediately present.. – SantiBailors Mar 1 '17 at 13:17
1

I've been looking into this quite a lot over the past few days. By far the simplest way to solve this is to create a driver property, rather than a variable and add a wait to the get.

  private IWebDriver _driver;
    public IWebDriver driver
    {
        get{ Thread.Sleep(500);
            return _driver;
        }

        set
        { _driver = value; }
    }

This means that anytime your driver is requested, which is anytime you do anything in the browser, it will slow it down by the specified amount.

0

There is several different ways to do this. I personally have a UI that controls my automation script that allows me to go step by step (in record mode or playback), full automation or however I like. Just build a UI to control the flow and then have different functions that can be controlled by the UI as needed.

For example, a step by step UI would do a function called nextStep() nextStep would find the next desired step and perform that action.

A fully automated one would check a boolean for true while automating and as long as it's true, it keeps going. Set up a pause/stop button that changes that boolean and that is done.

In order to create functionality like this, in a simplistic way:

Create a UI that lists out your test steps, how you do this is up to you. I made mine editable and drag and drop within a table (JTree for Suites, JList for Cases, JTable for Steps).

Add Stop and Play ToggleButtons on the UI in a button group Add an actionEventListener to the play button that grabs the selected step(s) and runs them. Between each step have it check that the play button is still selected. When it is no longer selected, the execution will stop.

For things like groovy script just add in a groovy console and create a trigger (IE. Keyword being Groovy=script) and then have the console parse that whenever it sees it.

I also added in keywords like screenshot, pause, wait and such. This gives the ability for the system to stop automatically until user intervention occurs.

  • Of what tool do you speak? Does it interface with webdriver? – boatcoder May 5 '14 at 21:37
  • It is a custom built system that A) Dynamically records flows B) Allows the end user to Edit the flows and add Groovy script to the test case C) Controls the runs of the flows and yes, it is built on top of the WebDriver – Paul Muir May 6 '14 at 15:51
  • I'm guessing it's not available then.... – boatcoder May 6 '14 at 15:54
  • 2
    Sadly, no. I will edit and put the steps I used in order to create the UI in my post. It was really simple. – Paul Muir May 6 '14 at 16:09
0

Firefox selenium web extension has an option to make the test run slower or faster using a sliding bar. Not sure if IE or Chrome has this if not i would just use the debugger.

0

By looking at your question I have one possible solution for you.

If your test platform supports it, try adding priority to each test method, because multiple @Test methods run in parallel.

  • How does this add to or improve on the accepted answer? – Kate Paulk Oct 5 '15 at 11:21
0

I don't have enough reputation to comment, but I think Eduard Sukharev above has the best answer - i.e. to add a wait to your after step code, as this involves just a one line change that you can easily add/remove. This is how I've done it in a couple of frameworks:

In Behat, I added a sleep to the after step:

/**
* @AfterStep
*/
public function after_step(AfterStepScope $scope) {
    //whatever else you want to do in the after_step
    sleep (x); //x is the number of seconds to sleep before continuing
}

In Robot framework, there's a function called 'Set Selenium Speed' which will wait the specified number of seconds between steps.

0

I also tried but could not figure out how to slow down selenium execution, and then i tried workaround to slow it down. Used 'net limitter' tool to control network bandwidth (trial version is available), you can put bandwidth limit to chrome driver so that it will communicate with selenium server and chrome browser slowly. This way you can simulate slow execution of test suites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.