0

I had been asked a question in interview like,

Question : we have 1000 lines of code, after every line webdriver should wait for 5 secs, how will u do this?

Answer i told : You can create a function using implicit wait, and put the code in for loop, for each iteration ask to run that wait function.

They told this was not correct way of doing.

Could you please suggest me the best way to handle this...

  • I suggest to review pretty similar question http://stackoverflow.com/a/23787258/2504101 – olyv Jun 25 '14 at 11:12
  • Implicit and Explicit waits are a way of handling similar requirements: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits – grumpasaurus Jun 26 '14 at 13:04
  • My own personal opinion is that these interview questions should only be reserved for quick hit contract jobs because knowledge of a tool is what you're paying for. A full timer interview shouldn't have interview questions like this. – grumpasaurus Jun 26 '14 at 13:06

2 Answers2

0

Frankly I would have asked them what is the purpose of forcing a test to take a minimum of 83.3333 minutes to execute.

If this is for visual ability, then who are they going to get to sit there for an hour and a half and just watch a test run...If it is for the application then there are much better ways to ensure something is loaded then to just put 5 seconds on everything.

As far as registering an event that fires for each Selenium command goes, the link provided by olyv in the above comment is a great place to start.

Personally though I would prefer to create a wrapper for the Selenium commands so that it isn't just an event, but I can execute any amount of common code within the wrapper and then when executing the command I just push it all through the wrapper. There are various ways to do this, but it is custom code to add-on or encapsulate Selenium API's. Then the actual seconds is in a config file for easy adjusting. I have found this approach very useful in many situations.

mutt
  • 783
  • 1
  • 7
  • 11
0

If we suppose that every line calls to a WebDriver function, with AspectJ you can detect when a function has been called and execute a code when it finishes. For example:

@Aspect
public class WebdriverAfterAspect {

   int waitTime = 5;

   @After("regular expression that represents the name a Webdriver function")
   public void logStringArguments(String name){
      wait(waitTime);
   }    
}

You have many examples here

rafaborrego
  • 610
  • 1
  • 8
  • 19