本文整理汇总了Golang中github.com/sclevine/agouti.Page.Forward方法的典型用法代码示例。如果您正苦于以下问题:Golang Page.Forward方法的具体用法?Golang Page.Forward怎么用?Golang Page.Forward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/sclevine/agouti.Page
的用法示例。
在下文中一共展示了Page.Forward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: itShouldBehaveLikeAPage
//.........这里部分代码省略.........
Expect(page.Find("#some_element")).NotTo(HaveText("some text"))
Eventually(page.Find("#some_element"), "4s").Should(HaveText("some text"))
Consistently(page.Find("#some_element")).Should(HaveText("some text"))
})
// NOTE: disabled due to recent Firefox regression with passing args
if name != "Firefox" {
By("executing provided JavaScript", func() {
arguments := map[string]interface{}{"elementID": "some_element"}
var result string
Expect(page.RunScript("return document.getElementById(elementID).innerHTML;", arguments, &result)).To(Succeed())
Expect(result).To(Equal("some text"))
})
}
})
It("should support taking screenshots", func() {
Expect(page.Screenshot(".test.screenshot.png")).To(Succeed())
defer os.Remove(".test.screenshot.png")
file, _ := os.Open(".test.screenshot.png")
_, err := png.Decode(file)
Expect(err).NotTo(HaveOccurred())
})
It("should support links and navigation", func() {
By("clicking on a link", func() {
Expect(page.FindByLink("Click Me").Click()).To(Succeed())
Expect(page.URL()).To(ContainSubstring("#new_page"))
})
By("navigating through browser history", func() {
Expect(page.Back()).To(Succeed())
Expect(page.URL()).NotTo(ContainSubstring("#new_page"))
Expect(page.Forward()).To(Succeed())
Expect(page.URL()).To(ContainSubstring("#new_page"))
})
By("refreshing the page", func() {
checkbox := page.Find("#some_checkbox")
Expect(checkbox.Check()).To(Succeed())
Expect(page.Refresh()).To(Succeed())
Expect(checkbox).NotTo(BeSelected())
})
})
// NOTE: browsers besides PhantomJS do not support JavaScript logs
if name == "PhantomJS" {
It("should support retrieving logs", func() {
Eventually(page).Should(HaveLoggedInfo("some log"))
Expect(page).NotTo(HaveLoggedError())
Eventually(page, "4s").Should(HaveLoggedError("ReferenceError: Can't find variable: doesNotExist\n (anonymous function)"))
})
}
It("should support switching frames", func() {
By("switching to an iframe", func() {
Expect(page.Find("#frame").SwitchToFrame()).To(Succeed())
Expect(page.Find("body")).To(MatchText("Example Domain"))
})
// NOTE: PhantomJS does not support Page.SwitchToParentFrame
if name != "PhantomJS" {
By("switching back to the default frame by referring to the parent frame", func() {
Expect(page.SwitchToParentFrame()).To(Succeed())
Expect(page.Find("body")).NotTo(MatchText("Example Domain"))
})
示例2: testPage
func testPage(browserName string, newPage pageFunc) {
Describe("page test for "+browserName, func() {
var (
page *agouti.Page
server *httptest.Server
)
BeforeEach(func() {
server = httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
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 retrieving page properties", func() {
Expect(page).To(HaveTitle("Page Title"))
Expect(page).To(HaveURL(server.URL + "/"))
Expect(page.HTML()).To(ContainSubstring("<h1>Title</h1>"))
})
It("should support JavaScript", func() {
By("waiting for page JavaScript to take effect", func() {
Expect(page.Find("#some_element")).NotTo(HaveText("some text"))
Eventually(page.Find("#some_element"), "4s").Should(HaveText("some text"))
Consistently(page.Find("#some_element")).Should(HaveText("some text"))
})
// NOTE: disabled due to recent Firefox regression with passing args
if browserName != "Firefox" {
By("executing provided JavaScript", func() {
arguments := map[string]interface{}{"elementID": "some_element"}
var result string
Expect(page.RunScript("return document.getElementById(elementID).innerHTML;", arguments, &result)).To(Succeed())
Expect(result).To(Equal("some text"))
})
}
})
It("should support taking screenshots", func() {
Expect(page.Screenshot(".test.screenshot.png")).To(Succeed())
defer os.Remove(".test.screenshot.png")
file, _ := os.Open(".test.screenshot.png")
_, err := png.Decode(file)
Expect(err).NotTo(HaveOccurred())
})
It("should support links and navigation", func() {
By("clicking on a link", func() {
Expect(page.FindByLink("Click Me").Click()).To(Succeed())
Expect(page.URL()).To(ContainSubstring("#new_page"))
})
By("navigating through browser history", func() {
Expect(page.Back()).To(Succeed())
Expect(page.URL()).NotTo(ContainSubstring("#new_page"))
Expect(page.Forward()).To(Succeed())
Expect(page.URL()).To(ContainSubstring("#new_page"))
})
By("refreshing the page", func() {
checkbox := page.Find("#some_checkbox")
Expect(checkbox.Check()).To(Succeed())
Expect(page.Refresh()).To(Succeed())
Expect(checkbox).NotTo(BeSelected())
})
})
// NOTE: browsers besides PhantomJS do not support JavaScript logs
if browserName == "PhantomJS" {
It("should support retrieving logs", func() {
Eventually(page).Should(HaveLoggedInfo("some log"))
Expect(page).NotTo(HaveLoggedError())
Eventually(page, "4s").Should(HaveLoggedError("ReferenceError: Can't find variable: doesNotExist\n (anonymous function)"))
})
}
It("should support switching frames", func() {
By("switching to an iframe", func() {
Expect(page.Find("#frame").SwitchToFrame()).To(Succeed())
Expect(page.Find("body")).To(MatchText("Example Domain"))
})
// NOTE: PhantomJS does not support Page.SwitchToParentFrame
if browserName != "PhantomJS" {
By("switching back to the default frame by referring to the parent frame", func() {
Expect(page.SwitchToParentFrame()).To(Succeed())
Expect(page.Find("body")).NotTo(MatchText("Example Domain"))
})
//.........这里部分代码省略.........