标签: angularjs-e2e

Javascript.confirm()和Angularjs Karma e2e测试

我有一个Angularjs应用程序,在执行某些操作之前使用简单的javascript确认.

控制器:

function TokenController($scope) {
  $scope.token = 'sampleToken';

  $scope.newToken = function() {
    if (confirm("Are you sure you want to change the token?") == true) {
      $scope.token = 'modifiedToken';
    }
  };
}
Run Code Online (Sandbox Code Playgroud)

视图:

<div id="tokenDiv">
  Token:{{token}} <button ng-click="newToken()">New Token</button>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我想要进行端到端测试以检查在视图中是否正确替换了令牌.如何拦截javascript.confirm()呼叫,以便它不会停止执行测试?

测试:

it('should be able to generate new token', function () {
   var oldValues = element('#tokenDiv').text();
   element('button[ng-click="newToken()"]').click(); // Here the javascript confirm box pops up.
   expect(element('#tokenDiv').text()).not.toBe(oldValues);
});
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经尝试重新定义window.confirm函数,但实际的调用抱怨它是未定义的.

我也想设置一个Jasmine间谍,window.confirm但是在下面的语法中,spyOn(window, 'confirm');它给了我一个错误,说你不能窥探null …

jasmine angularjs karma-runner angularjs-e2e

12
推荐指数
3
解决办法
1万
查看次数

量角器期望currenturl失败

我正在尝试针对我的本地服务器运行e2e测试并测试生成的url(在单击导航按钮之后)是正确的结果.但是,生成的url始终为false.

我的代码如下所示:

HTML:

//http://localhost/#/current_Page
<html>
    <head><title></title></head>
    <body>
    //should change the current url to
    //http://localhost/#/new_page
    <button class="button" ng-click="change_page()">Change Page</button>
</html>
Run Code Online (Sandbox Code Playgroud)

测试代码:

var protractor = require('protractor');
require('protractor/jasminewd');

describe('Tests', function() {      
    var ptor;

    describe('Test 1', function() {
        var ptor = protractor.getInstance();
        ptor.get('#/current_page'); 
        it('change page and current url', function() {
            ptor.findElement(protractor.By.className('.button').click().then(function() {
                expect(ptor.currentUrl()).toContain('#/new_page');
            });
        });
    }, 30000);
});
Run Code Online (Sandbox Code Playgroud)

问题是单击按钮后的当前URL仍为#/ current_url,并且未更改为预期结果#/ new_page.

有谁知道我哪里出错了?

angularjs angularjs-e2e protractor

12
推荐指数
1
解决办法
1万
查看次数

$ httpBackend.whenGET()passThrough()未定义

我想传递一些我的http请求,而不是在我的单元测试中模拟它们,但是当我尝试调用passThrough()方法时,抛出了丢失方法的错误:

"TypeError:Object#没有方法'passThrough'".

有人知道我该如何解决它吗?

有我的代码:

'use strict';

describe('Controller: MainCtrl', function () {

    // load the controller's module
    beforeEach(module('w00App'));

    var scope, MainCtrl, $httpBackend;

    // Initialize the controller and a mock scope
    beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
        $httpBackend = _$httpBackend_;
        $httpBackend.expectGET('http://api.some.com/testdata.json').passThrough();


        scope = $rootScope.$new();
        MainCtrl = $controller('MainCtrl', {
            $scope: scope
        });
    }));
});
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-e2e

11
推荐指数
1
解决办法
1万
查看次数

点击量角器中元素的给定坐标

我想点击我的canvas元素的特定位置,所以我写了下面的Protractor代码:

var canvas = element(by.id("canvas"));

var clickCanvas = function(toRight, toBottom) { 
  browser.actions()
    .mouseMove(canvas, -toRight, -toBottom)
    .click();
}
Run Code Online (Sandbox Code Playgroud)

toRight/ toBottom是应该进行单击的像素数,相对于画布的左上角.

但是,似乎没有在给定坐标处执行单击.我从软件质量保证和测试堆栈交换的相关问题中获得了片段.

你能确认这个片段有效吗?
你能建议替代品吗?

javascript mousemove angularjs-e2e protractor

11
推荐指数
2
解决办法
1万
查看次数

量角器 - 在做下一步之前等待异步承诺

首先,我已经检查了关于这一点的各种帖子和博客,我仍然无法弄清楚如何正确地做到这一点.

