In my framework, I am using a combination of keyword-driven and data-driven approaches. The expected strings are retrieved from an Excel sheet while the actual strings are taken from the webpage. Interestingly, even when both variables print the exact same strings, the test script fails. It passes for strings without spaces like "Resign", but fails for strings with spaces like "Property Search". Below is the result which prints "PASS" until "Resign", after which it fails. Please ignore the numbers as they are used for debugging purposes. Additionally, the XPaths used in the result are included.
Result generated
By.xpath: html/body/div[2]/div/div[2]/ul/li[1]/ul/li[1]
Tool tip text present: Revals
Revals
1
By.xpath: html/body/div[2]/div/div[2]/ul/li[1]/ul/li[2]/a[contains(text(),'Managed Client Accounts')]
Tool tip text present: Managed Client Accounts
Managed Client Accounts
1
By.xpath: html/body/div[2]/div/div[2]/ul/li[1]/ul/li[3]
Tool tip text present: Resigns
Resigns
1
... (additional results listed) ...
Here is the code:
public String verify_Text(String locatorType, String value, String data){
try
{
By locator;
locator = locatorValue(locatorType, value);
System.out.println(locator);
WebElement element = driver.findElement(locator);
// Get tooltip text
String toolTipText = element.getText();
System.out.println("Tool tip text present :- " + toolTipText);
System.out.println(data);
// Compare toll tip text
if(toolTipText.contentEquals(data))
{
System.out.println("1");
return PASS;
}
... (rest of the method implementation) ...
catch(Exception e)
{
LOG.error(Executor.currentSheet + ":" + e);
getScreenshot("verify_Link", data);
System.out.println("3");
return FAIL;
}
getScreenshot("verify_Link", data);
System.out.println("4");
return FAIL;
}