本文整理汇总了Golang中github.com/sclevine/agouti.Page.FindByXPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Page.FindByXPath方法的具体用法?Golang Page.FindByXPath怎么用?Golang Page.FindByXPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/sclevine/agouti.Page
的用法示例。
在下文中一共展示了Page.FindByXPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testSelection
func testSelection(browserName string, newPage pageFunc) {
Describe("selection test for "+browserName, func() {
var (
page *agouti.Page
server *httptest.Server
submitted bool
)
BeforeEach(func() {
server = httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Method == "POST" {
submitted = true
}
html, _ := ioutil.ReadFile("test_page.html")
response.Write(html)
}))
var err error
page, err = newPage()
Expect(err).NotTo(HaveOccurred())
Expect(page.Size(640, 480)).To(Succeed())
Expect(page.Navigate(server.URL)).To(Succeed())
})
AfterEach(func() {
Expect(page.Destroy()).To(Succeed())
server.Close()
})
It("should support asserting on element identity", func() {
By("asserting on an element's existence", func() {
Expect(page.Find("header")).To(BeFound())
Expect(page.Find("header")).To(HaveCount(1))
Expect(page.Find("not-a-header")).NotTo(BeFound())
})
By("comparing two selections for equality", func() {
Expect(page.Find("#some_element")).To(EqualElement(page.FindByXPath("//div[@class='some-element']")))
Expect(page.Find("#some_element")).NotTo(EqualElement(page.Find("header")))
})
})
It("should support moving the mouse pointer over a selected element", func() {
Expect(page.Find("#some_checkbox").MouseToElement()).To(Succeed())
Expect(page.Click(agouti.SingleClick, agouti.LeftButton)).To(Succeed())
Expect(page.Find("#some_checkbox")).To(BeSelected())
})
It("should support selecting elements", func() {
By("finding an element by selection index", func() {
Expect(page.All("option").At(0)).To(HaveText("first option"))
Expect(page.All("select").At(1).First("option")).To(HaveText("third option"))
})
By("finding an element by chained selectors", func() {
Expect(page.Find("header").Find("h1")).To(HaveText("Title"))
Expect(page.Find("header").FindByXPath("//h1")).To(HaveText("Title"))
})
By("finding an element by link text", func() {
Expect(page.FindByLink("Click Me").Attribute("href")).To(HaveSuffix("#new_page"))
})
By("finding an element by label text", func() {
Expect(page.FindByLabel("Some Label")).To(HaveAttribute("value", "some labeled value"))
Expect(page.FindByLabel("Some Container Label")).To(HaveAttribute("value", "some embedded value"))
})
By("finding an element by button text", func() {
Expect(page.FindByButton("Some Button")).To(HaveAttribute("name", "some button name"))
Expect(page.FindByButton("Some Input Button")).To(HaveAttribute("type", "button"))
Expect(page.FindByButton("Some Submit Button")).To(HaveAttribute("type", "submit"))
})
By("finding an element by name attibute", func() {
Expect(page.FindByName("some button name")).To(HaveAttribute("name", "some button name"))
})
By("finding multiple elements", func() {
Expect(page.All("select").All("option")).To(BeVisible())
Expect(page.All("h1,h2")).NotTo(BeVisible())
})
})
It("should support retrieving element properties", func() {
By("asserting on element text", func() {
Expect(page.Find("header")).To(HaveText("Title"))
Expect(page.Find("header")).NotTo(HaveText("Not-Title"))
Expect(page.Find("header")).To(MatchText("T.+e"))
Expect(page.Find("header")).NotTo(MatchText("X.+e"))
})
By("asserting on whether elements are active", func() {
Expect(page.Find("#labeled_field")).NotTo(BeActive())
Expect(page.Find("#labeled_field").Click()).To(Succeed())
Expect(page.Find("#labeled_field")).To(BeActive())
})
By("asserting on element attributes", func() {
//.........这里部分代码省略.........
示例2:
user.LoginTo(page)
})
It("should show app structure for an authenticated user", func() {
By("allowing the user to click a dropdown menu labeled 'Organizations'", func() {
user.OpenDropdownOfOrgsOn(page)
})
By("allowing the user to click on an organization in the dropdown menu", func() {
user.SelectOrgFromDropdown(page, testEnvVars.TestOrgName)
})
By("showing the table containing spaces", func() {
DelayForRendering()
Expect(page.Find("#spacesTable")).To(BeFound())
Expect(page.FindByXPath("//*[@id='spacesTable']/thead/tr/th[1]").Text()).To(Equal("Name"))
Expect(page.FindByXPath("//*[@id='spacesTable']/thead/tr/th[2]").Text()).To(Equal("Number of Apps"))
Expect(page.FindByXPath("//*[@id='spacesTable']/thead/tr/th[3]").Text()).To(Equal("Total Development Memory"))
Expect(page.FindByXPath("//*[@id='spacesTable']/thead/tr/th[4]").Text()).To(Equal("Total Production Memory"))
})
By("allowing the user to click on a space in the tab views", func() {
DelayForRendering()
Expect(page.FindByLink(testEnvVars.TestSpaceName)).To(BeFound())
Eventually(Expect(page.FindByLink(testEnvVars.TestSpaceName).Click()).To(Succeed()))
})
By("showing app name and quota information (along with other information)", func() {
DelayForRendering()
DelayForRendering()
Eventually(page.Find("#app-name-heading")).Should(BeFound())
示例3: itShouldBehaveLikeAPage
func itShouldBehaveLikeAPage(name string, newPage pageFunc) {
Describe("integration test for "+name, func() {
var (
page *agouti.Page
server *httptest.Server
submitted bool
)
BeforeEach(func() {
server = httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Method == "POST" {
submitted = true
}
html, _ := ioutil.ReadFile("test_page.html")
response.Write(html)
}))
var err error
page, err = newPage()
Expect(err).NotTo(HaveOccurred())
Expect(page.Size(640, 480)).To(Succeed())
Expect(page.Navigate(server.URL)).To(Succeed())
})
AfterEach(func() {
Expect(page.Destroy()).To(Succeed())
server.Close()
})
Describe("Selection interactions", func() {
It("should support asserting on element identity", func() {
By("asserting on an element's existence", func() {
Expect(page.Find("header")).To(BeFound())
Expect(page.Find("header")).To(HaveCount(1))
Expect(page.Find("not-a-header")).NotTo(BeFound())
})
By("comparing two selections for equality", func() {
Expect(page.Find("#some_element")).To(EqualElement(page.FindByXPath("//div[@class='some-element']")))
})
})
It("should support selecting elements", func() {
By("finding an element by selection index", func() {
Expect(page.All("option").At(0)).To(HaveText("first option"))
Expect(page.All("select").At(1).First("option")).To(HaveText("third option"))
})
By("finding an element by chained selectors", func() {
Expect(page.Find("header").Find("h1")).To(HaveText("Title"))
Expect(page.Find("header").FindByXPath("//h1")).To(HaveText("Title"))
})
By("finding an element by link text", func() {
Expect(page.FindByLink("Click Me").Attribute("href")).To(HaveSuffix("#new_page"))
})
By("finding an element by label text", func() {
Expect(page.FindByLabel("Some Label")).To(HaveAttribute("value", "some labeled value"))
Expect(page.FindByLabel("Some Container Label")).To(HaveAttribute("value", "some embedded value"))
})
By("finding an element by button text", func() {
Expect(page.FindByButton("Some Button")).To(HaveAttribute("name", "some button name"))
Expect(page.FindByButton("Some Input Button")).To(HaveAttribute("type", "button"))
Expect(page.FindByButton("Some Submit Button")).To(HaveAttribute("type", "submit"))
})
By("finding an element by class", func() {
Expect(page.FindByClass("some-element")).To(HaveAttribute("id", "some_element"))
})
By("finding an element by ID", func() {
Expect(page.FindByID("some_element")).To(HaveAttribute("class", "some-element"))
})
By("finding multiple elements", func() {
Expect(page.All("select").All("option")).To(BeVisible())
Expect(page.All("h1,h2")).NotTo(BeVisible())
})
})
It("should support retrieving element properties", func() {
By("asserting on element text", func() {
Expect(page.Find("header")).To(HaveText("Title"))
Expect(page.Find("header")).NotTo(HaveText("Not-Title"))
Expect(page.Find("header")).To(MatchText("T.+e"))
Expect(page.Find("header")).NotTo(MatchText("X.+e"))
})
By("asserting on whether elements are active", func() {
Expect(page.Find("#labeled_field")).NotTo(BeActive())
Expect(page.Find("#labeled_field").Click()).To(Succeed())
Expect(page.Find("#labeled_field")).To(BeActive())
})
By("asserting on element attributes", func() {
Expect(page.Find("#some_checkbox")).To(HaveAttribute("type", "checkbox"))
})
//.........这里部分代码省略.........
示例4:
Eventually(page).Should(HavePopupText("Logged in as user"))
Expect(page.ConfirmPopup()).To(Succeed())
Eventually(page.Find("#howdy"), "10s").Should(HaveText("Logged in as User Name"))
})
By("go to catalogue", func() {
Expect(page.FindByLink("Catalogue").Click()).To(Succeed())
Eventually(page, "10s").Should(HaveURL("http://localhost:9102/category.html"))
})
By("add item in the cart", func() {
time.Sleep(4 * time.Second)
Expect(page.First(".product").Find(".fa-shopping-cart").Click()).To(Succeed())
Eventually(page.Find("#numItemsInCart"), "10s").Should(HaveText("1 item(s) in cart"))
})
By("go to cart", func() {
Expect(page.Find("#numItemsInCart").Click()).To(Succeed())
Eventually(page.Find("#basket"), "10s").Should(MatchText("Shopping cart"))
Eventually(page.FindByXPath("//tbody[@id='cart-list']/tr[1]/td[2]"), "1s").Should(HaveText("Loading..."))
Eventually(page.FindByXPath("//tbody[@id='cart-list']/tr[last()]/td[2]/a"), "10s").Should(HaveText("Holy"))
})
// Give some time to follow the demo
time.Sleep(5 * time.Second)
})
})