我有以下TestBase.java:
package com.example.tests;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
public class TestBase {
protected WebDriver driver;
@BeforeMethod
@Parameters("hubAddress")
public void startDriver(String hubAddress) throws MalformedURLException {
driver = new RemoteWebDriver(new URL(hubAddress), DesiredCapabilities.firefox());
}
@AfterMethod
public void stopDriver() {
driver.quit();
driver = null;
}
}
以及以下扩展 TestBase 的 Test5.java:
package com.example.tests;
import org.testng.annotations.Test;
import java.lang.Thread;
@Test
public class Test5 extends TestBase {
public void test5() {
driver.get("https://10.20.44.16/main/");
try {
Thread.sleep(20000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
driver.findElement(By.id("loginUserName")).sendKeys("User5");
}
}
我的蚂蚁配置(build.xml):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="LoadTest">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="Selenium.classpath">
<pathelement location="C:\Lib\selenium-server-standalone-2.32.0.jar"/>
</path>
<path id="LoadTest.classpath">
<pathelement location="bin"/>
<path refid="Selenium.classpath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="init" name="build">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="LoadTest.classpath"/>
</javac>
</target>
<taskdef resource="testngtasks" classpathref="Selenium.classpath"/>
<target name="run-tests" depends="build">
<testng classpathref="LoadTest.classpath">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>
当我运行“ant run-tests”时,出现以下错误:
[javac] C:\LoadTest\src\com\example\tests\Test5.java:21: cannot find symbol
[javac] symbol : variable By
所以,我不明白这个错误的原因。上面的命令...
driver.get("https://10.20.44.16/main/");
...有效,所以我想CLASSPATH一切都很好。
有任何想法吗?
谢谢,浣熊