예제 #1
0
파일: selenium.go 프로젝트: jasocox/goblog
func main() {
	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, err := selenium.NewRemote(caps, "")

	if err != nil {
		log.Println("Failed to start selenium:", err.Error())
		os.Exit(1)
	}

	defer wd.Quit()

	wd.Get("http://play.golang.org/?simple=1")
}
예제 #2
0
파일: app.go 프로젝트: ncaio/thirdeye
func click(url string) string {
	caps := selenium.Capabilities{
		"browserName": "firefox",
	}
	wd, _ := selenium.NewRemote(caps, "")
	defer wd.Quit()
	wd.Get(url)
	img, _ := wd.Screenshot()
	ioutil.WriteFile("/go/src/thirdeye/public/img/screen.png", img, 0x755)
	//
	//
	//
	filename := "screen.png"
	return filename
}
예제 #3
0
// setup sets up a clean browser session.
func setup(t *testing.T) *Browser {
	if wd == nil {
		caps := selenium.Capabilities{"browserName": "chrome"}
		var err error
		wd, err = selenium.NewRemote(caps, "http://localhost:9515")
		if err != nil {
			t.Fatal("Could not get new remote: ", err)
		}
		if err := wd.SetImplicitWaitTimeout(5 * time.Second); err != nil {
			t.Fatal("Could not set implicit wait timeout: ", err)
		}
		if err != nil {
			t.Fatal("Could not setup selenium remote: ", err)
		}
	} else {
		if err := wd.DeleteAllCookies(); err != nil {
			t.Fatal("Could not delete cookies: ", err)
		}
	}
	return &Browser{wd}
}
예제 #4
0
파일: tests.go 프로젝트: ohtufox/isa
func runTests() error {
	var failed bool

	log.Println("Starting firefox driver")
	// FireFox driver
	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, err := selenium.NewRemote(caps, "")
	if err != nil {
		return err
	}
	defer wd.Quit()

	log.Println("Running tests..")
	for _, test := range tests {
		start := time.Now()

		wd.Get(pathTo(test))
		log.Printf(test)

		// Get the result
		div, err := wd.FindElement(selenium.ByCSSSelector, "#qunit-testresult")
		if err != nil {
			return err
		}

		output := ""
		// Wait for run to finish
		for {
			output, err = div.Text()
			if err != nil {
				return err
			}

			if strings.HasPrefix(output, "Tests completed") {
				if strings.HasSuffix(output, "0 failed.") {
					break
				}
				resultfields, _ := wd.FindElements(selenium.ByCSSSelector, "li.fail")
				for _, field := range resultfields {
					failed = true
					contents, _ := field.Text()
					if len(contents) > 0 {
						// Remove some useless trailing info
						log.Println(strings.Split(contents, "Rerun")[0])
					}
				}
				log.Printf("\n%s\n", output)
			}

			if time.Since(start) > time.Second*10 {
				return errors.New("Tests took more than 10 seconds")
			}

			time.Sleep(time.Millisecond * 100)
		}

	}
	if failed {
		return errors.New("Tests failed")
	}

	return nil
}