当ProtratorJs Test

时间:2017-09-12 04:04:32

标签: angularjs automation protractor automated-tests

我面临browser.wait()的非常奇怪的行为。在我的测试网站有时Spinner出现,有时似乎没有处理这种情况我使用browser.wait()。但是当在该条件下页面中没有出现微调器时,我的代码不起作用并抛出异常。你能帮我解决这个问题吗?我如何确保如果没有微调器执行将继续,如果有一个微调器,它等待微调器完成,然后转到测试中的下一步。

以下是我的代码:

this.waitForSpinnerFinished = () => {
        browser.wait(function() {
            return element(by.css('.spinner')).isDisplayed().then(function(result) {
                return !result;
            })
        }, 30000)
    }}

错误报告

节点版本:v6.10.0 量角器版本:4.0.9 角度版本:1.X 浏览器:Chrome 操作系统和版本Windows 10

  • 您的量角器配置文件

    require('babel-register');
    
    exports.config = {
    
        directConnect: true,
        // chrome driver location if different than installed with webdriver-manager update, when directConnect: true
        chromeDriver: './4_utilsObjects/chromedriver_2.29.exe',
    
        allScriptsTimeout: 180000,
    
        framework: 'jasmine',
    
            suites: {
            tests: ['1_testLaunchers/*.js'],
            visual: ['visualRegression/*.js'],
        },
         rootElement: '[ng-app="preApp"]',
             capabilities: {
            'browserName': 'chrome',
            'chromeOptions': {
                // needed to disable saving passwords in account creation tests
                'prefs': {
                    'credentials_enable_service': false,
                    'profile': {
                        'password_manager_enabled': false
                    }
                }
            },
    
               },
    
               jasmineNodeOpts: {
            silent: true,
            defaultTimeoutInterval: 180000,
            // needed for jasmine-spec-reporter
            print: function () {
            }
        },
    
            onPrepare: () => {
            // here we're adding real time jasmine reporter that will display test steps
            // see https://github.com/bcaudan/jasmine-spec-reporter
            var SpecReporter = require('jasmine-spec-reporter');
            // add jasmine spec reporter
            jasmine.getEnv().addReporter(new SpecReporter({
                displayStacktrace: 'none',
                displaySuccessfulSpec: true,
                displayFailedSpec: true,
                displaySpecDuration: true,
                displaySuiteNumber: true,
                displayPendingSummary: false,
                displayPendingSpec: false
            }))
    
            // adding Jasmine JUnit reporter
            var jasmineReporters = require('jasmine-reporters');
            jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
                consolidateAll: true,
                savePath: 'reports/JUnitReporter',
                filePrefix: 'testresults'
            }))
    
            // reporter for TeamCity, enabled only in CI
            if (process.env.TEAMCITY_VERSION)
            {
                jasmine.getEnv().addReporter(new jasmineReporters.TeamCityReporter());
            }
    
            // Disable animations so e2e tests run faster
            var disableNgAnimate = function () {
                angular.module('disableNgAnimate', []).run(['$animate',function ($animate) {
                    $animate.enabled(false);
                }]);
            }
            browser.addMockModule('disableNgAnimate', disableNgAnimate);
    
            // reporter taking screenshots when failed assertion is spotted, comment out to speed up test run
            var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
            jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
                savePath: 'reports/screenshotReporter/',
                takeScreenshotsOnlyOnFailures: true,
            }))
        }
    }
    
  • 相关的示例测试

    this.startSignUp = () => {
            element(by.css('#protractorjs')).click();
            this.waitForSpinnerFinished();
        }
    
  • 运行测试的输出

  • 失败:找不到使用定位器找到的元素:按(css选择器,' .spinner')

1 个答案:

答案 0 :(得分:0)

自从我在量角器中写了一些东西已经有一段时间了,所以我没有一个好的地方来测试这个,但如果你将waitForSpinnerFinished的回报改为:

return result === false;