Angular 如何编写一个简单的e2e测试?
e2e测试应该转到特定页面并检查URL 附录e2e-spec.tsAngular 如何编写一个简单的e2e测试?,angular,typescript,protractor,e2e-testing,endly,Angular,Typescript,Protractor,E2e Testing,Endly,e2e测试应该转到特定页面并检查URL 附录e2e-spec.ts import { AppPageObject } from './app.po'; describe('Subscriptions', () => { let main: AppPageObject; beforeEach(() => { main = new AppPageObject(); }); it('should work', () => { main.nav
import { AppPageObject } from './app.po';
describe('Subscriptions', () => {
let main: AppPageObject;
beforeEach(() => {
main = new AppPageObject();
});
it('should work', () => {
main.navigateToSubscriptions().then(() => {
main.getUrl().then(url => {
expect(url).toContain('account/subscriptions');
});
});
});
});
app.po.ts
import { browser, element, by } from 'protractor';
export class AppPageObject {
navigateToSubscriptions() {
return browser.get('/account/subscriptions');
}
getUrl() {
return browser.getCurrentUrl();
}
}
这是我的页面url:
这是一个错误:
预期“”包含“帐户/订阅”
这应该很容易。我做错了什么
也许您忘记了授权过程。看看这个例子: app.po.ts:
import { browser, element, by } from 'protractor';
export class AppPageObject {
public navigateTo(url?: string) {
browser.get(url || '/');
}
public loginForm(email: string, password: string) {
element(by.css("input[formcontrolname='email']")).sendKeys(email);
element(by.css("input[formcontrolname='password']")).sendKeys(password);
return element.all(by.id('login-button')).click();
}
public getCurrentUrl() {
return browser.getCurrentUrl();
}
}
附录e2e-spec.ts:
import { AppPageObject } from './app.po';
import { browser } from 'protractor';
describe('Subscriptions', () => {
let main: AppPageObject;
beforeEach(async () => {
main = new AppPageObject;
main.navigateTo('/#/auth/login');
});
it('should login', async () => {
main.loginForm('test@gmail.com', '1234')
.then(() => {
browser.driver.sleep(6000);
})
.then(() => {
expect(main.getCurrentUrl()).toContain('account/dashboard');
});
});
});
不如使用as e2e集成,您可以使用以下命令运行selenium测试
endly-r=测试
@test.yaml
defaults:
target:
URL: ssh://127.0.0.1/
credentials: localhost
pipeline:
init:
action: selenium:start
version: 3.4.0
port: 8085
sdk: jdk
sdkVersion: 1.8
test:
action: selenium:run
browser: firefox
remoteSelenium:
URL: http://127.0.0.1:8085
commands:
- get(http://localhost:5001/#/account/subscriptions)
- (xpath:input[formcontrolname='email']).clear
- (xpath:input[formcontrolname='email']).sendKeys(email);
- (xpath:input[formcontrolname='password']).clear
- (xpath:input[formcontrolname='password']).sendKeys(password);
- (#submit).click
- command: CurrentURL = CurrentURL()
exit: $CurrentURL:/account/subscriptions/
sleepTimeMs: 1000
repeat: 10
expect:
CurrentURL: account/subscriptions
这个错误意味着url没有改变,仍然在同一个页面中,当测试运行时,你看到页面改变了吗?你的目标url是什么?它位于另一个端口和应用程序上?@“Samuel Liew”免责声明,我已为endly开源提供了帮助