如何更改我的Firefox测试以在IE上运行?

时间:2016-11-07 09:56:43

标签: java selenium selenium-webdriver webdriver

我在Firefox浏览器上编写了Java Selenium测试。现在我想将浏览器更改为IE。 代码:

@BeforeTest
public void setup()
{
    File file = new File("C:\\Selenium\\IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    WebDriver driver = new InternetExplorerDriver();            
    driver.get("URL");
}

@Test(priority=0)
public void Log_In() throws InterruptedException
{
    objLogin = new LoginPage(driver);                               
    objLogin.loginTo("username", "password");                                                                                        
}

在Firefox中,测试会转到主页并定期运行,但是当我更改为IE浏览器时,只需打开浏览器,无需输入密码和用户名即可访问URL。为了使这项工作,我应该改变什么?

由于

public class Login{
    WebDriver driver;
    @FindBy(id="username")
    WebElement user;
    @FindBy(id="password")
    WebElement password;

    public LoginPage(WebDriver driver)
    {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void setUserName(String strUserName){
        user.sendKeys(strUserName);;
    }
    public void setPassword(String strPassword){
        password.sendKeys(strPassword);
    }
    public void clickLogin(){
        login.click();
    }
    public void loginTo(String strUserName,String strPasword){
        this.setUserName(strUserName);
        this.setPassword(strPasword);
        this.clickLogin();        
    }
}

Exp:

FAILED: Log_In_eAnal
java.lang.NullPointerException
    at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
    at com.sun.proxy.$Proxy6.sendKeys(Unknown Source)
    at POM.LoginPage_Pom_eAnal.setUserName(LoginPage_Pom_eAnal.java:43)
    at POM.LoginPage_Pom_eAnal.loginTo(LoginPage_Pom_eAnal.java:82)
    at POM.TestCase1_GuiDateChecker_POM_eAnal.Log_In_eAnal(TestCase1_GuiDateChecker_POM_eAnal.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

SKIPPED: TopLevelDomains_Check
java.lang.Throwable: Method TestCase1_GuiDateChecker_POM_eAnal.TopLevelDomains_Check()[pri:1, instance:POM.TestCase1_GuiDateChecker_POM_eAnal@6321e813] depends on not successfully finished methods
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1033)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

0 个答案:

没有答案