[英]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.