Headless Protractor Tests Don't Plug on Xvfb

Headless protractor tests don't plug on Xvfb

Alright, I finally managed to run my Protractor tests headlessly using

xvfb-run -a webdriver-manager start --seleniumPort 9094 &
protractor myconf.js

Where -a chooses any free display, and & makes the task run in background.

Xvfb (xvfb-run) incorrect resolution

I search resolving of the problem almost 4 ours and, when I ask, answer was founded. Need to hardcode window size (I have chrome flag to start maximized and protractor parameter browser.driver.manage().window().maximize()).
Answer from here helps me How to set default browser window size in Protractor/WebdriverJS

onPrepare: function() {
setTimeout(function() {
browser.driver.executeScript(function() {
return {
width: window.screen.availWidth,
height: window.screen.availHeight
};
}).then(function(result) {
browser.driver.manage().window().setSize(result.width, result.height);
});
});
},

How to use Xvfb + protractor + Gulp

I assume this is a headless machine, hence the need for the X Window System virtual frame buffer? If so, simply run XVFB as a service. That solves the problem. If you needed to (not sure why) you could then start and stop the service from gulp.

Chromedriver won't launch headlessly with Protractor tests (error 199)

I added something in my Protractor configuration file that solved the problem:

capabilities: {
'browserName': 'chrome',
// NEW
'chromeOptions': {
args: ["--headless", 'no-sandbox', "--disable-gpu", "--window-size=800x600"]
}
},

The tests launch. They get another error (they dont plug to the Xvfb). But this one is another story...

Running protractor tests iwithin Jenkins - looking for some inspiration

Please try something like this. You should modify accoding to what commands you want to run.

on Windows:
Step 1.

npm install

Step 2.

start npm start

Step 3. (will sleep 2 seconds)

ping -n 2 127.0.0.1 >nul

Step 4.

node node_modules/protractor/bin/protractor protractor.conf.js

On Linux:

npm install

this will start and move on without waiting for it to finish

npm start &

will wait for selenium to start

while ! curl http://localhost:4444/wd/hub/status &>/dev/null; do :;
done

and at last

npm test

package.json example:

"scripts": {
"postinstall": "node node_modules/protractor/bin/webdriver-manager update",
"pretest": "npm run tsc",
"test": "npm run protractor",
"protractor": "node node_modules/protractor/bin/protractor",
"start": "node node_modules/protractor/bin/webdriver-manager",
"tsc": "node node_modules/typescript/bin/tsc"
},

https://github.com/andriyze/proTR/blob/master/package.json

How to Close Xvfb after usage

The simple solution is to keep the old value of DISPLAY, change it to point to the xvfb, and then after the test is run you can change it back to the saved value.

This leaves the xvfb running, so you should also get the pid of that process and kill it. Otherwise, if you run this set of steps a dozen times, you'll have a dozen xvfb processes running in the background.



Related Topics



Leave a reply



Submit