简体   繁体   English

如何启用 JavaScript Protractor Firefox Headless

[英]How to enable JavaScript Protractor Firefox headless

We have e2e test with Protractor on headless mode.我们在无头模式下使用量角器进行 e2e 测试。

We want to test the authentication first.我们要先测试身份验证。 The behaviour is like the above:行为类似于上述:

1/ The user tap a link on the browser 2/ the server will check if this user is authenticated or not 2.1 if the user is authenticated, the home page will appear 2.2 if not, the user will be redirect to the sso login page by a 1/ 用户点击浏览器上的链接 2/ 服务器将检查此用户是否通过身份验证 2.1 如果用户通过身份验证,则主页将出现 2.2 如果没有,用户将被重定向到 sso 登录页面一种

The problem here is that, the javascript won't be executed.这里的问题是,javascript 不会被执行。 I try to add some flags but it doesn't make any difference.我尝试添加一些标志,但没有任何区别。

exports.config = {
    allScriptsTimeout: 20000,

    specs: [
        './e2e/account/**/account.spec.ts',
    ],

    capabilities: {
        'browserName': 'firefox',
        'marionette': true,  
        'moz:firefoxOptions': {
          args: [ "--headless"],
          firefox_binary: '/opt/firefox/firefox',
          binary_: '/opt/firefox/firefox',
         },
        acceptInsecureCerts: true,
        javascriptEnabled: true,
   },

    directConnect: true,

    baseUrl: 'http://demop-staging-ppd.com/',
    framework: 'mocha',

    // SELENIUM_PROMISE_MANAGER: false,

    mochaOpts: {
        reporter: 'spec',
        slow: 3000,
        ui: 'bdd',
        timeout: 720000
    },

    beforeLaunch: function() {
        require('ts-node').register({
            project: 'tsconfig.e2e.json'
        });
    },

    onPrepare: function() {
        browser.driver.manage().window().setSize(1280, 1024);
        // Disable animations
        // @ts-ignore
        browser.executeScript('document.body.className += " notransition";');
        const chai = require('chai');
        const chaiAsPromised = require('chai-as-promised');
        chai.use(chaiAsPromised);
        const chaiString = require('chai-string');
        chai.use(chaiString);
        // @ts-ignore
        global.chai = chai;
    },

    useAllAngular2AppRoots: true
};

the spec file :规范文件:

  before(async () => {
    await browser.waitForAngularEnabled(false);    
  });

  it('should content display content ', async () => {
    await browser.get('/');
    browser.sleep(5000);
    const content= await browser.getPageSource();
console.log(content)

  });

I'm open to any suggestions and can provide you with any additional information.我愿意接受任何建议,并且可以为您提供任何其他信息。

[UPDATE] [更新]

I change my config file as a above to try enabling javascript on my browse.我像上面那样更改我的配置文件,以尝试在我的浏览器中启用 javascript。 It works on local but when I try this on docker image dosen't它适用于本地,但是当我在 docker 图像上尝试时却没有

capabilities: {
        'browserName': 'firefox',
        'marionette': true,
        'moz:firefoxOptions': {
            args: ["--headless"],
            firefox_binary: '/opt/firefox/firefox',
            binary_: '/opt/firefox/firefox',
            "prefs": {
                "javascript.options.showInConsole": true,
                "javascript.enabled": true
            },
            "log": { "level": "trace" }
        },
        acceptInsecureCerts: true,
        acceptSslCerts: true,

      },
multiCapabilities: [ { browserName: 'firefox', firefoxOptions: { args: ['--headless'] }, 'moz:firefoxOptions': { args: [ '--headless' ] } } ]

Please check with this请检查这个

Use webdriver-manager to execute.使用webdriver-manager来执行。 With directConnect you will have permission denied error.使用directConnect您将遇到权限被拒绝错误。

I checked in linux PC also.我也检查了 linux PC。 This works fine这工作正常

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 selenium 中使用无头 Chrome 启用 JavaScript - How to enable JavaScript with headless Chrome in selenium AngularJS量角器:在无头模式下随机失败(Firefox) - AngularJS Protractor: randomly fail in headless mode (Firefox) 如何设置Protractor配置以在FireFox上运行并启用CORS - How to set Protractor configuration to run on FireFox and enable CORS Firefox-启用报告Javascript错误 - Firefox - enable reporting of Javascript errors 如何在firefox中启用剪贴板? - How to enable clipboard in firefox? 如何在量角器配置中启用Safari的私人浏览 - How to enable private browsing for Safari in the Protractor configuration Selenium webdriver:firefox无头注入javascript来修改浏览器属性 - Selenium webdriver: firefox headless inject javascript to modify browser property 如何在Javascript /量角器中执行``isVisible'' - How to do 'isVisible' in Javascript/Protractor 如何在无头模式下运行浏览器(chrome,IE和firefox)? - How to run browsers(chrome, IE and firefox) in headless mode? JavaScript-如何在使用特殊字符验证输入字段时在Firefox浏览器中启用箭头键 - JavaScript - How to enable arrow key in Firefox browser while validating input fields against special characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM