一、
以登陆模块为例子,举个例子:
const TESTPATH = require('./../path-conf');
describe('CloudOs Demo App', function() {
it('shuld open login page', function() {
browser.get(`${TESTPATH}/login`);
browser.setLocation('login');
expect(browser.getCurrentUrl()).toBe(`${TESTPATH}/login`);
});
it('should login sucess and open dashboard page', function() {
var loginBtn = element(by.buttonText('登 录'));
var name = element(by.model('$ctrl.name'));
var password = element(by.model('$ctrl.password'));
name.sendKeys('307409359@qq.com');
password.sendKeys('Huawei@2015');
loginBtn.click();
expect(browser.getCurrentUrl()).toBe(`${TESTPATH}/dashboard`);
})
});
二、
//Jasmine describe statement : Describes the test describe('APP LOGIN::', function() { //before Each : This piece of code executes before all it statement beforeEach(function() { var ptor = protractor.getInstance(); ptor.get('https://app.vwo.com'); }); //Jasmine it statement : What "it" will do. it('Verify that the user is logged in', function() { //Delete all cookies browser.driver.manage().deleteAllCookies(); //Enter UserName element.all(by.model('username')).get(0).sendKeys('abc@wingify.com'); //Enter Password element(by.model('password')).sendKeys('test'); //Click Submit button element(by.css('.login-form button[type="submit"]')).click(); //Wait for the current URL to change to welcome browser.driver.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return (/welcome/).test(url); }); }); //Jasmine expect statement : compare actual and expected value expect(browser.getCurrentUrl()).toEqual('https://app.vwo.com/#/welcome'); }); /* Write other it blocks */ });