Tyler Tyler - 3 months ago 9
Java Question

Unsure why Selenium methods are running fast in Main but slow in JUnit

I am working on a suite of automated Selenium tests. I have a bit a code that handles checking search filter's for our website (checking their validity, what is selected, etc.). This bit of code is running a lot slower than I had expected. I am developing the suite using the Page Object pattern, and during development, I would debug various bits out of a main method, then implement the test methods using JUnit once the Page Objects were functioning properly.

I noticed a significant time discrepancy between the execution times of constructing the object in Main vs. in JUnit. In Main, the object construction takes about 15 seconds. When I run it in through JUnit, however, object construction takes about 16 minutes. This is obviously a large enough difference that I am concerned about it and want to know how I can get the JUnit execution time closer to what I was observing when it was run through main. I'd appreciate any ideas, or a better understanding of why the delay was being caused. Thanks!

Configuration:
Java 8,
Selenium 2.53.0,
JUnit 4.12,
Fiefox 48

Here are the lines of code in question:

// Run in main

// getFilters() returns new Filters(webDriver);
Filters filters = resultsPage.getFilters();

// Run with JUnit (through IntelliJ)
filters = resultsPage.getFilters();


Essentially the only differences are 1) the filters in the test class are static and set in my
@BeforeClass
method and 2) they are run through JUnit through IntelliJ rather than just being executed by IntelliJ, but I'm quite certain that it is the exact same bit of code that is running on both places (The Filters constructor) where the time difference is occurring.

Answer

Well, it turns out it was a goof on my part. I had mis-configured my WebDriver in my test class which was throwing a wait into more than I expected it to.