3

I'm trying to use PhantomJS 2.0/GhostDriver instead the ChromeDriver, since I have read I could speed up my UI tests. This is the test code I'm running, as part of a Junit test:

@Override
public void runTestCase() throws Exception {
    long startTime = System.currentTimeMillis();
    // log in as admin
    Login.loginAs("admin", "password");
    System.out.println(System.currentTimeMillis() - startTime);
}

The loginAs function fills in the text fields for the username and password, then click on the submit button and finally moves in the home section of the new returned page.

Now, I'm running once a time this simple test using both Phantomjs and ChromeDriver as driver for Selenium in Java (v2.45). They are initialized as follow:

  • ChromeDriver

    System.setProperty("webdriver.chrome.logfile", workingDirectory + "\\chromedriver.log");
    service = new ChromeDriverService.Builder().usingDriverExecutable(new File(workingDirectory + "\\chromedriver.exe")).build(); 
    capabilities = DesiredCapabilities.chrome();
    
    options = new ChromeOptions();
    options.addArguments("--allow-file-access-from-files");
    options.addArguments("--verbose");
    capabilities.setVersion("");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(service, capabilities);
    
  • PhantomJS

    System.setProperty("phantomjs.binary.path", workingDirectory + "\\phantomjs.exe");
    cliArgsCap = new ArrayList<String>();
    capabilities = DesiredCapabilities.phantomjs();
    cliArgsCap.add("--web-security=false");
    cliArgsCap.add("--ssl-protocol=any");
    cliArgsCap.add("--ignore-ssl-errors=true");
    cliArgsCap.add("--webdriver-loglevel=INFO");
    cliArgsCap.add("--load-images=false");
    
    capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
    capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
    driver = new PhantomJSDriver(capabilities);
    

I'm running my test on a 64bit Windows 7 machine. So, having a look the time took by the test, I always note that ChromeDriver is faster than PhantomJS. Always. For instance, if the test with ChromeDriver takes about 3-4 seconds, the same with PhantomJS takes about 5-6 seconds.

Has anyone experienced with this issue? Or could anyone give me any reason for that? Am I setting something wrong?

Furthermore, if you need more details, let me know.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Bruno Bruzzano
  • 477
  • 7
  • 21
  • Your setup is correct. I have had the same experience with Ghostdriver. But, I find Ghostdriver useful, in case you just need to scrape the website or run it as a background process. Have you tried the command line / javascript phantomjs? – LittlePanda Apr 03 '15 at 11:03
  • Unfortunately no. How could I integrate my JUnit test with that?! Furthermore, I'm not able to modify the server I want to test.. – Bruno Bruzzano Apr 03 '15 at 11:23
  • For me, the performance seemed ok. Is it too slow for you? I understand it takes 3-4 seconds to show the log first and then the script execution starts. I would not recommend HtmlUnitDriver as I encountered too many exceptions with it. GhostDriver has a few issues too but its better than HtmlUnitDriver. – LittlePanda Apr 03 '15 at 11:29
  • The reason I'd use PhantomJS is that their slogan is: "it's fast, since no drawing needed". But it seems to be not true. Of course, I tried against ChromeDriver only. If it's so, I'll stay with ChromeDriver. – Bruno Bruzzano Apr 03 '15 at 11:49
  • Ghostdriver is good if you want to have a headless script / like a background process or for website scraping. – LittlePanda Apr 03 '15 at 11:52

3 Answers3

4

I have found that this setting uses a lot of memory that seems to keep growing:

cliArgsCap.add("--load-images=false");

But when I use this setting the memory usage is stable:

cliArgsCap.add("--load-images=true");
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Dan F
  • 41
  • 2
1

"PhantomJS is a headless WebKit scriptable with a JavaScript API" as it's explained on the main page of the project. Google split from WebKit to create Blink to use it in Chrome. What are the main differences between them - unfortunately I'm not the expert here.

I run one of my really long scenarios both on Chrome and PhantomJS and to my surprise the difference was pretty significant:

  • PhantomJS - 583.251 s
  • Chrome - 448.384 s

Using PhantomJS doesn't bring performance benefits in my case but running tests headless does. I can use machine without graphical desktop and save computing power for some additional threads.

Michal
  • 3,218
  • 2
  • 25
  • 44
  • 1
    Also, PhantomJS is 60MB, while Google Chrome will while a minimum of 250-300MB. This is an issue if you need to run multiple instances. – Adrian Lopez Apr 23 '16 at 19:47
0

The slowest aspect of a web page is the downloading of html, JavaScript, css, images, etc and making AJAX request.

To anybody who says Headless is faster, how can headless address any of these?

Robbie Wareham
  • 3,380
  • 1
  • 20
  • 38
  • Well, sure, but the time to spend to download the html and all other stuff plus the time to render the page is greater than just download the html and all othr stuff. Am I wrong? – Bruno Bruzzano Apr 07 '15 at 08:21
  • The amount of CPU spent on rendering is tiny. Infact, the fact you can get a screenshot fromPhantomJS suggests that rendering must still be done somewhere – Robbie Wareham Apr 07 '15 at 12:08