我无法运行TestNG测试,得到"在类路径中找不到类:TestNG1"在控制台中出错

时间:2016-02-22 06:28:54

标签: selenium

我无法运行TestNG测试,获得" Cannot find class in classpath: TestNG1"控制台出错。

这是我第一次使用TestNG测试

我无法运行TestNG测试,获得" Cannot find class in classpath: TestNG1"控制台出错。

我无法运行TestNG测试,获得" Cannot find class in classpath: TestNG1"控制台出错。

package automatiomFramework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.TestNGException;

public class TestNG1 {

    public WebDriver driver;

  @Test
  public void f() {

        driver.findElement(By.xpath(".//*[@id='topstrip123']/ul/li[5]/a")).click();

        Select oSelect = new Select(driver.findElement(By.id("ddlTitle")));
        oSelect.selectByIndex(2);
        Select oSelect1 = new Select(driver.findElement(By.id("ddlTitle")));
        oSelect1.selectByVisibleText("Mr.");

        driver.findElement(By.id("txtEmailsignup")).sendKeys("gjadjdsga@gmail.com");
        driver.findElement(By.id("txtPassword1")).sendKeys("password123");
        driver.findElement(By.id("txtCnfPassword")).sendKeys("password123");

        driver.findElement(By.id("Checkbox1")).click();
        driver.findElement(By.id("btnSignup")).click();
        driver.switchTo().alert().accept();
        driver.findElement(By.id("Checkbox1")).click();
        driver.findElement(By.id("btnSignup")).click();

        driver.switchTo().alert().accept();

        driver.findElement(By.id("chksubscribe")).click();
        WebElement radioBtn = driver.findElement(By.id("rbMailpre_1"));

        radioBtn.click();

        driver.findElement(By.id("btnLogin")).click();
  }

  @BeforeMethod
  public void beforeMethod() {
      driver = new FirefoxDriver();
        String url = "http://www.yepme.com";
        driver.get(url);
  }

  @AfterMethod
  public void afterMethod() {
      driver.close();
  }

}

1 个答案:

答案 0 :(得分:0)

创建一个名为testNG.xml且名称低于内容的xml文件,并将其保存在eclipse的项目根目录中,然后右键单击testNG.xml并选择Run As TestNG Suite。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="XYZ" parallel="false">
     <test name="TESTING">
        <classes>
           <class name="automatiomFramework.TestNG1" />
        </classes>
    </test>
</suite>