对于angularjs–量角器开关感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍安卓量角器,并为您提供关于AngularJsui-router.量角器测试失败、angularjs–Angula
对于angularjs – 量角器开关感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍安卓量角器,并为您提供关于AngularJs ui-router.量角器测试失败、angularjs – Angular中的量角器测试:如何检查指令属性?、angularjs – 任何无头浏览器的量角器?、angularjs – 使用单个Gulp任务运行量角器的有用信息。
本文目录一览:- angularjs – 量角器开关(安卓量角器)
- AngularJs ui-router.量角器测试失败
- angularjs – Angular中的量角器测试:如何检查指令属性?
- angularjs – 任何无头浏览器的量角器?
- angularjs – 使用单个Gulp任务运行量角器
angularjs – 量角器开关(安卓量角器)
这是我的测试:
describe("Harvest",function() { beforeEach(function () { browser.get('http://localhost:8110/'); expect(browser.getcurrenturl()).toMatch('_*#/login$'); element(by.model('user.username')).sendKeys('sam'); element(by.model('user.password')).sendKeys('pass'); element(by.id('bt_signin')).click(); }); afterEach(function () { browser.executeScript('window.sessionStorage.clear();'); }); describe('A user',function () { beforeEach(function () { browser.get('http://localhost:8110/'); }); it('should be able to obtain an access token from harvest',function () { expect(browser.getcurrenturl()).toMatch('_*#/home$'); //display and close the window element(by.id('btHarvest')).click(); expect(element(by.id('modalHarvest')).isPresent()).toBe(true); element(by.id('btCloseModal')).click(); expect(element(by.id('modalHarvest')).isPresent()).toBe(false); //Authenticate into harvest element(by.id('btHarvest')).click(); expect(element(by.id('modalHarvest')).isPresent()).toBe(true); browser.switchTo().frame('iframeHarvest'); //It fails here with a null exceptions,guess it can't find it element(by.id('email')).sendKeys(browser.params.harvestLogins.user); element(by.id('user_password')).sendKeys(browser.params.harvestLogins.password); element(by.id('sign-in-button')).click(); expect(element(by.name('commit')).isPresent()).toBe(true); browser.driver.switchTo().defaultContent(); }); }); });
这是生成的异常
1) Harvest A user should be able to obtain an access token from harvest Message: [31mError: Error while waiting for Protractor to sync with the page: {}[0m Stacktrace: Error: Error while waiting for Protractor to sync with the page: {} at Error (<anonymous>) ==== async task ==== WebDriver.executeScript() at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:45:22) ==== async task ==== Asynchronous test function: it() Error at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:26:5) at null.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:20:3) at Object.<anonymous> (/Users/samdurand/workspace/cake/subbie/src/test/web/js/features/harvest.js:1:63)
在按照建议更正iframe调用后,我收到此错误:
1) Projects A user is possible to create a project based on harvest data Message: [31mError: Error while waiting for Protractor to sync with the page: {}[0m Stacktrace: Error: Error while waiting for Protractor to sync with the page: {} at Error (<anonymous>)
解决方法
AngularJs ui-router.量角器测试失败
$rootScope.$on("$stateChangeStart",function (event,toState) { if(toState.authenticate && !MainService.isAuthenticated()) { if($cookieStore.get('authToken')) { MainService.loginWithToken($cookieStore.get('authToken')) .then(function() { $state.go(toState.name); event.preventDefault(); }); } $rootScope.requestPath = toState.name; $state.go('public.login'); event.preventDefault(); } if(toState.url == '/login' && MainService.isAuthenticated()) { $state.go('private.main'); event.preventDefault(); } });
在状态更改时,这将检查状态是否需要身份验证并在必要时转移到登录状态.此外,如果用户登录,则会阻止其进入登录状态.身份验证由存储在cookie中的令牌完成.
这是我的量角器测试场景:
describe('Routes',function() { it('Should go to the selected path if user logged in',function() { browser.get('/'); expect(browser.getLocationAbsUrl()).toMatch("/login"); browser.manage().addCookie("authToken","aaa"); browser.manage().getCookie("authToken").then(function(cookie) { expect(cookie.name).toBe('authToken'); expect(cookie.value).toBe('aaa'); }); browser.get('/'); expect(browser.getLocationAbsUrl()).toMatch("/main"); browser.get('/#/main'); expect(browser.getLocationAbsUrl()).toMatch("/main"); /* This part fails,because,when the user is logged in,he should be transfered to main state,if he is trying to reach the login page. In this failing case,the user is able to reach the /login even if he is logged in. */ browser.get('/#/login'); expect(browser.getLocationAbsUrl()).toMatch("/main"); browser.manage().deleteCookie("authToken"); browser.get('/#/login'); expect(browser.getLocationAbsUrl()).toMatch("/login"); browser.get('/#/main'); expect(browser.getLocationAbsUrl()).toMatch("/login"); });
});
当我尝试自己模拟测试行为时,一切都很好,但是当我运行量角器时:
Message: Expected 'http://localhost/#/login' to match '/main'.
堆栈跟踪:
错误:期望失败
解决方法
基本上,您等待新页面中的元素出现而不是依赖量角器等待状态/页面完成加载.在撰写此答案时,量角器在ui-router满载的等待页面上仍然不可靠.量角器等待$timeout和$http完成.
official doc
因此,如果您使用websocket,它可能不会被覆盖(至少根据我的观察).
你需要使用的api是browser.wait
browser.wait(function() { return $('#test321').isPresent(); // keeps waiting until this statement resolves to true },timetoWaitInMilliseconds,'message to log to console if element is not present after that time' ); expect($('#test321').isPresent()).toBe(true);
您可以在以下链接中找到详细信息
Protractor,AngularJS,Parse — Protractor does not wait for Angular to resolve
angularjs – Angular中的量角器测试:如何检查指令属性?
这就是我呈现的HTML的样子:
<div faqs-widget=""https://www.jb51.cc/tag/cop/" target="_blank">cope"> <h1>My FAQs</h1> <ul> <!-- ngRepeat: question in data --> <li ng-repeat="question in data"https://www.jb51.cc/tag/cop/" target="_blank">cope ng-binding">A question</li> <!-- end ngRepeat: question in data --> </ul> </div>
理想情况下,我想检查至少有一个带有faqs-widget属性的div.我怎样才能做到这一点?
(PS:关于我还应该测试什么的建议也是受欢迎的.)
解决方法
ptor.findElement(protractor.by.css('div[faqs-widget]').isElementPresent().then(function(v){ expect(v).toBe(true); });
angularjs – 任何无头浏览器的量角器?
您可以尝试docker-selenium,或者,如果您不喜欢Docker,您可以使用ubuntu-headless样品自行完成.这两种解决方案都提供Chrome& Firefox使用Xvfb即使没有真正的disPLAY.
更新2似乎可以在OSX中运行Xvfb:http://xquartz.macosforge.org/landing/
更新1 Mac OSX selenium无头解决方案:
启用对OSX计算机的多用户远程桌面访问
所以可以在Mac上测试硒无头.真的不是无头,而是作为另一个用户,所以它不会干扰您当前的用户显示.
要做到这一点,你需要kickstart:http://support.apple.com/en-us/HT201710
开始使用kickstart实用程序
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent
激活远程桌面共享,为所有用户启用访问权限并重新启动ARD代理:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all
Apple Remote Desktop 3.2或更高版本
允许所有用户访问并为所有用户提供完全访问权限
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all
Kickstart帮助命令
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help
angularjs – 使用单个Gulp任务运行量角器
现在,为了运行e2e测试,我必须打开3个单独的shell并运行以下命令:
webdriver-manager update webdriver-manager start npm start (which runs the app server) protractor protractor.conf.js (in a separate window)
必须有一种更简单的方法来运行这些测试.有什么想法吗?
var protractor = require("gulp-protractor").protractor; var spawn = require('child_process').spawn; //run webdriver method function runWebdriver(callback) { spawn('webdriver-manager',['start'],{ stdio: 'inherit' }).once('close',callback); } //run protractor.config method function runProtractorConfig() { gulp.src('./**/*-page.spec.js') .pipe(protractor({ configFile: 'protractor.config.js' })) .on('error',function (e) { throw e; }); } //execute protractor.config after webdriver is executed function runWebdriverProtractor(){ runWebdriver(runProtractorConfig); } //put them into gulp task gulp.task('run-protractor',runWebdriverProtractor);
关于angularjs – 量角器开关和安卓量角器的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于AngularJs ui-router.量角器测试失败、angularjs – Angular中的量角器测试:如何检查指令属性?、angularjs – 任何无头浏览器的量角器?、angularjs – 使用单个Gulp任务运行量角器的相关信息,请在本站寻找。
本文标签: