2

I wrote a Selenium test with java that I launched with the FirefoxDriver and it is executing fine in Firefox browser.

Then I am replacing FirefoxDriver with HtmlunitDriver like this:

driver = new FirefoxDriver();

with

driver = new HtmlUnitDriver(true);

But then I got this error :

It's missing ';' Before an instruction (http://local.project/bundles/app/js/socket.js#1)

This is the socket.js file :

class SocketHandler {
    constructor(url) {
        this.url = url;
        this.session = null;
    }

    ....
}

I suspect that it doesn't recognize the class declaration. Any idea how to correct that please?

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
Mit94
  • 718
  • 8
  • 28

1 Answers1

1

You don't even need to use PhantomJs. As PhantomJs is not so much maintain these days. You can use chromedriver in headless mode.

you just need to add options as headless as below :-

chromeOptions.addArguments("--headless");

Please find complete code below:

System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://google.com");

While if still you want to use phantomjs. then first download phantomjs binary from below location :-

http://phantomjs.org/download.html

Now use below code :-

System.setProperty("phantomjs.binary.path","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\phantomjs\\phantomjs.exe");
DesiredCapabilities capabilities = null;
ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,new String[] { "--logLevel=2" });
driver = new PhantomJSDriver(capabilities);
driver.get("https://www.google.co.in/");

Hope it will help you :)

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Thank you it was really helpful. I'am doing some test loading with Selenium and even in headless mode I can't put more than 50 browsers before my computer starts "lagging". Do you know if there is some more chromeOptions than can use to "lighten" the browser ? Or if it's worth moving to PhantomJS? I need to reach 80 browsers simultaneously. – Mit94 Aug 09 '17 at 16:02
  • Yes you can try with phantomjs .. you can also go for selenium grid concept where your host will send instructions to slaves machine.. so using grid you need 2 machine which will run 40 instance each – Shubham Jain Aug 09 '17 at 16:13