量角器:使用 angular $window 服务测试重定向
protractor: testing redirect with angular $window service
在我正在测试的应用程序中,我们使用 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>
protractor.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();
});
测试状态:
If we click the button it will block the test runner.
我想知道这到底是什么意思。我很好奇它为什么以及如何阻止量角器测试运行程序?这对测试该功能有何影响?看起来 ignore.Synchronization=true
可能有助于在其中一些情况下进行测试,但希望我能更好地理解 $window 服务破坏测试的原因,希望找到测试这些情况的良好解决方案。
只是点击按钮后会弹出提示框
在量角器中,您可以切换到它,检查文本并关闭:
var alertDialog = browser.switchTo().alert();
expect(alertDialog.getText(), 'Hello, E2E Tests');
alertDialog.accept(); // or alertDialog.dismiss();
在我正在测试的应用程序中,我们使用 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>
protractor.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();
});
测试状态:
If we click the button it will block the test runner.
我想知道这到底是什么意思。我很好奇它为什么以及如何阻止量角器测试运行程序?这对测试该功能有何影响?看起来 ignore.Synchronization=true
可能有助于在其中一些情况下进行测试,但希望我能更好地理解 $window 服务破坏测试的原因,希望找到测试这些情况的良好解决方案。
只是点击按钮后会弹出提示框
在量角器中,您可以切换到它,检查文本并关闭:
var alertDialog = browser.switchTo().alert();
expect(alertDialog.getText(), 'Hello, E2E Tests');
alertDialog.accept(); // or alertDialog.dismiss();