Skip to content

Instantly share code, notes, and snippets.

@nvcnvn
Created June 12, 2015 05:10
Show Gist options
  • Save nvcnvn/9c788a62cfd457d36113 to your computer and use it in GitHub Desktop.
Save nvcnvn/9c788a62cfd457d36113 to your computer and use it in GitHub Desktop.
A slow test
package main
import (
"net/http"
"time"
)
func main() {
http.HandleFunc("/a", pageA)
http.HandleFunc("/b", pageB)
http.HandleFunc("/c", pageC)
http.HandleFunc("/d", pageD)
http.HandleFunc("/e", pageE)
http.ListenAndServe(":8080", nil)
}
func pageA(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`<html>
<a id="link" href="/b">link</a>
</html>`))
}
func pageB(rw http.ResponseWriter, req *http.Request) {
time.Sleep(5 * time.Second)
http.Redirect(rw, req, "/c", 302)
}
func pageC(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`<html>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
var Api = function() {
this.call = function(e, t, n, r, i, s, o) {
var u = {};
if (typeof e == "object") {
u = e;
typeof u.data == "undefined" && (u.data = {});
typeof u.success == "undefined" && (u.success = function() {});
typeof u.error == "undefined" && (u.error = function() {});
typeof u.action == "undefined" && (u.action = "GET");
typeof u.async == "undefined" && (u.async = !0)
} else {
u.data = typeof n == "undefined" ? {} : n;
u.success = typeof r == "undefined" ? function() {} : r;
u.error = typeof i == "undefined" ? function() {} : i;
u.action = typeof s == "undefined" ? "GET" : s;
u.async = typeof o == "undefined" ? !0 : o
}
$.ajax({
url: "/d",
data: u.data,
dataType: "json",
success: u.success,
error: u.error,
type: u.action,
async: u.async
})
}
}
var api = new Api();
startLoading()
function startLoading() {
var _call = {
'success' : finishLoading,
'error' : finishLoading,
'data' : { id : 14826 }
};
api.call( _call );
}
function finishLoading() {
window.location = '/e';
}
$(function() {
setTimeout( startLoading, 500 );
setTimeout( startLoading, 1000 );
setTimeout( startLoading, 1500 );
});
</script>
<body>
</body>
</html>`))
}
func pageD(rw http.ResponseWriter, req *http.Request) {
time.Sleep(2 * time.Minute)
}
func pageE(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("ok"))
}
package main_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/sclevine/agouti"
"time"
"github.com/onsi/ginkgo/reporters"
"testing"
)
func TestMain(t *testing.T) {
RegisterFailHandler(Fail)
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Old Internavenue Suite", []Reporter{junitReporter})
}
var agoutiDriver *WebDriver
var page *Page
var _ = BeforeSuite(func() {
agoutiDriver = PhantomJS()
Expect(agoutiDriver.Start()).To(Succeed())
page = setupPage()
})
var _ = AfterSuite(func() {
page.Destroy()
agoutiDriver.Stop()
})
func setupPage() *Page {
page, err := agoutiDriver.NewPage()
Expect(err).NotTo(HaveOccurred())
Expect(page.ClearCookies()).To(Succeed())
Expect(page.Size(1366, 7680)).To(Succeed())
return page
}
var _ = Describe("ClickFlow", func() {
It("should redirect to page e after click", func() {
Expect(page.Navigate("http://localhost:8080/a")).To(Succeed())
t1 := time.Now()
Expect(page.Find("#link").Click()).To(Succeed())
fmt.Fprintln(GinkgoWriter, "time take to click succeed", time.Now().Sub(t1))
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment