使用量角器进行当前url单元测试的getTitle?

时间:2016-05-17 19:33:30

标签: javascript selenium-webdriver jasmine protractor

尝试检查当前网址并获取html网页的标题。 我创建测试以单击我的帐户按钮,因为用户之前没有登录,然后网站重定向到登录页面然后我使用sendKeys发送用户名和密码然后单击登录按钮但是在调用browser.getCurrentUrl()之后 和browser.getTitle()仍然返回与登录前相同的标题。

    beforeEach(function () {
    browser.ignoreSynchronization = true;
    browser.get('https://*******************.net/');
});T

it(' childern (li) of parent (ul) with class(nav)  should have names Login/Register/Forgot Password/Forgot Username', function () {
    var myAccount = element(by.id('navItem_MyAccount'));
    myAccount.click();
    list = element.all(by.css('#tabs-Login li'));    
    expect(list.get(0).getText()).toBe('Login');
    expect(list.get(1).getText()).toBe('Register');
    expect(list.get(2).getText()).toBe('Forgot Password');
    expect(list.get(3).getText()).toBe('Forgot Username');

}, 10000);

it(' logIn should be active', function () {
    var myAccount = element(by.id('navItem_MyAccount'));
    myAccount.click();
    _login = element.all(by.css('.active'));
    expect(list.get(0).getText()).toBe('Login');

}, 1000);

it(' Page Title should be iSportsman: Home ', function () {
    var _login = element.all(by.css('#Login'));
    var log = element.all(by.css('#btnLogin'));
    var _loginPw = element.all(by.css('#inputRow-Password'));
    _login.sendKeys('************************');
    console.log('step1 done');

    _loginPw.sendKeys('*********');
    console.log('step2 done');

    log.click();
    console.log('step3 done');
    var _url = browser.getCurrentUrl();
    console.log(_url.toString());
    browser.get(_url.toString());

    browser.getTitle().then(function (title) {
        expect(title).toEqual('imakerman: Home');
    })

},10000);

});

1 个答案:

答案 0 :(得分:0)

它找到答案我忘记在sendKeys之前点击我的帐户按钮,在第三次测试中输入密码和user_name。然后我在一个承诺中结合user_name和密码,然后我点击登录按钮

it(' Page Title should be iMaker: Home ', function () {
    var myAccount = element(by.id('navItem_MyAccount'));
    myAccount.click();
    var log = element.all(by.css('#btnLogin'));
    var _login = element.all(by.css('#Login')).sendKeys('*****************');

    console.log('step1 done');

    var _loginPw = element.all(by.css('#Password')).sendKeys('**********');

    console.log('step2 done');

    protractor.promise.all([_login, _loginPw]).then(function () {

     log.click();
    });
    console.log('step3 done');
    browser.getCurrentUrl();

    browser.getTitle().then(function (title) {
        expect(title).toEqual('iMaker: Home');
    })

 },5000);
 });