【发布时间】:2017-01-14 02:09:42
【问题描述】:
我正在尝试获取当前 url 并希望将其存储为字符串,但 .then 始终返回未定义。以下是功能代码:
navigateToLandingPage() {
let EC = protractor.ExpectedConditions;
let currentURL: string;
browser.getCurrentUrl().then ( (url) => {
currentURL = url;
} );
if (currentURL !== 'operator') {
browser.get('localhost:3000/#/operator');
browser.wait(EC.urlContains('/operator'), 10000);
}
我这样称呼它形式规范:
describe('Checking Module', () => {
let page: CalendarModule;
let EC = protractor.ExpectedConditions;
beforeEach(() => {
page = new CalendarModule();
});
it('Clicking on Calendar should redirect to Calendar Module', () => {
page.commonMethodObj.navigateToLandingPage();
let calendarLink = page.getCalendarLink();
calendarLink.click().then(() => {
browser.wait(EC.urlContains('/calendar'), 50000);
expect(browser.getCurrentUrl()).toMatch('/calendar');
});
});
});
我正在使用以下版本的依赖项:
"@angular/core": "2.3.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"protractor": "~4.0.13"
【问题讨论】:
-
calendarLink.click()方法即可;但是,由于 Protractor 使这些异步调用看起来与 jasminewd 同步,因此不需要它。
标签: typescript protractor