2017-10-05 46 views
-2

config.js超时失败:等待后30009ms

exports.config = { 
framework: 'jasmine', 
seleniumAddress: 'http://localhost:4444/wd/hub', 

specs: [ 
    'Login.js', 
    'FeatureList.js', 
    'NewApplicationRegistration.js', 
    'ApplicationRegistrationManagement.js', 
    'RegistrationStatus.js', 
], 
baseUrl: 'http://localhost:3000', 
multiCapabilities: [{ 
    'browserName': 'chrome' 
}, 
    // { 
    //  'browserName': 'firefox' 
    // }, 
    // { 
    //  'browserName': 'internet explorer' 
    // } 
], 
jasmineNodeOpts: { 
    onComplete: null, 
    isVerbose: false, 
    showColors: true, 
    includeStackTrace: true, 
    defaultTimeoutInterval: 3000000 
}, 
allScriptsTimeout: 11000, 
rootElement: 'html', 
onPrepare: function() { 
    browser.ignoreSynchronization = true; 
    browser.driver.manage().window(); 
}, 
}; 

1规范文件

'use strict' 

describe('Application Registration Page', function() { 

beforeEach(function() { 
    browser.waitForAngular(); 
    browser.get('/register'); 
}); 

// Login 
it('Test for Login', function() { 
    expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/th/label'))); 
    var EC = protractor.ExpectedConditions; 
    var username = element(by.id('login-username')); 
    browser.wait(EC.visibilityOf(username), 30000); 
    username.sendKeys('sss'); 

    expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[2]/th/label'))); 
    var EC = protractor.ExpectedConditions; 
    var password = element(by.id('login-password')); 
    browser.wait(EC.visibilityOf(password), 30000); 
    password.sendKeys('sss'); 

    browser.driver.sleep(1000); 

    element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[3]/td/button')).click().then(function (username, password) { 
     if (username, password) { 
      browser.navigateTo('http://localhost:3000/register/core/feature-list'); 
     } else { 
      expect(browser.isElementPresent(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/td/b')))); 
     } 
    }); 
}); 
}); 

第二规格

'use strict' 

describe('Welcome to feature list', function() { 

beforeEach(function() { 
    browser.waitForAngular(); 
    browser.get('/register/core/feature-list'); 
}); 


describe('Header', function() { 

    // Application Registration text 
    it('Test for Application Registration text', function() { 
     var EC = protractor.ExpectedConditions; 
     var ar = element(by.xpath('/html/body/admin-app-root/layout/div[1]/c-header/nav/div/div[1]/a[2]')); 
     browser.wait(EC.presenceOf(ar), 2000000); 
     expect(ar.getAttribute('value')).toEqual('Application Registration'); 
    }); 


    it('Test for user name', function() { 
     var EC = protractor.ExpectedConditions; 
     var username = element(by.xpath('//*[@id="cox-navbar"]/ul/li[1]/a')); 
     browser.wait(EC.visibilityOf(username), 2000); 
     expect(username.isPresent()).toBe(true); 
    });  
}); 

1规范的脚本运行良好,但,同时运行第2规格我得到一个错误说:

等待超时后2000000ms

即使脚本超时是非常大的它越来越错误。在给定的时间内,它无法从浏览器中找到元素。

帮我找到解决方案。

+0

您是否尝试过使用此元素的其他选择器?使用这种xpath有点不好,也许尝试使用css类,名称或id? – Hikaryu

+0

@Hikaryu,亚我已经尝试了所有的期望,但同样的错误,我越来越。但有一件事我看到,虽然运行2nd规范它只显示第一个规格页面,但我不确定是否加载了第二个规格的browser.get页面。 – amit

回答

0

在很短的答案中:让您的量角器工作而不使用ignoreSynchronization来避免这些问题。我将详细阐述你的问题,从你特别提出的问题开始。

原因混得第二规格

EC.presencesOf(),超时被隐式调用waitForAngular read more about it here

因为你有你的ignoreSynchronization = true呼吁waitForAngular超时(因为你忽略AngularSynchronization量角器无法识别对象的存在)。因为你间接称它超时。

这只是没有意义,如果你使用ignoreSynchronization而不知道它的后果。原因很有限,为什么你应该使用它。

您与第一个规范问题,而ignoreSynchronization

鉴于你的XPath查询,对我来说,似乎你的Angular-Root-Elementbody,但admin-app-root。因此,请尝试将您的rootElement: bodyconfig.ts更改为rootElement: admin-app-root。 (作为一个可能的根本原因,为什么您的量角器不能很好地与您的Angular页面进行测试)。

配置调整后:如果仍然超时或缺少可测性,请进一步check this answer

同样减少您的timeout为2000000为您的ar -element。我认为,如此之久的超时几乎没有任何意义,因为之前的许多其他超时适用(Web超时,茉莉超时,进一步的webdriver超时等)。

一些更多的建议和相关信息

  1. global.EC = protractor.ExpectedConditions;conf.jsonPrepare:部分,所以你不必把它添加到每个测试用例。
  2. 添加并承诺一个步骤,你onPrepare:部分作为其他的测试可能开始早(见this documentationa simple example here
  3. 避免使用XPath的选择器,因为它们很慢,难以维护(任何任何添加div或移动窗体......基本上任何UI设计修改都可能让您的测试失败)。改用Angular-Model或CSS-Selectors(learn about it here)。
  4. 作为browser.get()命令不会创建承诺,您应该在beforeEach部分放置browser.waitForAngular()以确保您的测试仅在页面完全加载后启动。
  5. 只能使用ignoreSynchronization,如果您知道您测试了您需要它的特定情况。例如,如果您在加载过程中明确尝试验证某些内容,那么处理异步任务时(即测试阻塞程序元素的外观)。 Learn about the purpose of ignoreSynchronization here
  6. 如果您的量角器无法与您的Angular-Page同步或者您正在测试非角度页使用browser.waitForAngularEnabled(false)。如果你处理一个Angular页面,首先尝试调试Protractor不能同步的原因。 Learn about these possibilities here
+0

从测试用例中删除browser.wait(presenceOf()/ visibilityOf())后,出现错误,说没有找到使用定位器的元素。 – amit

+0

我刚才看到,在conf.js中设置了'ignoreSynchronization = true'。有什么具体的原因呢?因为这基本上告诉量角器不要等到页面加载。将该变量设置为true有更具体的原因。阅读更多关于[这里](https://stackoverflow.com/questions/28808463/what-is-browser-ignoresynchronization-in-protractor)。 我现在更新了我的答案。 –

+0

如果我对该行发表评论browser.ignoreSynchronization = true;那么我得到第一个规范的错误也说等待超时错误。 – amit

0

@amit尝试使用承诺beforeEach某事里面是这样的:

beforeEach(function() { 
    browser.waitForAngular().then(funtion(){ 
     return browser.get('/register/core/feature-list'); 
    }).then(function(){ 
     console.log(browser.getCurrentUrl()) // ensure you are on correct url 
    }) 
}); 

它应该工作。

+0

该代码不起作用。 @Hikaryu – amit

+0

有什么错误?因为没有它,我无法帮助。如果你复制粘贴然后它可能无法正常工作,因为我只是为了一个想法而写它 – Hikaryu

+0

我写了代码并尝试过,但得到相同的错误。 – amit

相关问题