A locator in Java Selenium Testng dataprovider is coming in a very long time. Why could it be?

51 Views Asked by At

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?

0

There are 0 best solutions below