0

I have a static ExcelUnits class. I get a list from Excel and I wanna test with the list. Everything is working correctly. The locator is too late for only 1 html tag. It takes 20 to 30 seconds. That's too much. If I try this locator outside of testng provider, it finds this locator immediately. If this is because of Testng, why is this locator found in a very long time while other locators are found in a short time?

My dataprovider

@DataProvider(name = "setConnectionListForRemove")

public Object[][] setConnectionListForRemove() throws Exception {
    return ExcelUtils.setConnectionListForRemove();
}

@Test(priority = 9, dataProvider = "setConnectionListForRemove") public void setConnectionListForRemove(String firstName, String lastName, String company, String position, int rowNumber) throws InterruptedException, IOException {

    searchPage.clickShowKeywordsButton();
    Log4j.info("Clicked Showing Keywords List Button");
    searchPage.setConnectionsKnowledge(firstName, lastName, position, company);
    Log4j.info("Connection related data has been entered.");
    searchPage.clickKeywordsResult();
    Log4j.info("Clicked the Show results button.");
    boolean checkConnectionInformetion = searchPage.CheckConnectionInformation();
    Log4j.info("Checked About Connection Informations");
    if (!checkConnectionInformetion) {
        boolean checkPosition = searchPage.checkCurrentTitleWithPosition();
        if (!checkPosition) {
            searchPage.clickOpenProfile();

} } }`

I found the locator very slowly. The locator:

By getCurrentTitleElement = By.xpath("(//div[contains(@class,'entity-result__primary-subtitle t-14 t-black t-normal')])[1]");


    public boolean checkCurrentTitleWithPosition() {

        String currentTitle = (getText(getCurrentTitleElement) == null) ? "" : getText(getCurrentTitleElement);
        return Arrays.stream(properties.getProperty("Positions")
                .split(",")).anyMatch(position -> find(currentTitle, position)); // this is my positions list and the list at properties.file. 
    }

This is my getText method

public String getText(By key) {
        WebElement element = findElement(key);
        if (element != null)
            return findElement(key).getText();
        return null;
    }

This is my findElement method

public WebElement findElement(By key) {
        WebElement element = presenceElement(key);
        scrollToElement(element);
        return element;
    }

This is my presenceElement method

 public WebElement presenceElement(By key) {
        WebElement element = null;
        try {
            element = wait.until(ExpectedConditions.presenceOfElementLocated(key));
        } catch (TimeoutException e) {

        }
        return element;
    }

Does anyone have an idea?

  • This is definitely unrelated to data provider or to TestNg. You need to watch visually what is happening and why that locator takes so much time. You can also try to rework your locator from xpath to css. It works way faster especially considering you are just using filter by classes in your xpath locator. – Alexey R. Apr 20 '23 at 11:54
  • I don't think so. I tried except the data provider and it's works. I tried your idea but it doesn't work. Do you have any another idea? – Bilal Günaydın Apr 22 '23 at 14:10

0 Answers0