【问题标题】:protractor: testing redirect with angular $window service量角器:使用角度 $window 服务测试重定向
【发布时间】:2016-01-04 11:07:33
【问题描述】:

在我正在测试的应用程序中,我们使用 angular $window service 重定向到不同的 URL。

例如: 当你点击一个按钮时,它会通过以下方式将你重定向到一个新页面:

$window.location.assign('/redirect/to/this/newURL');

angular docs for $window 中,他们提供了这个量角器示例:

index.html:

<script>
 angular.module('windowExample', [])
  .controller('ExampleController', ['$scope', '$window', function($scope, $window) {
    $scope.greeting = 'Hello, World!';
    $scope.doGreeting = function(greeting) {
        $window.alert(greeting);
    };
  }]);
</script>
<div ng-controller="ExampleController">
  <input type="text" ng-model="greeting" aria-label="greeting" />
  <button ng-click="doGreeting(greeting)">ALERT</button>
</div>

量角器.js:

 it('should display the greeting in the input box', function() {
    element(by.model('greeting')).sendKeys('Hello, E2E Tests');
    // If we click the button it will block the test runner
    // element(':button').click(); 
 });

测试状态:

如果我们点击按钮,它将阻止测试运行器。

我想知道这到底是什么意思。我很好奇它为什么以及如何阻止量角器测试运行器?这对尝试测试该功能有何影响?看起来ignore.Synchronization=true 可能有助于在其中一些情况下进行测试,但希望我能更好地理解为什么 $window 服务会破坏测试,以期找到测试这些情况的好解决方案。

【问题讨论】:

    标签: angularjs window protractor


    【解决方案1】:

    只是点击按钮会有提示框。

    在量角器中,您可以切换到它,检查文本并关闭:

    var alertDialog = browser.switchTo().alert();
    expect(alertDialog.getText(), 'Hello, E2E Tests');
    alertDialog.accept();  // or alertDialog.dismiss();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多