从非角度登录页面进行量角器测试

时间:2015-10-05 14:15:56

标签: angularjs protractor

我正在尝试从我的网站测试基本登录/注销。我的角度应用程序的入口点来自非角度登录页面(oauth),然后在验证凭据后为应用程序提供服务。我的测试将在本地运行,但不会在Circle Ci上运行;我的错误就是这个;

Message:
    Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
  Stack:
Error: Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

这是我的测试功能:

    it('Log into Webapp', function() {
     browser.ignoreSynchronization = true;
        browser.manage().timeouts().pageLoadTimeout(40000);
        browser.manage().timeouts().implicitlyWait(25000);

        browser.get('http://localhost:8000/login');

        element(by.id('username')).sendKeys('x..');
        element(by.id('password')).sendKeys('...');
        element(by.name('Login')).click();

        setTimeout(function(){}, 15000);
        element(by.name('save')).click();

        setTimeout(function(){}, 10000);
        //browser.waitForAngular();
        //browser.ignoreSynchronization = false;
        //browser.ignoreSynchronization = false;
        // Angular app should be served, Logout is on this
        browser.ignoreSynchronization = false;

        element(by.name('logoutBtn')).click();

});

2 个答案:

答案 0 :(得分:4)

尝试将ignoreSynchronization移至beforeEachafterEach

beforeEach(function () {
    browser.ignoreSynchronization = true;
});

afterEach(function () {
    browser.ignoreSynchronization = false;
});

帮我解决:Non-angular page opened after a click

答案 1 :(得分:1)

用browser.sleep(10000);

替换setTimeout调用

setTimeout在超时后执行回调函数,但主"线程"继续执行流程。所以你真的没有等待。

此外,您可以在上次logoutBtn点击之前使用browser.waitForAngular()。

这样的事情:

it('Log into Webapp', function() {
    browser.ignoreSynchronization = true;
    browser.manage().timeouts().pageLoadTimeout(40000);
    browser.manage().timeouts().implicitlyWait(25000);

    browser.get('http://localhost:8000/login');

    element(by.id('username')).sendKeys('x..');
    element(by.id('password')).sendKeys('...');
    element(by.name('Login')).click();

    browser.sleep(15000);
    element(by.name('save')).click();

    browser.sleep(10000);
    browser.waitForAngular();        

    element(by.name('logoutBtn')).click();

    // Angular app should be served, Logout is on this
    browser.ignoreSynchronization = false;

});

相关问题