本文整理汇总了Golang中github.com/sclevine/agouti.Page.Navigate方法的典型用法代码示例。如果您正苦于以下问题:Golang Page.Navigate方法的具体用法?Golang Page.Navigate怎么用?Golang Page.Navigate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/sclevine/agouti.Page
的用法示例。
在下文中一共展示了Page.Navigate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LogoutOf
func (u User) LogoutOf(page *agouti.Page) {
Expect(page.Navigate(u.testEnvVars.Hostname + "/v2/logout")).To(Succeed())
/*
Expect(page.Find("#logout-btn").Click()).To(Succeed())
Eventually(Expect(page).To(HaveURL(u.testEnvVars.LoginURL + "login")))
*/
}
示例2: LoginTo
func (u User) LoginTo(page *agouti.Page) {
Expect(page.Navigate(u.testEnvVars.Hostname)).To(Succeed())
Expect(page.Find("#login-btn").Click()).To(Succeed())
Expect(page).To(HaveURL(u.testEnvVars.LoginURL + "login"))
Expect(page.FindByName("username").Fill(u.username)).To(Succeed())
Expect(page.FindByName("password").Fill(u.password)).To(Succeed())
Expect(page.FindByButton("Sign in").Click()).To(Succeed())
Expect(page).To(HaveURL(u.testEnvVars.Hostname + "/#/dashboard"))
}
示例3: LoginTo
func (u User) LoginTo(page *agouti.Page) {
Expect(page.Navigate(u.testEnvVars.Hostname + "/#/")).To(Succeed())
var loginLink = page.First(".test-login")
Eventually(loginLink).Should(BeFound())
Expect(loginLink.Click()).To(Succeed())
Eventually(page).Should(HaveURL(u.testEnvVars.LoginURL + "login"))
Expect(page.FindByName("username").Fill(u.username)).To(Succeed())
Expect(page.FindByName("password").Fill(u.password)).To(Succeed())
Expect(page.FindByButton("Sign in").Click()).To(Succeed())
Eventually(page.FindByButton("Authorize").Click())
Eventually(page).Should(HaveURL(u.testEnvVars.Hostname + "/#/dashboard"))
}
示例4: TestSpec
func TestSpec(t *testing.T) {
Convey("UserRegister", t, func() {
var agoutiDriver *agouti.WebDriver
var page *agouti.Page
session, _ := mgo.Dial("localhost")
session.DB("TESTGoNuts").DropDatabase()
agoutiDriver = agouti.PhantomJS()
So(agoutiDriver.Start(), ShouldBeNil)
log.Println("Starting")
go StartMyApp(3232, "TESTGoNuts")
var err error
page, err = agoutiDriver.NewPage(agouti.Browser("chrome"))
So(err, ShouldBeNil)
Convey("User Registration page", func() {
Convey("when the user registration is reached", func() {
Convey("should see the page", func() {
So(page.Navigate("http://localhost:3232"), ShouldBeNil)
url, _ := page.URL()
So(url, ShouldEqual, "http://localhost:3232/")
})
})
})
Reset(func() {
So(page.Destroy(), ShouldBeNil)
So(agoutiDriver.Stop(), ShouldBeNil)
})
})
}
示例5:
// Start a test server
server, testEnvVars = startServer()
// Create a fresh page to navigate.
page = createPage()
// Reset page
resetPage(page, testEnvVars)
// Create user
user = StartUserSessionWith(testEnvVars)
})
It("should show the login form if accessing privileged dashboard page without first logining in.", func() {
By("redirecting the user to the login form", func() {
Expect(page.Navigate(testEnvVars.Hostname + "/#/")).To(Succeed())
Expect(page.Find(".test-login")).Should(BeVisible())
})
})
It("should manage user authentication", func() {
By("directing the user to a landing page", func() {
Expect(page.Navigate(testEnvVars.Hostname)).To(Succeed())
})
By("allowing the user to click the login button and redirected to fill out the login form and submit it", func() {
user.LoginTo(page)
})
By("allowing the user to log out", func() {
示例6: 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"))
})
//.........这里部分代码省略.........
示例7: resetPage
func resetPage(page *agouti.Page, testEnvVars AcceptanceTestEnvVars) {
page.Navigate(testEnvVars.Hostname + "/v2/logout")
page.Navigate(testEnvVars.Hostname)
}
示例8: 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() {
//.........这里部分代码省略.........
示例9: 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"))
})
//.........这里部分代码省略.........
示例10:
Expect(page.Destroy()).To(Succeed())
})
Context("when dev is enabled", func() {
BeforeEach(func() {
args = append(args, fmt.Sprintf("-httpPort=%d", httpPort))
args = append(args, "-dev")
})
It("does not redirect to /login", func() {
session = startMainWithArgs(args...)
Eventually(session).Should(gbytes.Say("garagepi started"))
url := fmt.Sprintf("http://localhost:%d/", httpPort)
Expect(page.Navigate(url)).To(Succeed())
Expect(page).Should(HaveURL(url))
})
})
Context("when dev is disabled and username/password are provided", func() {
Describe("logging in", func() {
const (
username = "some-user"
password = "8eEd3g4vf0"
)
var (
expectedLoginURL string
expectedHomepageURL string
)
示例11:
var _ = Describe("UserLogin", func() {
var page *agouti.Page
BeforeEach(func() {
var err error
page, err = agoutiDriver.NewPage()
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(page.Destroy()).To(Succeed())
})
It("should manage user authentication", func() {
By("redirecting the user to the login form from the webapp page", func() {
Expect(page.Navigate(AcceptanceSettings("webappUrl"))).To(Succeed())
})
By("allowing the user to fill out the login form and submit it", func() {
Eventually(page.FindByName("email")).Should(BeFound())
Expect(page.FindByName("email").Fill(AcceptanceSettings("email"))).To(Succeed())
Expect(page.FindByName("password").Fill(AcceptanceSettings("password"))).To(Succeed())
Expect(page.FirstByButton("Get Access").Submit()).To(Succeed())
})
By("allowing the user to view its data", func() {
Eventually(page.Find("#user-context")).Should(BeFound())
Expect(page.Find("#user-context").Click()).To(Succeed())
Expect(page.Find(".user-submenu")).To(BeVisible())
Expect(page.Find(".user-submenu .submenu-data p").Text()).To(Equal("Signed in as\nAcceptance Tests"))
})
示例12:
By("saving the job using the service", func() {
jobService.SaveStub = func(job *jobs.Job) error {
defer GinkgoRecover()
Expect(job.Name).To(Equal("Alice"))
Expect(job.Command).To(Equal("bork bork"))
Expect(job.DockerImage).To(Equal("user/image:tag"))
Expect(job.GitRepository).To(Equal("some-repo.git"))
job.ID = "some-id"
return nil
}
jobService.RunJobReturns(4, nil)
jobService.FindBuildReturns(build, nil)
Expect(page.Navigate(fmt.Sprintf("%s/jobs/new", server.URL))).To(Succeed())
pageobjects.NewNewJobPage(page).CreateJob("Alice", "bork bork", "user/image:tag", "some-repo.git")
Expect(jobService.SaveCallCount()).To(Equal(1))
})
By("redirecting to the build output page", func() {
Eventually(page).Should(HaveURL(fmt.Sprintf("%s/jobs/some-id/builds/4", server.URL)))
})
By("running job", func() {
Eventually(page.Find("#jobOutput")).Should(HaveText("boom!"))
Eventually(page.Find("#jobResult")).Should(HaveText("Success"))
Expect(jobService.RunJobCallCount()).To(Equal(1))
Expect(jobService.RunJobArgsForCall(0)).To(Equal("some-id"))
示例13:
By("having the active tab set to default space users", func() {
Eventually(page.First(".test-subnav-users")).Should(BeVisible())
Expect(page.First(".test-subnav-users .active").Text()).To(Equal("Current space users"))
})
By("seeing a user list for spaces on the first page by default", func() {
Eventually(page.First("table")).Should(BeFound())
Eventually(page.First("table tbody tr")).Should(BeFound())
})
})
It("should allow a org manager to see a list of users for an org", func() {
By("allowing the user to navigate to the space users page", func() {
Expect(page.Navigate(fmt.Sprintf(testEnvVars.Hostname+
"/#/org/%s/spaces/%s/users",
testOrg, testSpace))).To(Succeed())
})
By("allowing the user to navigate to the all org users page", func() {
var orgUsersLink = page.FindByLink("All organization users")
Eventually(orgUsersLink).Should(BeFound())
Expect(orgUsersLink.Click()).To(Succeed())
})
By("seeing a user list for the whole org", func() {
var table = page.First("table")
Eventually(table).Should(BeFound())
var rows = table.First("tbody tr")
Eventually(rows).Should(BeFound())
Expect(rows.Count()).Should(BeNumerically(">=", 1))
示例14:
})
Context("with more then 100 job builds", func() {
var testBuilds []db.Build
BeforeEach(func() {
for i := 1; i < 103; i++ {
build, err := pipelineDB.CreateJobBuild("job-name")
Expect(err).NotTo(HaveOccurred())
testBuilds = append(testBuilds, build)
}
})
It("can have paginated results", func() {
// homepage -> job detail w/build info
Expect(page.Navigate(homepage())).To(Succeed())
// we will need to authenticate later to prove it is working for our page
Authenticate(page, "admin", "password")
Eventually(page.FindByLink("job-name")).Should(BeFound())
Expect(page.FindByLink("job-name").Click()).To(Succeed())
Eventually(page.All("#builds li").Count).Should(Equal(103))
// job detail w/build info -> job detail
Eventually(page.Find("h1 a")).Should(BeFound())
Expect(page.Find("h1 a").Click()).To(Succeed())
Eventually(page).Should(HaveURL(withPath("jobs/job-name")))
Eventually(page.All(".js-build").Count).Should(Equal(100))
Expect(page.First(".pagination .disabled .fa-arrow-left")).Should(BeFound())
Expect(page.First(".pagination .fa-arrow-right").Click()).To(Succeed())
示例15:
Expect(err).NotTo(HaveOccurred())
sqlDB.SaveBuildEvent(build.ID, event.Log{
Origin: event.Origin{
Source: event.OriginSourceStdout,
ID: "some-id",
},
Payload: "hello this is a payload",
})
Expect(sqlDB.FinishBuild(build.ID, db.StatusSucceeded)).To(Succeed())
})
It("can view the resource", func() {
// homepage -> job detail w/build info
Expect(page.Navigate(homepage())).To(Succeed())
// we will need to authenticate later to prove it is working for our page
Authenticate(page, "admin", "password")
Eventually(page.FindByLink("job-name")).Should(BeFound())
Expect(page.FindByLink("job-name").Click()).To(Succeed())
// job detail w/build info -> job detail
Eventually(page).Should(HaveURL(withPath(fmt.Sprintf("jobs/job-name/builds/%d", build.ID))))
Eventually(page.Find("h1")).Should(HaveText(fmt.Sprintf("job-name #%d", build.ID)))
Expect(page.Find("h1 a").Click()).To(Succeed())
Eventually(page).Should(HaveURL(withPath("jobs/job-name")))
// job-detail pausing
Eventually(page.Find("#job-state.btn-pause")).Should(BeFound())
Expect(page.Find("#job-state.btn-pause").Click()).To(Succeed())
Eventually(page.Find("#job-state.btn-pause.enabled")).Should(BeFound())