Reputation: 100250
I run:
mvn clean test
and I get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:testCompile (default-testCompile) on project suman: Compilation failure [ERROR] /home/oleg/WebstormProjects/oresoftware/sumanjs/sce-test/suman/src/test/java/suman/SeleniumTest.java:[21,15] cannot access org.openqa.selenium.HasInputDevices [ERROR] class file for org.openqa.selenium.HasInputDevices not found
I am looking at this:
Looks like my FirefoxDriver or ChromeDriver is causing the issue.
Here is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>suman</groupId>
<artifactId>suman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>suman</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.29.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.0rc3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.0rc3</version>
</dependency>
</dependencies>
</project>
I have two test scripts, one uses ChromeDriver, the other uses FirefoxDriver, they look like so:
package suman;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumTest {
private static FirefoxDriver driver;
private WebElement element;
@BeforeClass
public static void openBrowser(){
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void valid_UserCredential(){
System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName());
driver.get("http://www.store.demoqa.com");
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
driver.findElement(By.id("log")).sendKeys("testuser_3");
driver.findElement(By.id("pwd")).sendKeys("Test@123");
driver.findElement(By.id("login")).click();
try{
element = driver.findElement (By.xpath(".//*[@id='account_logout']/a"));
}catch (Exception e){
}
Assert.assertNotNull(element);
System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName());
}
@Test
public void inValid_UserCredential()
{
System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName());
driver.get("http://www.store.demoqa.com");
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
driver.findElement(By.id("log")).sendKeys("testuser");
driver.findElement(By.id("pwd")).sendKeys("Test@123");
driver.findElement(By.id("login")).click();
try{
element = driver.findElement (By.xpath(".//*[@id='account_logout']/a"));
}catch (Exception e){
}
Assert.assertNotNull(element);
System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName());
}
@AfterClass
public static void closeBrowser(){
driver.quit();
}
}
Does anyone know how I can fix this compilation error?
Upvotes: 2
Views: 13097
Reputation: 11
public class TestUtil extends BaseTest {
public static String destDir;
public static DateFormat dateFormat;
public static String destFile;
public static String mailscreenshotpath;
public static String xPath, Action;
Login lg = new Login();
public static void captureScreenshot() throws IOException {
destDir = System.getProperty("user.dir") + File.separator + "test-output" + File.separator + "html";
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
new File(destDir).mkdir();
destFile = dateFormat.format(new Date()) + ".png";
mailscreenshotpath = destDir + "/" + destFile;
// System.out.println(" mailscreenshotpath : " + mailscreenshotpath);
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
}
/**
*
* Static method to get the screenshot
*
* @param driver
* @param imgPath
*
* @return dest : String value of Path
*
* @throws IOException
*/
public static String capture(String imgPath) throws IOException {
String newTime = time();
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest = imgPath + newTime + ".png";
File destination = new File(dest);
FileUtils.copyFile(source, destination);
String relativePath = "." + File.separator + "Screenshots" + File.separator + newTime + ".png";
return relativePath;
}
/**
*
* Method to return date in format dd_MMM_yyyy_hh_mm_ss_aa
*
* @return String
*/
public static String time() {
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy_hh_mm_ss_aa");
String time = dateFormat.format(now);
return time;
}
public static void scrollDown() {
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL, Keys.END);
}
public static void scrollUp() {
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL, Keys.HOME);
}
Upvotes: 1
Reputation: 7968
You are getting this error because dependencies in your pom.xml are not compatible.
Dependency list should be like this.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
Upvotes: 2