我是詹金斯的新手。我已经安装了詹金斯和插件。端口8080我正在使用它。在Jenkins中运行测试用例时,出现以下错误“ java.lang.AssertionError:不支持的类型参数”。
java.lang.AssertionError: Unsupported type parameter : class com.volvo.tests.properties.ChosenWebDriver
[TestNG] at org.testng.internal.Parameters.convertType(Parameters.java:246)
[TestNG] at org.testng.internal.Parameters.createParameters(Parameters.java:165)
[TestNG] at org.testng.internal.Parameters.createParameters(Parameters.java:355)
[TestNG] at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
[TestNG] at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
[TestNG] at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
[TestNG] at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
[TestNG] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
[TestNG] at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
[TestNG] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
[TestNG] at org.testng.TestRunner.privateRun(TestRunner.java:767)
[TestNG] at org.testng.TestRunner.run(TestRunner.java:617)
-------------------------------------------
“ ChosenWebDriver”
package com.volvo.tests.properties;
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public enum ChosenWebDriver {
IE("IE"), CHROME("CHROME"), Firefox("FF");
private final String chosenDriver;
private ChosenWebDriver(String driver) {
chosenDriver = driver;
}
public WebDriver getDriver() {
WebDriver ret = null;
switch (chosenDriver) {
case "IE":
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("nativeEvents", false);
capabilities.setCapability("requireWindowFocus", true);
// capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,
// "http://www.bing.com/");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE");
// capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,
// true);
ret = new InternetExplorerDriver(capabilities);
break;
case "CHROME":
try {
if (Platform.getCurrent() != null && Platform.getCurrent().is(Platform.LINUX)) {
ChromeDriverService chromeDriverService = new ChromeDriverService.Builder().usingDriverExecutable(new File(
"/usr/bin/chromedriver")).usingAnyFreePort().withLogFile(new File("/home/jenkins/.config/google-chrome/chromedriver.log")).build();
chromeDriverService.start();
ret = new ChromeDriver(chromeDriverService, getChromeCapabilities());
} else {
/*
* ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
* .usingDriverExecutable(new File("selenium_drivers/chromedriver.exe")).usingAnyFreePort()
* .withLogFile(new File("selenium_drivers/chromedriver.log")).build();
* chromeDriverService.start();
*/
ret = new ChromeDriver();
}
} catch (IOException e) {
e.printStackTrace();
}
break;
case "FF":
ret = new FirefoxDriver();
break;
}
return ret;
}
// Setting Chrome desired capabilities:
private DesiredCapabilities getChromeCapabilities() {
// System.setProperty("webdriver.chrome.driver",
// "/usr/bin/chromedriver");
// System.setProperty("webdriver.chrome.logfile",
// "/home/jenkins/.config/google-chrome/chromedriver.log");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// capabilities.setCapability(CapabilityType.PLATFORM, "Linux
// 3.10.0-327.el7.x86_64 x86_64");
capabilities.setCapability(CapabilityType.PLATFORM, Platform.getCurrent());
capabilities.setCapability(ChromeOptions.CAPABILITY, getChromeOptions());
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
capabilities.setBrowserName("chrome");
return capabilities;
}
// Setting Chrome options:
private ChromeOptions getChromeOptions() {
ChromeOptions options = new ChromeOptions();
// options.addArguments("user-data-dir=".concat("/home/jenkins/.config/google-chrome"));
options.addArguments("profile-directory=".concat("Default"));
options.addArguments("disable-extensions");
options.addArguments("disable-plugins");
options.addArguments("headless");
options.addArguments("window-size=1920x1080");
options.addArguments("no-sandbox");
options.addArguments("disable-gpu");
options.addArguments("enable-logging --v=4");
// options.setBinary(new File("/usr/bin/google-chrome-beta"));
return options;
}
}