I am new to Geb , I am writing a test that will check for a text on the webpage and assert if the value exists. The text I am interested is a table row text Here is my HTML table row's CSS / xpath .
/html/body/table/tbody/tr[3]/td/table/tbody/tr[3]/td[2]/table/tbody/tr/td/table/tbody/tr[2]/td/b/pre/a
body > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(3) > td:nth-child(2) > table > tbody > tr > td > table > tbody > tr:nth-child(2) > td > b > pre > a
my need is to check if the value of this row matches a particular text and assert it.
What is the best way to do in Geb. I have a tried a variety of options and I am not getting a clear clue.
class HomePage extends Page
{
static at ={ title== "Dispute Home Page"}
static content = {
displayMsg {$(By.xpath("/html/body/table/tbody/tr[3]/td/table/tbody/tr[3]/td[2]/table/tbody/tr/td/table/tbody/tr[2]/td/b/pre/a"))}
def message = displayMsg.text()
assert (message == 'text pattern')
}
}
thank you in advance
For starters, I highly advise you take advantage of Geb's navigator api that allows you to get content off the page nearly identical to jquery. Using xpath is difficult to read, hard to maintain and not best practice.
In your content block, if you define a table with an id:
myTable{ $("table#myTable")}
Now you can do things like the following:
myTable.children('td').find{it.text() == 'your text here' }
This can of course be expanded on to find specific rows or table data by name or even index. I have some examples of proper page objects and spec files in my Github Repo, which should aide you in writing future tests. I hope this gives you enough to work off of.