IE webdriver没有运行我的代码

时间:2013-11-18 15:36:38

标签: java eclipse selenium webdriver

尝试通过selenium webdriver在eclipse上运行我的测试用例。它仅适用于Firefox驱动程序和Chrome驱动程序,但它不适用于IE驱动程序。它在控制台中说启动了InternetExplorerDriver服务器,但它没有打开窗口。这是我正在尝试运行的代码。

package com.example.tests;

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.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;

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

    @Before
    public void setUp2() throws Exception {
        driver = new InternetExplorerDriver();
        baseUrl = "http://maggies.latestcreativework.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testUntitled() throws Exception {
        driver.get(baseUrl + "/");
        driver.findElement(By.linkText("HOW MAGGIE’S CAN HELP")).click();
        driver.findElement(By.cssSelector("li.sibling")).click();
        driver.findElement(By.linkText("OUR CENTRES")).click();
        driver.findElement(By.linkText("HOW YOU CAN HELP")).click();
        driver.findElement(By.linkText("ABOUT MAGGIE’S")).click();
        driver.findElement(By.cssSelector("img[alt=\"Maggie's Logo\"]")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        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 boolean isAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
          return false;
        }
    }

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

  

要设置保护模式设置,请从“工具”菜单中选择“Internet选项...”,然后单击“安全”选项卡。对于每个区域,标签底部将标有“启用保护模式”

我刚试过但它在控制台中抛出了这个错误:

INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed Nov 18, 2013 4:26:01 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request Nov 18, 2013 4:26:10 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset Nov 18, 2013 4:26:10 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request.
  

此外,还需要将IE的Protected Mode settings设置为正确的值。

我已经完成了这个但是它还没有在IE上运行我的测试用例。它只是打开基本URL但实际上并不运行测试用例。任何帮助将不胜感激。

0 个答案:

没有答案