代码之家  ›  专栏  ›  技术社区  ›  Om Prakash Ganesan

Geb断言html表行文本

  •  0
  • Om Prakash Ganesan  · 技术社区  · 7 年前

    这是我的HTML表行的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
    

    我需要检查此行的值是否与特定文本匹配,并对其进行断言。

    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')
        }
    }
    

    提前谢谢你

    2 回复  |  直到 7 年前
        1
  •  0
  •   Justin Schoen    7 年前

    Geb's navigator api 这允许您从页面上获取与jquery几乎相同的内容。使用xpath很难阅读,很难维护,而且不是最佳实践。

    在内容块中,如果使用id定义表:

    myTable{ $("table#myTable")}
    

    myTable.children('td').find{it.text() == 'your text here' }
    

    Github Repo ,这将帮助您编写未来的测试。我希望这能给你足够的时间。

        2
  •  0
  •   Nicole Zeckner    7 年前

    看起来您的断言位于内容块中。它应该采用自己的方法。类似这样:

    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 textCompare(){
            def message = displayMsg.text()
            assert (message == 'text pattern')
        }
    
    }