31

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.

2
  • 1
    Is there a reason why you want to do this? Commented Apr 29, 2014 at 11:58
  • I am not sure about necessity of it but if you really need it then you can use EventFiringWebDriver stackoverflow.com/a/23787258/2504101
    – olyv
    Commented Jun 11, 2014 at 13:01

13 Answers 13

7

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));
2
  • 7
    How does this help to reduce execution speed?? This still takes actions as soon as the element is found.
    – FDM
    Commented Aug 16, 2017 at 7:36
  • 5
    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
    Commented Aug 17, 2017 at 14:58
13

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.

3

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.

1

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

3
  • 1
    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? Commented Apr 29, 2014 at 12:29
  • 3
    Why do you want to slow the execution??? Commented Apr 29, 2014 at 13:32
  • 2
    Just to view on browser that whatever I wrote in script is performing well on browser. Commented May 1, 2014 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);
}
2
  • 1
    Whats the added value over using the accepted answer? ImplicitlyWait setting does the same, not? Commented Jun 8, 2015 at 10:08
  • 1
    @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.. Commented Mar 1, 2017 at 13:17
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.

4
  • Of what tool do you speak? Does it interface with webdriver?
    – boatcoder
    Commented May 5, 2014 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
    Commented May 6, 2014 at 15:51
  • I'm guessing it's not available then....
    – boatcoder
    Commented May 6, 2014 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
    Commented May 6, 2014 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.

1
  • How does this add to or improve on the accepted answer?
    – Kate Paulk
    Commented Oct 5, 2015 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.

0

I think this will slow down each step by sleep interval of 3 seconds. Try it

WebDriverWait driverWait = new WebDriverWait( new SystemClock(), Driver, TimeSpan.FromSeconds( 20 ), TimeSpan.FromSeconds( 3 ) );

TimeSpan.FromSeconds( 3 ) is the sleep interval here.

Note: I am using ChromeDriver.

0

If you are looking to slow down or pause your execution, press F8 (if you are using chrome). If you are looking to get some info from the dev tool you have open the dev tool first and then press F8 (or function F8 on mac). This will pause your browser. I hope this help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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