![](/img/trans.png)
[英]error: incompatible types: java.lang.String cannot be converted to String
[英]Error:(34, 12) java: incompatible types: java.lang.String cannot be converted to org.openqa.selenium.WebDriver
我有這個錯誤的麻煩,我從代碼中看不到任何明智的錯誤
package driver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class DriverFactory {
// Get a new WebDriver Instance.
// There are various implementations for this depending on browser. The required browser can be set as an environment variable.
// Refer http://getgauge.io/documentation/user/current/managing_environments/README.html
public static WebDriver getDriver() {
String browser = System.getenv("BROWSER");
if (browser == null) {
WebDriverManager.chromedriver().setup();
return new ChromeDriver();
}
switch (browser)
{
case "IE":
WebDriverManager.iedriver().setup();
return new InternetExplorerDriver();
case "FIREFOX":
WebDriverManager.firefoxdriver().setup();
return new FirefoxDriver();
default:
WebDriverManager.chromedriver().setup();
return new ChromeDriver();
}
}
}
錯誤:(34、12)java:不兼容的類型:java.lang.String無法轉換為org.openqa.selenium.WebDriver
它通過審查pom.xml依賴關系解決了就像這樣,
http://maven.apache.org/maven-v4_0_0.xsd“> 4.0.0
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-archetype-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.thoughtworks.gauge</groupId>
<artifactId>gauge-java</artifactId>
<version>0.6.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<specsDir>specs</specsDir>
</configuration>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.