如何在chimp.js中使用Firefox配置文件?

时间:2017-09-19 20:50:34

标签: firefox automation profile webdriver-io chimp.js

我正在运行黑猩猩来自动化我的一些测试用例。在其中一个中,我必须下载一个文件并检查文件大小是否匹配。通过在黑猩猩配置文件的Webdriver.io部分中定义以下prefs,我可以在点击Chrome链接时自动下载文件:

prefs:{" profile.default_content_settings.popups":false," download.default_directory":" ./ downloads"}

现在,我试图对Firefox做同样的事情。但是,我仍然无法做到这一点。我读到我需要创建一个firefox配置文件并传递以下Firefox首选项:

"browser.download.folderList",2
"browser.download.manager.showWhenStarting",false
"browser.download.dir", "/save/file/to/this/directory"
"browser.helperApps.neverAsk.saveToDisk","text/html, application/xhtml+xml, application/xml, application/csv, text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream"

有没有办法在黑猩猩配置文件的Webdriver.io部分执行此操作,就像我为Chrome做的那样?

顺便说一句,我确实安装了npm package firefox profile。试图使用下面的代码直接在我的步骤defs中启动浏览器,但是我收到以下错误:

[chimp]检测到未处理的拒绝: [chimp] [hooks]错误:无法在end()连接到selenium服务器 - ula_software_step_defs.js:42:1

this.Given(/^The Home page with FF profile$/, function () {
    let fp = new FirefoxProfile();
    fp.setPreference("browser.download.folderList",2);
    fp.setPreference("browser.download.manager.showWhenStarting",false);
    fp.setPreference("browser.download.dir", "./downloads");
    fp.setPreference("browser.helperApps.neverAsk.saveToDisk","text/html, application/xhtml+xml, application/xml, application/csv, text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream");

     fp.encoded(function(prof) {

      let client = webdriverio.remote({
        desiredCapabilities: {
          browserName: 'firefox',
          firefox_profile: prof
        }
      });

      client
        .init()
        .url("www.google.com.br", shared.defaultTimeout)
        .pause(10000)
        .end();

    });

有人可以帮忙吗?

0 个答案:

没有答案
相关问题