I created a simple Page Object style test that automates testing for language changes on a site. Locally the test runs correctly, but when running in jenkins an error occurs.
I have attached a screenshot of the error: AssertionError: Test isn't completed: error when trying to change language: expected false to be true.
Application source code below.
File test.js.
const assert = require('chai').assert;
const LanguagePage = require('../PageObjects/LanguagePage');
describe('Language Change Test', function () {
this.timeout(120000);
it('Verify language change button', async function () {
const result = await LanguagePage.performLanguageChange();
assert.isTrue(result, 'Test isn\'t completed: error when trying to change language');
});
after(async function () {
await LanguagePage.closeBrowser();
});
});`
File BasePage.js:
const webdriver = require('selenium-webdriver');
const { By } = require('selenium-webdriver');
class BasePage {
constructor() {
this.driver = new webdriver.Builder().forBrowser('chrome').build();
this.driver.manage().setTimeouts({ implicit: 10000 });
}
async goToUrl(url) {
return await this.driver.get(url);
}
async findElementByXPath(path) {
return await this.driver.findElement(By.xpath(path));
}
async closeBrowser() {
return await this.driver.quit();
}
}
module.exports = BasePage;
File LanguagePage.js:
const BasePage = require('./BasePage');
class LanguagePage extends BasePage {
async performLanguageChange() {
try {
await this.goToUrl('https://www.mts.by');
const langButton = await this.findElementByXPath('/html/body/div[6]/header/div[1]/div/div/div[2]/div/div/a[2]');
await langButton.click();
const englishButton = await this.findElementByXPath('/html/body/div[6]/header/div[2]/div/div/div[2]/div/button');
const buttonText = await englishButton.getText();
console.log('Button Text:', buttonText);
return buttonText === 'Sign In';
} catch (error) {
return false;
}
}
}
module.exports = new LanguagePage();
To make sure that the site is translated into English, I compare the value of the englishButton button using the gettext() method for strict equality with "Sign In". Result of local run:
Local Language Change Test.
I tried adding delays before and after the click() and gettext() methods, tried using css instead of xpath (on the site full xpath is the same as xpath), but it doesn't help.