Ejemplo n.º 1
0
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")
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 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}
}
Ejemplo n.º 4
0
Archivo: tests.go Proyecto: 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
}