0

Currently, I have five instances of phantomjs set up on my Selenium Grid all on different nodes. I am trying to run 5 parallel tests at once, but some of these tests will fail. Each time, it is a different test that will fail on different lines.

I have also put in waits and assertions to wait until the element shows up, but the test cases are still failing in different spots each time. When I run the tests one by one however, all of the tests pass 100% of the time.

Is there any way I can optimize my tests for parallel execution?

My tests are written in Java in a Windows environment. I am using phantomjs 1.9.8 and Selenium 3.54

Jay
  • 61
  • 2
  • 14
  • I think you should try to identify the bottleneck: could be memory, conflicting resources - pretty much anything. Once you know what it is, you could either eliminate it, or work around it. – timbre timbre Jun 06 '17 at 21:50

1 Answers1

1

Anecdotal: When I find my tests run fine on my machine but not so well on a Grid Node, it is typically a timing issue. My workstation is way more powerful than my VMs (Grid Nodes) so simple animations take longer to render. It got to the point where I wrote a .ClickViaJavaScript() to use instead of .Click(). I also threw in a 500ms sleep after the js click.

// Click element via JavaScript
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click()", element);
// Wait a moment
System.Threading.Thread.Sleep(500);

Parallel doesn't really necessitate any code being rewritten so long as you do not change global variables at run-time and each test is atomic.

Timothy Cope
  • 482
  • 2
  • 11
  • My tests involve a lot of clicking and loading different pages so that may be the problem. I put in active waits (so wait until a certain element on my page is present), but these waits time out after about 4 seconds). I've heard that static waits is a bad coding practice? – Jay Jun 07 '17 at 12:46
  • Static waits are not considered best practice, but sometimes you do what you have to. Also, your timeout of 4 seconds is pretty low. Typically I see timeouts around 10, 30, or 60 seconds (be it implicit or explicit). – Timothy Cope Jun 07 '17 at 15:18
  • Yes, I have increased my dynamic timeouts and will give that a shot, if that doesn't work i will look into static waits. Thanks, for your help :) – Jay Jun 07 '17 at 15:20