multilingual automation testing using selenium webdriver

Viewed 1055

I am working on automation project that support multi languages the doubt here is, we have page like dashboard or any page where we'll be having many strings and texts so verifying all the text in each test case will be so lengthy so what will be best way or approach. I have created property file also but still don't know how we can verify multiple strings at once. please help me to optimize the test cases.

enter code here

{ please help }

1 Answers

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.

Related