gpt4 book ai didi

java - 使用 Selenium 测试 Angularjs 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:20:31 25 4
gpt4 key购买 nike

我正在测试一个有 Angular 的 js 应用程序

链接 Angular js App

当我在 Web 应用程序上单击 UI Kit 链接时,出现以下错误 -

at demoaj.Ajapp.main(Ajapp.java:16) Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"html/body/div1/div1/aside/div/div/ul/li[2]/a"} Command duration or timeout: 51 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

我是新手,我对这个 AngularJS 做了一些研究

java代码

    package demoaj;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Ajapp {

public static void main(String[] args) throws InterruptedException {
WebDriver d=new FirefoxDriver();
d.manage().window().maximize();
d.get("http://iarouse.com/demo/index.html?product=square");
WebDriverWait wait = new WebDriverWait(d, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div[1]/div[1]/aside/div/div/ul/li[2]/a"))).click();
//d.findElement(By.xpath("html/body/div[1]/div[1]/aside/div/div/ul/li[2]/a")).click();

}

}

我认为它无法找到该元素,因为在 angularjs 中,dom 未呈现。当我检查页面源代码时,它没有显示任何东西,在对 angularjs 测试做了一些研究后,所有东西都被隐藏了,我有几个问题请帮忙,

用于 Angular 应用测试。

  1. 我想我必须使用 Protractor ?我想
  2. 如果我使用 Protractor ,我必须用 javascript 或 jquery 编写代码吗?
  3. 如果我使用 Protractor ,我可以使用 eclipse ide 或 intellij 在 java 中编写代码吗?

请帮忙,

提前致谢。

最佳答案

这是你的答案-

  • 是的,对于 AngularJS 测试,您需要使用 Protractor ,因为它具有等待 Angular 加载的内置支持。
  • 如果您使用 Protractor,那么您需要使用 JavaScript 而不是 jquery 编写代码。
  • 如果您使用 Protractor,则不能使用 Java,因为 Protractor 构建于 Selenium WebDriverJS 之上。

优点是您可以编写 Javascript 代码(比 Java 更简单)来测试您的 Angular 应用程序,并且您不必担心 AngularJS 如何在您的页面上运行。唯一可能让您感到困惑的是使用 promises这是从 WebdriverJS 中获取的。希望这会有所帮助。

关于java - 使用 Selenium 测试 Angularjs 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32557644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com