带Nightwatch.js集成测试的Selenium缓存问题

Rob*_*son 1 selenium-webdriver nightwatch.js

我在Selenium网络驱动程序(v2.41.0)之上使用Nightwatch.js(v0.5.6)构建了一个小型但不断增长的集成测试套件(希望如此)。我总是会偶尔遇到Element not found in the cache错误,但是我正在处理一个大型的验证测试用例-一个文件,其中包含2打以上的单独测试以及setUp()。我还不能完成运行此测试,这是一个问题。

There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
Run Code Online (Sandbox Code Playgroud)

该错误似乎总是在我的setUp()函数结束时发生,但是我找不到能阻止这种缓存发生的答案。这是我的setUp()功能:

setUp: function(browser) {
  console.log('Logging in & navigating to Eligibility Groups...');
  login(browser, app.masterAdminUsername, app.masterAdminPassword)
    // Navigate to Eligibility Groups
    .waitForElementVisible('button[data-action="EligibilityGroups"]', 1000, function() {
      browser
        .click('button[data-action="EligibilityGroups"]', function() {
          console.log('Link clicked. Waiting for #btnCreate to be visible');
          browser
            .waitForElementVisible('#btnCreate', 1000, function() {
              console.log('Exiting setUp()');
            });

        });
    })
}
Run Code Online (Sandbox Code Playgroud)

最终,我得到了:

There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
    Command duration or timeout: 3.72 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
    Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
    System info: host: 'robwilkerson.local', ip: '172.20.1.112', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
    Session ID: 04f47f5c-fda0-f049-9ec1-1d3a40ac44fe
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=30.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
?  Timed out while waiting for element <#btnCreate> to be visible for 1000 milliseconds.  - expected "visible" but got: not visible
Run Code Online (Sandbox Code Playgroud)

测试用例有所不同,但“在等待元素<#btnCreate>可见1000毫秒时”似乎总是失败。更改我等待的毫秒数仅会更改错误中报告的毫秒数。

我在这里可以做什么?我的脚本有问题吗?我读过的所有内容和尝试过的所有内容都无济于事。

Rob*_*son 5

万一有人跌落,我通过反复试验发现:

  1. 实际上,每次.click()加载或重新加载内容时,我都需要添加一个.pause()。通常,.pause(1000)就足够了,但偶尔需要更长的时间。.waitForElementVisible()单独使用很少能始终如一地工作。
  2. 每当我使用时.waitForElementVisible(),都会使用默认超时值30000。对于较大的值似乎没有任何惩罚。

可能会有更好的答案,但是到目前为止,这对我来说还算不错。

我现在将其标记为答案,但是如果有人有更好的策略,则可以更改它。