未能将ChromeDriver设置为运行TestNG教程

时间:2017-11-10 20:37:21

标签: selenium-webdriver automation testng selenium-chromedriver qa

我是TestNG的新手,我正在尝试按照教程,但我不想使用firefox运行测试,我想使用ChromeDriver但是当我尝试将其设置为网络驱动程序。

以下是代码:

package TestNG;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class DemoTestNG {

这是我编辑试用和使用chromedriver的部分

public 
        System.setProperty("webdriver.chrome.driver", "/applications/chromedriver");
        WebDriver driver = new ChromeDriver();
        String appURL = "https://accounts.google.com";

代码的其余部分

@Test
      public void gmailLogin() {
        //launch the chrome browser and open the application url
        driver.get("https://accounts.google.com");

    //maximize the browser window
    driver.manage().window().maximize();

    //declare and initialize the variable to store the expected title of the webpage
    String expectedTitle ="sign in - Google Accounts";

    //Fetch the title of the web page and save it into a string variable
    String actualTitle = driver.getTitle();
    Assert.assertEquals(expectedTitle,actualTitle);

    //enter a valid username in the email textbox
    WebElement username = driver.findElement(By.id("Email"));
    username.clear();
    username.sendKeys("TestSelenium");

    //enter a valid password in the password textbox
    WebElement password = driver.findElement(By.id("Passwd"));
    password.clear();
    password.sendKeys("password123");

    //click on the sign in button
    WebElement SignInButton = driver.findElement(By.id("signIn"));
    SignInButton.click();

    //close the web browser
    driver.close();

} 
}

这是我得到的错误

[RemoteTestNG] detected TestNG version 6.12.0
org.testng.TestNGException: 
Cannot instantiate class TestNG.DemoTestNG
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:31)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:420)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:333)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
    at org.testng.TestClass.getInstances(TestClass.java:99)
    at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:85)
    at org.testng.TestClass.init(TestClass.java:77)
    at org.testng.TestClass.<init>(TestClass.java:42)
    at org.testng.TestRunner.initMethods(TestRunner.java:455)
    at org.testng.TestRunner.init(TestRunner.java:282)
    at org.testng.TestRunner.init(TestRunner.java:252)
    at org.testng.TestRunner.<init>(TestRunner.java:178)
    at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
    at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:663)
    at org.testng.SuiteRunner.init(SuiteRunner.java:230)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:173)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1400)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1380)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1234)
    at org.testng.TestNG.runSuites(TestNG.java:1161)
    at org.testng.TestNG.run(TestNG.java:1129)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:23)
    ... 25 more
Caused by: java.lang.Error: Unresolved compilation problems: 
    The import org.openqa cannot be resolved
    The import org.openqa cannot be resolved
    The import org.openqa cannot be resolved
    The import org.openqa cannot be resolved
    Syntax error on token ".", @ expected after this token
    Syntax error on token ",", < expected
    Syntax error, insert "SimpleName" to complete QualifiedName
    Syntax error, insert "Identifier (" to complete MethodHeaderName
    Syntax error, insert ")" to complete MethodDeclaration
    WebDriver cannot be resolved to a type
    ChromeDriver cannot be resolved to a type
    WebDriver cannot be resolved to a type
    WebDriver cannot be resolved to a type
    WebDriver cannot be resolved to a type
    WebElement cannot be resolved to a type
    WebDriver cannot be resolved to a type
    By cannot be resolved
    WebElement cannot be resolved to a type
    WebDriver cannot be resolved to a type
    By cannot be resolved
    WebElement cannot be resolved to a type
    WebDriver cannot be resolved to a type
    By cannot be resolved
    WebDriver cannot be resolved to a type

    at TestNG.DemoTestNG.<init>(DemoTestNG.java:3)
    ... 30 more

任何帮助将不胜感激!谢谢!

0 个答案:

没有答案