javaleanft

LeanFT to verify specific text is present


I need to verify that a specific string of text is present on webpage and check the number of occurences in LeanFT. I have tried code below to verify if text is present:

browser = BrowserFactory.launch(BrowserType.CHROME);
browser.getVisibleText().contains("Success");

Solution

  • I don't think getVisibleText on Browser is the best fit for the problem you're facing. AFAIK getVisibleText uses OCR and not the application's underlying technology.

    A better way, I think, would be to identify the Web.Element that contains "Success". If you don't want to bother getting the specific element you can use the Page's text property.

    I'm not familiar with LeanFT's Java SDK but in JavaScript it would be written like this:

    expect(browser.$(Web.Page({})).text()).toContain("Success");
    

    Edit: according to comments (thanks @Adelin), the Java equivalent is:

    browser.getPage().getText().contains("Success");