问题: 我试图在Eclipse中调试一个简单的测试(使用 selenium web驱动程序3.4.0,testng,FF 53,chrome latest )但是得到了这个例外: "源附件不包含文件remotewebdriver.class的源#34;一旦到达这一行" WebDriver driver = new FirefoxDriver();"
设定:
我从这里下载了最新的Java selenium web驱动程序:http://selenium-release.storage.googleapis.com/3.4/selenium-java-3.4.0.zip 2.将所有jar文件提取并复制到一个文件夹" d:\ jars \" 3.在我的项目中添加了外部jar文件:Project>构建路径>配置构建路径>库>添加外部罐子>在这里添加了所有的罐子。
执行: 执行我的测试作为" testNG套件"和驱动程序初始化错误。
初始化驱动程序的代码:
package com.trantor.base;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
public class TestBaseSetup {
private WebDriver driver;
static String driverPath = "D:\\jars\\chromedriver_win32\\";
public WebDriver getDriver() {
return driver;
}
private void setDriver(String browserType, String appURL) {
switch (browserType) {
case "chrome":
driver = initChromeDriver(appURL);
break;
case "firefox":
driver = initFirefoxDriver(appURL);
break;
default:
System.out.println("browser : " + browserType
+ " is invalid, Launching Firefox as browser of choice..");
driver = initFirefoxDriver(appURL);
}
}
private static WebDriver initChromeDriver(String appURL) {
System.out.println("Launching google chrome with new profile..");
System.setProperty("webdriver.chrome.driver", driverPath
+ "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to(appURL);
return driver;
}
private static WebDriver initFirefoxDriver(String appURL) {
System.out.println("Launching Firefox browser..");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to(appURL);
return driver;
}
@Parameters({ "browserType", "appURL" })
@BeforeClass
public void initializeTestBaseSetup(String browserType, String appURL) {
try {
setDriver(browserType, appURL);
} catch (Exception e) {
System.out.println("Error....." + e.getStackTrace());
}
}
@AfterClass
public void tearDown() {
driver.quit();
}
}
测试类:
package com.trantor.authorportal.tests;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.trantor.authorportal.pageobjects.LoginPage;
import com.trantor.base.TestBaseSetup;
public class AuthorTestSuite1 extends TestBaseSetup{
private WebDriver driver;
@BeforeClass
public void setUp() {
driver=getDriver();
}
@Test
public void verifyHomePage() {
System.out.println("Home page test...");
LoginPage loginPage = new LoginPage(driver);
Assert.assertTrue(loginPage.verifyPageTitle(), "Home page title doesn't match");
}
}