I have the following 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;
}
}
And the following Test5.java that extends TestBase:
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");
}
}
My Ant config (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>
When I run "ant run-tests", I get the following error:
[javac] C:\LoadTest\src\com\example\tests\Test5.java:21: cannot find symbol
[javac] symbol : variable By
So, I don't understand the reaason for this error. The command above ...
driver.get("https://10.20.44.16/main/");
... works, so I guess all is fine with CLASSPATH.
Any ideas?
Thanks, Racoon
You need import org.openqa.selenium.By;
in Test5.Java.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.