使用Selenium测试Angularjs应用程序

Cha*_*ari 6 java selenium angularjs protractor webdriverjs

我正在测试角度js应用程序

链接Angular js App

当我点击Web应用程序上的UI Kit链接时,我收到以下错误 -

at demoaj.Ajapp.main(Ajapp.java:16)引起:org.openqa.selenium.NoSuchElementException:无法找到元素:{"method":"xpath","selector":"html/body/div 1/div 1/aside/div/div/ul/li [2]/a"}命令持续时间或超时:51毫秒有关此错误的文档,请访问: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();

        }

}
Run Code Online (Sandbox Code Playgroud)

我认为它无法找到该元素,因为在angularjs中dom不会渲染.当我检查页面源它没有显示任何东西被隐藏后对angularjs测试做一些研究我有几个问题请帮助,

用于Angular App测试.

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

请帮忙,

提前致谢.

Sun*_*l L 1

以下是我用来测试 AngularJS 应用程序的一些技术:

  1. 查看 Karma 框架。它非常好,并且有很好的文档。 https://karma-runner.github.io/0.8/plus/AngularJS.html
  2. 如果您更喜欢端到端测试,请使用 Protractor,因为它一次又一次地被证明是最好的。 https://angular.github.io/protractor/#/