Javascript打破Selenium测试

时间:2015-03-25 08:52:56

标签: java javascript selenium

我正在为一家我实习的公司写一个基本的Selenium测试,这个错误一直困扰着我一段时间。如果我在测试中关闭Javascript,它会很好,但是一旦我打开Javascript进行测试,它就永远不会完成。

测试如下:

public void Login()
{
    driver.setJavascriptEnabled(true);
    driver.get("https://127.0.0.1:4433");

    WebElement usernamefield = driver.findElement(By.id("username"));
    WebElement passwordfield = driver.findElement(By.id("password"));
    usernamefield.sendKeys(email);
    passwordfield.sendKeys(password);
    WebElement loginButton = driver.findElement(By.className("jsLoginSubmit"));
    loginButton.click();
    driver.navigate().to("https://127.0.0.1:4433/?op=caselist");
    assertTrue(driver.getTitle().contains("Overblik")
            && driver.getTitle().contains(userid.toString()));
    System.out.println(email);
    driver.close();
}

如果禁用Javascript,此测试工作正常。我使用它来在我的setUp()方法中实例化驱动程序:

driver = new HtmlUnitDriver();

但是这里是启用Javascript运行测试的输出:

09:40:35,162 ERROR StrictErrorReporter:79 - runtimeError: message=[The data necessary to complete this operation is not yet available.] sourceName=[https://127.0.0.1:4433/static/lib/jquery/jquery-1.11.1.min.js] line=[2] lineSource=[null] lineOffset=[0]
09:40:35,470  WARN DefaultCssErrorHandler:39 - CSS error: [21:23] Error in style rule. Invalid token ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <STRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
09:40:35,471  WARN DefaultCssErrorHandler:53 - CSS warning: [21:23] Ignoring the following declarations in this rule.
09:40:35,502  WARN DefaultCssErrorHandler:39 - CSS error: [148:23] Error in style rule. Invalid token ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <STRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
09:40:35,503  WARN DefaultCssErrorHandler:53 - CSS warning: [148:23] Ignoring the following declarations in this rule.
09:40:35,509  WARN DefaultCssErrorHandler:39 - CSS error: [163:23] Error in style rule. Invalid token ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <STRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
09:40:35,510  WARN DefaultCssErrorHandler:53 - CSS warning: [163:23] Ignoring the following declarations in this rule.
09:40:35,512  WARN DefaultCssErrorHandler:39 - CSS error: [182:23] Error in style rule. Invalid token ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <STRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
09:40:35,513  WARN DefaultCssErrorHandler:53 - CSS warning: [182:23] Ignoring the following declarations in this rule.
09:40:35,516  WARN DefaultCssErrorHandler:39 - CSS error: [201:23] Error in style rule. Invalid token ":". Was expecting one of: <S>, "}", <COMMA>, ";", "/", <PLUS>, "-", <HASH>, <STRING>, <URI>, "!", "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
09:40:35,516  WARN DefaultCssErrorHandler:53 - CSS warning: [201:23] Ignoring the following declarations in this rule.

我不知道这意味着什么,而且我似乎无法找到解决方案或理由来解释为什么会发生这种情况。我正在启用Javascript,但它抱怨CSS规则??

任何人都知道如何解决这个问题?

我正在使用 Selenium 2.21.0

0 个答案:

没有答案