The general idea is to have parameterized locators for your elements that would take different values (taken from i18n files) depending on chosen language.
You can take this lib so that you build one page object for all languages in the way like this:
import click.webelement.pagefactory.parameterized.FindByParameterized;
import click.webelement.pagefactory.parameterized.PageObjectParameterized;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class MyPage extends PageObjectParameterized {
@FindByParameterized(xpath = "//button[@name='{wec:btn.name}']")
WebElement button;
@FindByParameterized(xpath = "//label[text()='{wec:lbl.text}']")
WebElement label;
@FindBy(xpath = "//input")
WebElement input;
public MyPage(SearchContext searchContext) {
super(searchContext);
}
}
and then your tests would look like:
@DataProvider(name = "languages")
Object[][] dataProvider(){
return new Object[][]{
{"en", "Press me", "Read me"},
{"ru", "Нажми меня", "Прочти меня"}
};
}
@Test(dataProvider = "languages")
public void testPage(String language, String btnLocator, String labelLocator){
driver.get(URL + "/" + language);
DefaultParameterProvider
.properties
.set(Map.of("btn.name", btnLocator, "lbl.text", labelLocator));
MyPage myPage = new MyPage(driver);
myPage.button.click();
myPage.label.getText();
}
There is also an article where some details of the concept implemented above are explained so that you can implement it in your own way.