I'm new to Selenium & new to Java as well. So maybe I'm missing something obvious, but I’m spinning on this for a while now, can't move forward & totally desperate. Please help!
Here is my set-up:
My custom Driver class implements WebDriver & sets property:
public class Driver implements WebDriver {
private WebDriver driver;
private String browserName;
public Driver(String browserName) throws Exception {
this.browserName = browserName;
if(browserName.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver");
this.driver = new ChromeDriver();
}
else if(browserName.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver");
this.driver = new FirefoxDriver();
}
else {
throw new Exception("Browser is not correct");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
<...>
}
BaseTest class gets property & creates new instance of the Driver inside @BeforeClass method (browser name passed with a maven command when running the test):
String browserName = getParamater("browser");
driver = new Driver(browserName);
In the Test class inside the @Test I create new Actions & pass there the driver from BaseTest:
Actions builder = new Actions(driver);
Action mouseOverHome = builder
.moveToElement(pb.testGoodle)
.build();
mouseOverHome.perform();
And this code doesn’t work -> no Actions performed (no mouse over or anything), no errors too.
However if I create & define new WebDriver inside the @Test itself:
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver");
WebDriver driver = new FirefoxDriver();
Actions perfectly working. Any ideas or hints very appreciated!