我尝试了许多不同的组合:

  • 浏览器等待
  • protractor.controlFlow().执行
  • protractor.controlFlow().等待(

...仍然没有成功..

我的问题

在我的beforeEach函数中,我想调用一个量角器承诺并在执行其余代码之前等待它解决.

我的守则

我已经为愿意帮助我的人准备了这个简单的测试

describe('testAsync', function() {

  beforeEach(function() {
    console.log('beforeEach - step 1 ')

    browser.get("https://angularjs.org/");
    console.log('beforeEach - step 2 ')
    testFunc()
    console.log('beforeEach - after testFunc - step 3')

  });

  var testFunc = function(){

    console.log("testFunc - step 1")

    browser.wait(function() {
      var deferred = protractor.promise.defer();
      element(by.id('twitter-widget-1')).isPresent()
        .then(function (isPresent) {
          console.log("testFunc - step 2")
          deferred.fulfill(isPresent);
      });
      return deferred.promise;
    });

    console.log("testFunc - step 3")

  }

  it('test after BeforeEach', function() {
    console.log("Last trace")
  });

});
Run Code Online (Sandbox Code Playgroud)

电流输出

[launcher] Running 1 …
Run Code Online (Sandbox Code Playgroud)

webdriver promise selenium-webdriver angularjs-e2e protractor

11
推荐指数
1
解决办法
1万
查看次数

量角器E2E - 您如何管理数据库?

我目前正在依靠Node + Angular堆栈并利用Karma和Protractor进行测试.

我目前很难弄清楚如何处理创建和编辑数据的E2E测试,以及加载预期数据的需求.

搜索谷歌会出现大量各种自定义方法.我经常阅读'你应该设置你的数据'或'只是创建一个模拟'而不需要更多关于一个共同过程的细节.其他人从头开始创建一个全新的模拟模块需要花费太多开销.

我只想知道人们目前是如何做到的,并且有一个标准吗?或者人们往往只是嘲笑后端?自从你在浏览器范围内以来,模拟后端似乎并不像Karma那样简单.

我是按照预期使用MongoDB,所以很高兴在这个场景中做其他事情.特别是通过量角器自动加载夹具和数据库清理会很好.

unit-testing node.js angularjs angularjs-e2e protractor

10
推荐指数
1
解决办法
1217
查看次数

在AngularJS中,e2e测试的量角器有哪些替代方案?

目前,在2014年9月,Protractor似乎是唯一可行的框架,用于进行角度端到端测试.除了使用准系统WebDriver之外,还有其他我可以使用的框架吗?如果没有,是否有具体原因?

angularjs angularjs-e2e protractor

10
推荐指数
2
解决办法
7753
查看次数

在量角器测试中设置localStorage中的项目

describe('The feature', function() {     
    beforeEach(function () {
       browser.executeScript('localStorage.setItem("key","value");');
    });

   it('should do this', function() {

   });
});
Run Code Online (Sandbox Code Playgroud)

但是当用chromedriver 2.10和chrome 37对抗硒时,我得到了这个错误

Executing: [execute script: window.localStorage.setItem("key","value");, []])
15:31:29.747 WARN - Exception thrown
org.openqa.selenium.WebDriverException: <unknown>: Failed to read the 'localStorage'
property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: chrome=37.0.2062.120)
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-26-generic x86_64) (WARNING:  
The server did not provide any stacktrace information)
Run Code Online (Sandbox Code Playgroud)

知道问题出在哪里?

javascript selenium-webdriver angularjs-e2e protractor

10
推荐指数
1
解决办法
5646
查看次数

在非角度页面上使用量角器测试登录

我正在尝试使用量角器进行e2e测试,但首先我需要在非角度页面上登录.我尝试直接使用webDriver,如此处所示,但它失败了.

我的e2e测试:

describe('angularjs homepage', function() {

  it('should prompt the login page', function() {
    browser.get('/');
    expect(browser.driver.find(By.id('user_password')));
  });

});
Run Code Online (Sandbox Code Playgroud)

我的日志:

Running "protractor:all" (protractor) task
Using the selenium server at http://localhost:4444/wd/hub
F

Failures:

  1) angularjs homepage should prompt the login page
   Message:
     TypeError: Object [object Object] has no method 'find'
Run Code Online (Sandbox Code Playgroud)

你知道解决方案吗?

jasmine angularjs selenium-webdriver angularjs-e2e protractor

10
推荐指数
1
解决办法
8230
查看次数

等待与量角器的离子加载对话框

有类似的问题(下面链接)但没有解决这个问题.我正在为一个离子项目编写量角器测试.当Ionic Loading对话框出现并消失时,我需要执行测试.

我已经用应用程序的骨干和需要进行的测试创建了一个repo.解决这个问题并解决问题(我在下面描述了这个问题):https://github.com/TmanTman/StackoverflowQ.只需在conf.js中调整适用于您系统的Chrome的路径即可.

要模拟异步离子加载对话框,我只需将其添加到空白离子项目中的控制器:

$interval( function() {
        $ionicLoading.show({
            template: 'Async ionicLoading',
            duration: 5000
        });
      }, 5000 , 1);
    })
Run Code Online (Sandbox Code Playgroud)

我需要让量角器等待对话框出现,做一些测试,等待对话框消失,然后再进行一些测试.我在测试文件中的最新尝试是:

it('should only test when ionicLoading appears', function() {
  browser.wait(function(){
    return element(by.css('.loading-container.visible.active')).isPresent();
  }, 10000);
  var ionicLoadingText = element(by.css('.loading-container.visible.active')).getText();
  expect(ionicLoadingText).toEqual('Async IonicLoading');
})



it('should only test once ionicLoading disappears', function() {
  browser.wait(function() {
    var deferred = protractor.promise.defer();
    var q = element(by.css('.loading-container.visible.active')).isPresent()
      q.then( function (isPresent) {
        deferred.fulfill(!isPresent);
      });
      return deferred.promise;
    });
  expect(1).toEqual(1);
})
Run Code Online (Sandbox Code Playgroud)

我试图避免使用同步睡眠功能,因为我的代码是高度异步的.我尝试了无数的变化,但我无法让它发挥作用.我用于信息的链接包括:

angularjs-e2e protractor ionic-framework ionic e2e-testing

10
推荐指数
1
解决办法
966
查看次数