Reputation: 33
I have written 6 e2e tests , using protractor for my Angular2 application. The tests run fine on my windows 10 system . The tests are consistent and pass all the time.
Now I am trying to run the same tests in CentOS docker container. The tests are not consistent. They keep failing .
I get an error saying
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
I have increased the time out , I have given browser.wait(till presence of ) in required places , I have increased the computing resources allocated to docker ( CPU-3 , Memory-3328MB) . nothing seem to have worked.
// Protractor configuration file, see link for more information
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': [ '--no-sandbox']
}
},
directConnect: false,
baseUrl: 'http://localhost:3200/',
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {
// NOOP
}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
One of the tests
// create a user and he should be able to login after creation
it('should add a new user and log him in successfully', () => {
browser.wait(until.presenceOf(userCreate.forename, 5000, 'Timed out'));
const forename = 'newUserFore' + generateRandom.generateRandom();
const surename = 'newUserSur' + generateRandom.generateRandom();
const username = 'newUserUser2' + generateRandom.generateRandom();
const password = 'Pass@123' + generateRandom.generateRandom();
userCreate.addUserWithPassword(forename, surename, username, password);
// select language
userCreate.selectDropdownByNumber(userCreate.mylang, 1);
// select role
userCreate.selectDropdownByNumber(userCreate.myrole, 1);
// click add
userCreate.addUserButton.click();
browser.wait(until.presenceOf(userCreate.successMessage, 5000, 'Timed out'));
expect(userCreate.successMessage.getText()).toContain('User saved successfully!');
// cancelbutton
userCreate.cancelbutton.click();
browser.wait(until.presenceOf(userOverview.addUserButton, 5000, 'Timed out'));
// logout
indexPage = homePage.menu.navigateTo(MenuOption.LOGOUT, until);
// click on login button on first page
loginPage = indexPage.loginButtonClickedOnBasePage();
// login with the credentials
browser.wait(until.presenceOf(loginPage.loginTitle, 5000, 'Timed out'));
loginPage.login(username, password);
browser.wait(until.presenceOf(menu, 5000, 'Timed out'));
expect(menu.isDisplayed()).toBe(true);
});
The functional test file , where I first start the server and then run the ui
#!/usr/bin/env bash
echo "API: Ensuring the port $API_SERVER_PORT is freed."
fuser -k -n tcp $API_SERVER_PORT
echo " Starting the server in detached mode. This will take about 5 minutes the first time "
cd ../api && mvn spring-boot:run -D server.port=$API_SERVER_PORT >> api-start.log 2>&1 &
# Wait for the server to come up..
while ! (ncat -w 1 127.0.0.1 $API_SERVER_PORT </dev/null >/dev/null 2>&1); do sleep 1; done
echo "Server started on port $API_SERVER_PORT"
echo "UI: Ensuring the port $UI_SERVER_PORT is freed."
fuser -k -n tcp $UI_SERVER_PORT
npm start >> ui-start.log 2>&1 &
while ! (ncat -w 1 127.0.0.1 $UI_SERVER_PORT </dev/null >/dev/null 2>&1); do sleep 1; done
echo "Angular app is running on port $UI_SERVER_PORT , startup logs is in start.log".
protractor container.protractor.conf.js
Upvotes: 1
Views: 676
Reputation: 1057
Have you tried volume mounting the host's /dev/shm
to the container?
https://github.com/SeleniumHQ/docker-selenium#running-the-images
That's apparently a known workaround to stop selenium from crashing with Chrome or Firefox inside Docker. The selenium crash wasn't immediately apparent, it was just expressed through the Jasmine timeout instead.
Upvotes: 1