无法获取selenium webdriver Java脚本来运行

时间:2014-12-09 17:39:00

标签: java selenium webdriver

您好我是webdriver的新手我试图让脚本运行。当我运行脚本时,它会打开浏览器并输入详细信息,但@Test部分却没有。我尝试过使用css定位器x路径等,但我没有尝试过任何工作。有没有人可以提供任何想法或建议?

package firsttestngpackage;    

    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    public class FirstTestNGFile {
        public String baseUrl = "http://zzzz";
        public WebDriver driver = new FirefoxDriver();

        @BeforeTest
        public void login() {
            driver.get(baseUrl);
            WebElement id = driver.findElement(By.id("z_username"));
            id.sendKeys("todd");
            WebElement pass = driver.findElement(By.id("z_password"));
            pass.sendKeys("todd");
            WebElement button = driver.findElement(By.name("login"));
            button.submit();
        }

        @Test
        public void createSub() {
            driver.findElement(By.linkText("Customers")).click();
        }

        @AfterTest
        public void terminateBrowser() {
            driver.quit();

        }
    }

1 个答案:

答案 0 :(得分:0)

您错过了关闭},而且customers元素的选择器也可能是失败的原因

package firsttestngpackage;    

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class FirstTestNGFile {
    public String baseUrl = "http://zzzz";
    public WebDriver driver = new FirefoxDriver();

    @BeforeTest
    public void login() {
        driver.get(baseUrl);
        WebElement id = driver.findElement(By.id("z_username"));
        id.sendKeys("todd");
        WebElement pass = driver.findElement(By.id("z_password"));
        pass.sendKeys("todd");
        WebElement button = driver.findElement(By.name("login"));
        button.submit();
    }

    @Test
    public void createSub() {
        driver.findElement(By.xpath("//*[.='Customers']")).click();
    }

    @AfterTest
    public void terminateBrowser() {
        driver.quit();

    }
}