我试图用量角器测试角度应用。对于以下代码段,我找不到找到它的方法。
我正在尝试点击路线链接
完整的代码段
describe('Enter username and passord', function () {
it('should enter name as harish', function () {
browser.get('http://dev.policytracker.io');
element(by.buttonText('Login')).click().then( function () {
//browser.sleep(3000);
element(by.name('username')).sendKeys('Harish.abc');
browser.sleep(1000);
element(by.name('Password')).sendKeys('rupesh');
element(by.className('mat-raised-button')).click()
browser.sleep(5000);
//element(by.linkText('Calculators')).click();
element(by.css('[routerlink="/notifications/notification"]')).click();
//var byBranch = element(by.cssContainingText(".mat-list-item-content .font-size-xs > div", "Calculators"));
//byBranch.click();
//browser.waitForAngular();
});
});
});
HTML
<mat-nav-list _ngcontent-c0="" class="mat-nav-list mat-list-base" role="navigation">
<mat-list-item _ngcontent-c0="" class="text-color-light mdl-grid padding-lr-zero mat-list-item" routerlink="/notifications/notification" tabindex="0" ng-reflect-router-link="/notifications/notification">
<div class="mat-list-item-content">
<div class="mat-list-item-ripple mat-ripple" mat-ripple="" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLElement]"></div>
<div class="mat-list-text"></div>
<div _ngcontent-c0="" class="text-align-center full-width mdl-cell--hide-tablet mdl-cell--hide-phone">
<mat-icon _ngcontent-c0="" class="mdl-grid margin-zero padding-zero mat-icon material-icons mat-icon-no-color" role="img" aria-hidden="true">notifications</mat-icon>
<div _ngcontent-c0="" class="font-size-xs">Notifications</div>
</div>
<div _ngcontent-c0="" class="mdl-grid mdl-grid--no-spacing full-width mdl-cell--hide-desktop">
<mat-icon _ngcontent-c0="" class="mdl-grid margin-zero padding-l-zero mdl-cell--middle mat-icon material-icons mat-icon-no-color" role="img" aria-hidden="true">notifications</mat-icon>
<span _ngcontent-c0="" class="mdl-cell--middle">Notifications</span>
</div>
</div>
</mat-list-item>
</mat-nav-list>
错误堆栈:
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
Message:
Failed: script timeout: result was not received in 11 seconds
(Session info: chrome=75.0.3770.80)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'MADAN-RAMINENI', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: unknown
Stack:
ScriptTimeoutError: script timeout: result was not received in 11 seconds
(Session info: chrome=75.0.3770.80)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'MADAN-RAMINENI', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: Protractor.waitForAngular() - Locator: By(css selector, [routerlink="/notifications/notification"])
at thenableWebDriverProxy.schedule (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
at ProtractorBrowser.executeAsyncScript_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\browser.js:425:28)
at angularAppRoot.then (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\browser.js:456:33)
at ManagedPromise.invokeCallback_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
at TaskQueue.execute_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
at TaskQueue.executeNext_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
at asyncRun (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
at C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7Error
at ElementArrayFinder.applyAction_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\element.js:459:27)
at ElementArrayFinder.(anonymous function).args [as click] (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\element.js:91:29)
at ElementFinder.(anonymous function).args [as click] (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\element.js:831:22)
at E:\Protractor POC\spec.js:13:75
at elementArrayFinder_.then (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\built\element.js:804:32)
at ManagedPromise.invokeCallback_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
at TaskQueue.execute_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
at TaskQueue.executeNext_ (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
at asyncRun (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
at C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
From: Task: Run it("should enter name as harish") in control flow
at UserContext.<anonymous> (C:\Users\madan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:19)
From asynchronous test:
Error
at Suite.<anonymous> (E:\Protractor POC\spec.js:2:5)
at Object.<anonymous> (E:\Protractor POC\spec.js:1:63)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
1 spec, 1 failure
Finished in 32.402 seconds
答案 0 :(得分:0)
尝试以下一个
it('should enter name as harish', async() => {
await browser.get('http://dev.policytracker.io');
await browser.waitForAngularEnabled(true);
await element(by.buttonText('Login')).click();
await browser.sleep(3000);
await element(by.name('username')).sendKeys('Harish.abc');
await browser.sleep(1000);
await element(by.name('Password')).sendKeys('rupesh');
await element(by.className('mat-raised-button')).click();
await browser.sleep(5000);
await element(by.css('mat-nav-list>mat-list-item.text-color-light')).click();
});
希望它对您有帮助