Hello. There is such a code. The snag in the place where I left XXXXXXXX. How do I go there each time in a cycle to substitute input data in turn (from 0th to last, one cycle).
public void MenuText (String ExpectedMenuItem1, String ExpectedMenuItem2, String ExpectedMenuItem3, String ExpectedMenuItem4, String ExpectedMenuItem5){ List<WebElement> allLi = driver.findElements(By.xpath("//ul[@class = 'navbar_item']/li")); int sizeAllLi = allLi.size(); for(int i = 0; i < sizeAllLi; i++){ Assert.assertEquals(XXXXXXXX, allLi.get(i).getText()); } Thank you in advance.
UPD: Thanks for the tips and for the idea of using a variable number of arguments. And how do I then shove the data into this method? So I understand, it should be an array. This is code under Selenium and I want to use TestNG. Input data is specified in the xml file. While it turns out this way (taking into account your advice):
@Test @Parameters({"ExpectedMenuItem1", "ExpectedMenuItem2", "ExpectedMenuItem3", "ExpectedMenuItem4", "ExpectedMenuItem5"}) public void MenuText (String ... expectedMenuItems){ driver.get("https://www.medimpact.com/"); List<WebElement> allLi = driver.findElements(By.xpath("//ul[@class = 'navbar_item']/li")); int sizeAllLi = allLi.size(); for(int i = 0; i < sizeAllLi; i++){ // Assert.assertEquals(ExpectedMenuItem, allLi.get(i).getText()); Assert.assertTrue(expectedMenuItems.length > i); Assert.assertEquals(expectedMenuItems[i], allLi.get(i).getText()); }
public void MenuText(String... ExpectedMenuItems)this:public void MenuText(String... ExpectedMenuItems)- diraria