Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Selenium自动测试网站的同步问题以及使用Internet Explorer的测试问题。_Javascript_Angularjs_Selenium_Internet Explorer_Automated Tests - Fatal编程技术网

Javascript 使用Selenium自动测试网站的同步问题以及使用Internet Explorer的测试问题。

Javascript 使用Selenium自动测试网站的同步问题以及使用Internet Explorer的测试问题。,javascript,angularjs,selenium,internet-explorer,automated-tests,Javascript,Angularjs,Selenium,Internet Explorer,Automated Tests,我正在尝试使用SeleniumWebDriver为我的一个网站编写一个自动测试程序。我在Internet Explorer上进行测试时遇到一些问题。我尝试测试的网站是用AngularJS构建的。我会详细解释我的问题 这里是等待Angular完成处理的代码 private static ExpectedCondition angularHasFinishedProcessing() { return (ExpectedCondition<Boolean>) driver -&g

我正在尝试使用SeleniumWebDriver为我的一个网站编写一个自动测试程序。我在Internet Explorer上进行测试时遇到一些问题。我尝试测试的网站是用AngularJS构建的。我会详细解释我的问题

这里是等待Angular完成处理的代码

private static ExpectedCondition angularHasFinishedProcessing() {
    return (ExpectedCondition<Boolean>) driver -> {
        String hasAngularFinishedScript = "var callback = arguments[arguments.length - 1];\n" +
                "var el = document.querySelector('html');\n" +
                "if (!window.angular) {\n" +
                "    callback('false')\n" +
                "}\n" +
                "if (angular.getTestability) {\n" +
                "    angular.getTestability(el).whenStable(function(){callback('true')});\n" +
                "} else {\n" +
                "    if (!angular.element(el).injector()) {\n" +
                "        callback('false')\n" +
                "    }\n" +
                "    var browser = angular.element(el).injector().get('$browser');\n" +
                "    browser.notifyWhenNoOutstandingRequests(function(){callback('true')});\n" +
                "}";

        JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
        assert javascriptExecutor != null;
        String isProcessingFinished = javascriptExecutor.executeAsyncScript(hasAngularFinishedScript).toString();

        return Boolean.valueOf(isProcessingFinished);
    };
}

private void waitForAngular() {
    WebDriverWait wait = new WebDriverWait(driver, 15, 100);
    wait.until(angularHasFinishedProcessing());
}
我不得不绕过保护模式设置(如上面代码所示),因为我经常遇到这种异常

Caused by: org.openqa.selenium.WebDriverException: Unexpected error launching Internet
Explorer. Protected Mode must be set to the same value (enabled or disabled) for all
zones. (WARNING: The server did not provide any stacktrace information)
尽管我确保启用了保护模式,并且为所有区域设置了相同的值

现在我遇到了真正的问题。看看这段代码

waitForAngular();

WebElement el = driver.findElement(By.xpath("//div[@class='events-list__event-info' and @id='48040']" +
            "//following-sibling::div[@class='events-list__event-buy']/a"));
if(driver.toString().toUpperCase().contains("INTERNETEXPLORER"))
    el.sendKeys(Keys.ENTER);
else
    el.click();

waitForAngular();

webElement = driver.findElement(By.xpath("(//div[@class='ticket u-cf ng-scope'])[1]//select"));
select = new Select(webElement);
select.selectByIndex(1);
我的第一个问题是,我试图通过调用
waitForAngular()
来等待Angular应用程序准备就绪,这是一种好方法吗?
在我的程序中,我甚至不得不多次使用
Thread.sleep()
,以便在调用元素的操作之前让元素正确渲染。若你们能给我推荐一种使用SeleniumWebDriver和Angular应用程序的正确方法,那个就太好了

现在让我们谈谈我的第二个问题。为了运行这个程序,我必须从Internet Explorer的选项中完全禁用受保护模式。否则我会得到这个例外

Caused by: org.openqa.selenium.JavascriptException: JavaScript error in async script. (WARNING: The server did not provide any stacktrace information)
我在尝试执行
waitForAngular()
时遇到此异常这可能是什么原因造成的?是否有任何方法可以使受保护模式保持启用状态,并且仍然能够在
angularHasFinishedProcessing()方法中执行该脚本?

最后,我的第三个问题与未触发的单击操作有关。暂时忘掉之前的问题。我禁用了IE的保护模式,所以我的程序启动IE时不会抛出任何异常。程序成功地找到了第一个元素,如上面的代码所示。但是,不会触发单击操作,因此浏览器不会导航到下一页,并且程序无法找到第二个元素。作为一种解决方法,我甚至尝试了
el.sendKeys(Keys.ENTER)但它不起作用。**那么,我遇到这个问题是因为我绕过/禁用了保护模式吗?或者,还有什么我看不见的吗**

我在IE、Opera、Chrome和Firefox上运行测试,问题似乎只发生在IE上。我们非常感谢您提供的任何帮助、建议或指导

多谢各位

Caused by: org.openqa.selenium.JavascriptException: JavaScript error in async script. (WARNING: The server did not provide any stacktrace information)