0

我是 selenium 新手,我使用 selenium firefox IDE 记录了一个场景。我已将测试用例保存为 java 格式,并尝试使用 selenium-ie 驱动程序和 IEDriverServer.exe 运行测试用例。

这是我的测试用例 java 文件。

package com.xyz.test;

import java.io.File;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;

public class TestPCQDE {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
      File file = new File(TestPCQDE.class.getResource("IEDriverServer.exe").toURI());
      System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
      driver = new InternetExplorerDriver();//IN THIS LINE I GET EXCEPTION POSTED BELOW,IE BROWSER DOES NOT OPEN.PS:driver VARIABLE DOES NOT INITIALIZE PROPERLY
    baseUrl = "http://122.12.122.12:9090/MyWebApp/security/mort_main.htm";
    driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
  }

  @Test
  public void testTestPCQDE() throws Exception {
    driver.get(baseUrl + "/MyWebApp/security/login.htm?logOut=yes");
    driver.findElement(By.name("ssoId")).clear();
    driver.findElement(By.name("ssoId")).sendKeys("abcd");
    driver.findElement(By.name("button")).click();
    driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//tr[23]/td[2]/a/u")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | rightFrame | ]]
    driver.findElement(By.id("dtree_0i0font")).click();
    driver.findElement(By.id("dtree_0i1font")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | leftFrame | 30000]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=up | ]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | leftFrame | ]]
    new Select(driver.findElement(By.name("loanType1"))).selectByVisibleText("Personal Car");
    new Select(driver.findElement(By.cssSelector("select[name=\"strCustomerType\"]"))).selectByVisibleText("Individual");
    new Select(driver.findElement(By.id("strTitle"))).selectByVisibleText("Miss.");
    driver.findElement(By.name("strApplicantFirstName")).clear();
    driver.findElement(By.name("strApplicantFirstName")).sendKeys("testseleniumdemo");
    new Select(driver.findElement(By.name("customerCategory"))).selectByVisibleText("OTHERS");
    driver.findElement(By.name("strApplicantLastName")).clear();
    driver.findElement(By.name("strApplicantLastName")).sendKeys("testing");
    new Select(driver.findElement(By.name("maritalStatus"))).selectByVisibleText("Single");
    driver.findElement(By.xpath("//img[@onclick='javascript:cal2.popup()']")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | Calendar | 30000]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=Calendar | ]]
    new Select(driver.findElement(By.name("yearSelect"))).selectByVisibleText("1963");
    driver.findElement(By.xpath("//tr[6]/td[3]/a/font")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=leftFrame | ]]
    driver.findElement(By.name("mothersMaidenName")).clear();
    driver.findElement(By.name("mothersMaidenName")).sendKeys("shraddha");
    new Select(driver.findElement(By.name("relationship"))).selectByVisibleText("FATHER");
    new Select(driver.findElement(By.name("strCategory"))).selectByVisibleText("GENERAL");
    driver.findElement(By.name("relationFirstName")).clear();
    driver.findElement(By.name("relationFirstName")).sendKeys("sdf");
    new Select(driver.findElement(By.name("employerType"))).selectByVisibleText("SALARIED");
    new Select(driver.findElement(By.name("multiVehicles"))).selectByVisibleText("No");
    new Select(driver.findElement(By.name("strChannel"))).selectByVisibleText("Direct");
    new Select(driver.findElement(By.name("strDistributionChannel"))).selectByVisibleText("NEW");
    driver.findElement(By.name("strTerm")).clear();
    driver.findElement(By.name("strTerm")).sendKeys("22");
    driver.findElement(By.name("strLoanAmount")).clear();
    driver.findElement(By.name("strLoanAmount")).sendKeys("500000");
    driver.findElement(By.name("strRecomendedAmount")).clear();
    driver.findElement(By.name("strRecomendedAmount")).sendKeys("5000000");
    driver.findElement(By.xpath("//img[@onclick='javascript:searchProduct();']")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | newwin | 30000]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=newwin | ]]
    driver.findElement(By.name("product")).click();
    driver.findElement(By.name("New")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=leftFrame | ]]
    new Select(driver.findElement(By.name("strSoftApproval"))).selectByVisibleText("abc xyz");
    driver.findElement(By.id("fanNo")).clear();
    driver.findElement(By.id("fanNo")).sendKeys("0");
    driver.findElement(By.id("productLine")).clear();
    driver.findElement(By.id("productLine")).sendKeys("test 05 01 Vxi");
    driver.findElement(By.name("costOfVehicle")).clear();
    driver.findElement(By.name("costOfVehicle")).sendKeys("40000");
    driver.findElement(By.name("bttnSearch")).click();
    assertTrue(closeAlertAndGetItsText().matches("^Do you want to save the data[\\s\\S]$"));
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();//SINCE VARIABLE driver DOES NOT INITIALIZE PROPERLY,I GET NULL POINTER EXCEPTION
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alert.getText();
    } finally {
      acceptNextAlert = true;
    }
  }
}

PS:我已将 IEDriverServer.exe 文件复制到同一文件夹/包(com.xyz.test)中。

这是堆栈跟踪

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.29.1', revision: 'dfb1306b85be4934d23c123122e06e602a15e446', time: '2013-01-22 12:58:05'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_31'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:201)
    at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:105)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:51)
    at com.tcs.test.TestPCQDE.setUp(TestPCQDE.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.29.1', revision: 'dfb1306b85be4934d23c123122e06e602a15e446', time: '2013-01-22 12:58:05'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_31'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:506)
    ... 29 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:19455/status] to be available after 20007 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
    ... 31 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
    ... 32 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
    at java.util.concurrent.FutureTask.get(FutureTask.java:91)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
    ... 33 more

java.lang.NullPointerException
    at com.tcs.test.TestPCQDE.tearDown(TestPCQDE.java:103)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

这是我的 POM.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pcqdetestcases</groupId>
  <artifactId>pcqdetestcases</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <dependencies>
    <dependency>
        <groupId>org.openqa.selenium.core</groupId>
        <artifactId>selenium-core</artifactId>
        <version>1.0-20080914.225453</version>
    </dependency>
    <dependency>
        <groupId>org.openqa.selenium</groupId>
        <artifactId>selenium-rc</artifactId>
        <version>1.0-20081010.060147</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.29.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>2.29.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>2.30.0</version>
    </dependency>
  </dependencies>
</project>

请注意:我的系统没有管理员权限。我的机器上安装了 IE 8。

如果需要任何其他信息,请告诉我。谢谢

4

1 回答 1

0

最可能的原因是您的 IEDriverServer.exe 无法启动。尝试明确地将其称为File file = new File("path to file");

从您的堆栈跟踪: 原因:org.openqa.selenium.WebDriverException:等待驱动程序服务器启动超时。

于 2013-03-14T16:10:21.663 回答