使用酱和量角器来测试Internet Explorer和safari

时间:2014-01-11 20:29:23

标签: angularjs protractor angularjs-e2e saucelabs

我有以下测试,当我使用firefox和chrome在本地和酱上(至少大部分时间)运行它们时运行正常。

ptor = protractor.getInstance();

baseUrl = protractor.getInstance().params.sBaseUrl;
aRequiredTextFieldsKeys = [
'sFirstName',
'sLastName',
'sStreet',
'sZip',
'sCity'
];


describe('form', function ()
{
var sFormUrl = baseUrl + '#/form';

beforeEach(function ()
{
    ptor.get(sFormUrl);
});


describe('wholeForm', function ()
{

    it('fully filled form => required fields have correct class && submit leads to other route', function ()
    {

        function checkRequiredClass(el)
        {
            expect(el.getAttribute('class')).toContain('ng-valid-required');
        }

        // requried text-fields
        for (var i = 0; i < aRequiredTextFieldsKeys.length; i++) {
            var el = element(by.model('oFormData.' + aRequiredTextFieldsKeys[i]));
            el.sendKeys('a');
            checkRequiredClass(el);
        }

        // email
        var elEmail = element(by.model('oFormData.sEmail'));
        elEmail.sendKeys('jo@jo.de');
        checkRequiredClass(el);

        // birthday
        var elBirthday = element(by.model('oFormData.oBirthday'));
        elBirthday.sendKeys('1.1.1995');
        checkRequiredClass(el);

        // checkboxes
        var elCheck1 = element(by.model('oFormData.bAgb'));
        elCheck1.click();
        checkRequiredClass(elCheck1);

        var elCheck2 = element(by.model('oFormData.bPrivatePolicy'));
        elCheck2.click();
        checkRequiredClass(elCheck2);
        // hack upload bon
        ptor.executeScript(function ()
        {
            var scope = $('#application-form-id').scope();
            scope.oFormData.bBonUploaded = true;
        });

        // submit form
        element(by.className('btn-submit')).click();

        ptor.getCurrentUrl()
            .then(function (url)
            {
                expect(url).toNotBe(sFormUrl);
            });
    });
 });

但是当我启动Internet Explorer或Safari时,我会遇到各种错误,而手动测试时页面工作正常。对于IE我得到:

  

消息:        UnknownError:JavaScript错误(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:97   毫秒构建信息:版本:'2.30.0',修订版:'dc1ef9c',时间:   '2013-02-19 00:15:27'系统信息:os.name:'Windows Server 2008 R2',   os.arch:'x86',os.version:'6.1',java.version:'1.6.0_35'Session   ID:42b30348-8598-4edb-923e-a7019ced6eb0驱动程序信息:   org.openqa.selenium.ie.InternetExplorerDriver功能   [{platform = WINDOWS,elementScrollBehavior = 0,javascriptEnabled = true,   enablePersistentHover = true,ignoreZoomSetting = false,   browserName = internet explorer,enableElementCacheCleanup = true,   unexpectedAlertBehaviour = dismiss,version = 10,   cssSelectorsEnabled = true,ignoreProtectedModeSettings = false,   requireWindowFocus = false,allowAsynchronousJavaScript = false,   handlesAlerts = true,initialBrowserUrl =,nativeEvents = true,   takesScreenshot =真}]

     

错误:等待Protractor与页面同步时出错:{“stack”:“TypeError:   无法在匿名函数中获取未定义或空引用的属性'get'(未知   脚本代码:25:5)\ n匿名函数(未知脚本代码:21:14)\ n匿名   function(未知脚本代码:21:2)“,”description“:”无法获取未定义的属性'get'   或null引用“,”数字“: - 2146823281}

对于Safari:

  

UnknownError:检测到页面卸载事件;脚本执行不适用于页面加载。 (警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:384毫秒   构建信息:版本:'2.33.0',修订版:'4e90c97',时间:'2013-05-22 15:32:38'   系统信息:os.name:'Windows Server 2008 R2',os.arch:'x86',os.version:'6.1',java.version:'1.6.0_35'   会话ID:null   驱动程序信息:org.openqa.selenium.safari.SafariDriver   功能[{platform = WINDOWS,javascriptEnabled = true,cssSelectorsEnabled = true,secureSsl = true,browserName = safari,takesScreenshot = true,version = 5.1.7}]

我对原因感到不安。我尝试使用相同的结果进行更简单的测试,我尝试了本地和远程网址,并尝试了各种延迟,例如waitForAngularwaitptor ignoreAsynch = true。它们都没有导致预期的结果。有什么建议吗?

我的量角器配置文件:

// A reference configuration file.
    exports.config = {

        seleniumServerJar: null,
        seleniumPort: null,
        chromeOnly: false,
        // Additional command line options to pass to selenium. For example,
        // if you need to change the browser timeout, use
        // seleniumArgs: ['-browserTimeout=60'],
        seleniumArgs: [],
        sauceUser: 'saucesuer',
        sauceKey: 'key',
        allScriptsTimeout: 120000,
        specs: [
            'test/e2e/**/*.js',
        ],

        // https://code.google.com/p/selenium/wiki/DesiredCapabilities
        // https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
        capabilities: {
            'browserName': 'phantomjs',
            'phantomjs.binary.path':'node_modules/phantomjs/bin/phantomjs'
        },


        // Selector for the element housing the angular app - this defaults to
        // body, but is necessary if ng-app is on a descendant of <body>
        rootElement: 'body',

        onPrepare: function ()
        {
    //        driver.manage().timeouts().setScriptTimeout(60000);
        },

        params: {
            sBaseUrl: 'https://dev.com/'

        },
        baseUrl: 'http://localhost:8000',

        framework: 'jasmine',

        // ----- Options to be passed to minijasminenode -----
        //
        // See the full list at https://github.com/juliemr/minijasminenode
        jasmineNodeOpts: {
            // onComplete will be called just before the driver quits.
            onComplete: null,
            // If true, display spec names.
            isVerbose: true,
            // If true, print colors to the terminal.
            showColors: true,
            // If true, include stack traces in failures.
            includeStackTrace: true,
            // Default time to wait in ms before a test fails.
            defaultTimeoutInterval: 120000
        }
    };

虽然它似乎无关紧要,但我使用grunt-protractor runner顺序运行多个实例。

           chrome: {
            options: {
                args: {
                    browser: 'chrome',
                    "idle-timeout": 120
                }
            }
        },
        firefox: {
            options: {
                args: {
                    browser: 'firefox'
                }
            }
        },
        ie9: {
            options: {
                args: {
                    browser: 'internet explorer',
                    version: '9',
                    "idle-timeout": 120
                }
            }
        },
        ie10: {
            options: {
                args: {
                    browser: 'internet explorer',
                    version: '10'
                }
            }
        },
        safari7: {
            options: {
                args: {
                    browser: 'safari',
                    version: '7'
                }
            }
        },
        safari6: {
            options: {
                args: {
                    browser: 'safari',
                    version: '6'
                }
            }
        },
        safari5: {
            options: {
                args: {
                    browser: 'safari',
                    version: '5'
                }
            }
        }
    }

grunt.registerTask('e2eall', [
    'protractor:ie9',
    'protractor:ie10',
    'protractor:safari5',
    'protractor:safari6',
    'protractor:safari7',
    'protractor:firefox',
    'protractor:chrome'
]);

1 个答案:

答案 0 :(得分:4)

雨果, 这是某些测试配置的问题,这些配置在Protractor 0.17中得到部分解决,并且在0.18中更明确地得到解决。我建议您将量角器更新为最新版( 0.18.1 在本文发布时)并查看是否能解决您的问题。

相关的更改日志条目:

v0.18

  

(10aec0f)fix(pageload):增加等待超时

     

在Sauce Labs上测试IE时,300毫秒等待会导致问题。这似乎太短了。 “browser.get()”总是超时。增加它解决了我们的问题。

v0.17

  

(a0bd84b)fix(pageload):在protractor.get()期间添加等待以解决卸载问题

     

在开始执行异步脚本之前,某些系统不会等待浏览器卸载事件完成。

     

关闭#406。关闭#85。

希望有所帮助!