2013-09-06 2 views
0

I가 다음 TestBase.java : TestBase를 확장개미 + javac의 + WebDriver : "기호 찾을 수 없습니다 작성자 : 변수를"

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; 
    } 

} 

그리고 다음 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> 

나는 "개미 실행 테스트"를 실행, 나는 다음과 같은 오류가 발생합니다 :

,
[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에서 문제가되지 않습니다.

아이디어가 있으십니까?

덕분에, 너구리

답변

3

당신은 Test5.Java에서 import org.openqa.selenium.By;해야합니다.

+1

여전히 Test5.java에서 가져와야합니다. –

+0

감사합니다. 작동합니다! 아직도, 나는 지구상에서 내가 셀레늄을 위해 정확히 그것을해야만하는지 이해하지 못한다. 셀레늄을위한 것이 아니고 .WebDriver. – Racoon

+0

Test5에서'WebDriver'라는 이름을 사용하지 않고'driver' 만 상속받습니다. 간접적으로 유형을 사용하는 것이 좋습니다. 가져 오기는 모두 이름에 관한 것입니다. –

관련 문제