在量角器配置中为硒测试设置非Chrome窗口大小

时间:2017-06-15 23:45:43

标签: javascript selenium firefox protractor

因此对于Chrome,我的理解是以下允许Protractor决定窗口的大小:

exports.config = {
    ...

    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: ['--window-size=1440,900', '-window-position=0,0']
        },
    },

    ...
}

我尝试做的是将类似的方法应用于其他浏览器,特别是Firefox和Internet Explorer。我特别试图避免让浏览器调整自身作为测试过程的一部分。我决定用Firefox开始我的努力。

在量角器论坛中搜索信息导致我here建议将exports.config对象的getMultiCapabilities属性设置为包含firefox-profile编码实例的promise。试图实施该解决方案导致任何尝试运行我的测试套件以启动Chrome窗口而不是Firefox。

尽管我可以说,有问题的演示项目已经过时了。另一个Stack Overflow帖子让我尝试了这个:

var FirefoxProfile = require('firefox-profile');
exports.config = {
    ...

    capabilities: firefoxCapabilities(),

    ...
}

function firefoxCapabilities() {
    var firefoxProfile = new FirefoxProfile();

    return {
        browserName: 'firefox',
        maxSessions: 1,
        firefox_profile : firefoxProfile,
    };
}

这几乎,ALMOST似乎有效。与示例项目中的示例不同,它至少启动了Firefox。不幸的是,根据this,似乎我应该使用selenium-webdriver / firefox而不是firefox-profile。好的,一切都很好,我只需安装另一个包,因为要求找不到selenium-webdriver / firefox;哦,等等,应该已经有空了吗?然后它变得越来越复杂了,我甚至没有看到让我相信创建我自己的Firefox配置文件甚至让我按照自己的意愿设置窗口尺寸的东西。

更改大头钉,我发现this(具体来说,Martin Sznapka的回答)似乎提出了一个更简单的解决方案:使用onPrepare属性告诉驱动程序它应该使用什么尺寸。也就是说,IntelliJ告诉我onPrepare是一个未使用的函数,当我打算并尝试实现解决方案时,似乎没有任何改变。变化似乎没有帮助。

所以在这一点上我花了几个多小时试图让量角器定义窗口的尺寸,因为它对Chrome来说非常容易。在过时的演示,额外的软件包和看似完全无效的解决方案之间,我发现自己想知道我是否在正确的轨道上。

非常感谢任何帮助或指向正确的方向。

编辑:根据请求,这是我的完整exports.config对象。这将启动Firefox,但似乎对窗口大小没有任何影响。

exports.config = {
    baseUrl: 'http://localhost:8080/',
    directConnect: true,
    framework: 'jasmine',
    capabilities: {
        browserName: 'firefox',
        maxSessions: 1,
    },
    // Options to be passed to Jasmine.
    jasmineNodeOpts: {
        defaultTimeoutInterval: 60000
    },
    //Ensures that user is signed in before running tests
    onPrepare: function () {
        var disableNgAnimate = function () {
            angular.module('disableNgAnimate', []).run([
                '$animate', function ($animate) {
                    $animate.enabled(false);
                }
            ]);
        };
        browser.addMockModule('disableNgAnimate', disableNgAnimate);

        beforeEach(function () {
            browser.ignoreSynchronization = true; // prevents waiting on angular until timing out.
            browser.driver.manage().window().setSize(300, 300);
        });
    },
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['**/*.spec.js'],
    suites: {
        demo: 'demo/demo.spec.js',
        index: 'index/index.spec.js',
    }
};

0 个答案:

没有答案