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.