0

I have been using WebDriverManager to manage drivers for my class file which in turn is used extended to other class files for testing using Selenium.

I am using maven to do the builds, below is the content of my pom.xml file :

<dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>3.12.0</version>
  </dependency>
  <dependency>
   <groupId>org.testng</groupId>
   <artifactId>testng</artifactId>
   <version>6.9.8</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
   <version>3.1.1</version>
   <scope>test</scope>
  </dependency>
</dependencies>

And below is the class file that I am using to invoke the drivers :

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.testng.annotations.BeforeTest;
    import io.github.bonigarcia.wdm.WebDriverManager;
    import io.github.bonigarcia.wdm.PhantomJsDriverManager;

    public abstract class GetDriver {

    // declare driver
    public WebDriver driver;

    // Assign the driver
    @BeforeTest
    public void WebdriverSetUp() {

        WebDriverManager.phantomjs().setup();
        driver = new PhantomJsDriver();
    }
   }

Now the problem is that whenever I try to add the phantomjs driver using the below two lines :

WebDriverManager.phantomjs().setup();
driver = new PhantomJSDriver();

It gives me the error, "PhantomJSDriver cannot be resolved to a type". Eclipse suggests me to do any of the below fix :

Create class 'PhantomJSDriver' Change to 'WebDriver' (org.openqa.selenium) "Change to 'PhantomJsDriverManager' (io.github.bonigarcia.wdm)"

When I try selecting the third fix which is to change to PhantomJsDriverManager, another error pops up

Type mismatch: cannot convert from PhantomJsDriverManager to WebDriver

For the above error again, Eclipse suggests two fixes : Add cast to 'WebDriver' Change type of 'driver' to 'PhantomJsDriverManager'

When I select the second option from above the code changes to

public abstract class GetDriver {

// declare driver
public PhantomJsDriverManager driver;

// Assign the driver
@BeforeTest
public void WebdriverSetUp() {

    WebDriverManager.phantomjs().setup();
    driver = new PhantomJsDriverManager();
    }
}

After the above change I now get the error, "The constructor PhantomJsDriverManager() is not visible".

This issue is happening just for the PhantomJs driver. I tried with chrome driver and it worked like a charm. Please help me as to how can I use webdrivermanager so that I can PhantomJS driver to be used for headless execution of my Selenium code.

Swastik
  • 1
  • 1
  • PhantomJS is deprecated – Corey Goldberg Dec 30 '18 at 06:53
  • Thanks - Yes I was not aware of it being deprecated. I am a complete newbie to the whole testing thing. Hence I was struggling with PhantomJS but then it dawned on me to use Chrome in headless mode :) – Swastik Dec 31 '18 at 08:22

2 Answers2

0

I had to move away from using the WebDriverManager for PhantomJS and instead used chrome driver with headless chrome. That fixed the issues I was facing, and finally I was able to do my testing via Jenkins without any issues.

Swastik
  • 1
  • 1
0

I had same issue so i decide to go with ChromeOptions class instead of PhantomJS driver by setting the value of addArguments as --headless like below:

WebDriverManager.chromedriver().setup();
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--headless");
            options.addArguments("--disable-gpu");
            driver = new ChromeDriver(options);
Cosmin
  • 2,354
  • 2
  • 22
  • 39