Beispiel #1
0
func webDriver() {
	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, err = selenium.NewRemote(caps, "")
	if err != nil {
		errors.New("Unable to intialize wd.")
	}
}
Beispiel #2
0
// setup sets up a clean browser session.
func setup(t *testing.T) *Browser {
	if wd == nil {
		executor := "http://*****:*****@ondemand.saucelabs.com/wd/hub",
				os.Getenv("SAUCE_USERNAME"),
				os.Getenv("SAUCE_ACCESS_KEY"),
			)
		}
		var err error
		wd, err = selenium.NewRemote(caps, executor)
		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)
		}
	}
	b := &Browser{wd}
	if err := b.Go(appURL); err != nil {
		t.Fatal("Could not visit homepage: ", err)
	}
	return b
}
Beispiel #3
0
func (t *InterfaceTest) TestMain() {
	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, _ := selenium.NewRemote(caps, "")
	defer wd.Quit()

	wd.Get("http://localhost:9000")

}
Beispiel #4
0
func main() {
	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, _ := selenium.NewRemote(caps, "")
	defer wd.Quit()

	// Get simple playground interface
	wd.Get("http://play.golang.org/?simple=1")
}
Beispiel #5
0
func newRemote(browser string) (selenium.WebDriver, func(), error) {
	caps := selenium.Capabilities{
		"browserName":    browser,
		"acceptSslCerts": true,
	}
	if *webdriverProxy != "" {
		proxy := make(map[string]string)
		proxy["proxyType"] = "MANUAL"
		proxy["httpProxy"] = *webdriverProxy
		proxy["sslProxy"] = *webdriverProxy
		caps["proxy"] = proxy
	}

	remoteUrl := *webdriverRemoteUrl
	var internalChromeServer *chromedriver.Server
	if *internalChromeMode {
		var err error
		internalChromeServer, err = chromedriver.Start()
		if err != nil {
			return nil, nil, fmt.Errorf(
				"Error starting internal chrome driver: %s", err)
		}
		remoteUrl = internalChromeServer.URL()
	}

	wd, err := selenium.NewRemote(caps, remoteUrl)
	if err != nil {
		return nil, nil, fmt.Errorf(
			"Can't start session %s for browser %s", err, browser)
	}
	err = wd.SetAsyncScriptTimeout(*webdriverAsyncScriptTimeout)
	if err != nil {
		return nil, nil, fmt.Errorf("Can't set async script timeout %s", err)
	}
	err = wd.SetImplicitWaitTimeout(*webdriverImplicitWaitTimeout)
	if err != nil {
		return nil, nil, fmt.Errorf("Can't set implicit wait timeout %s", err)
	}

	quit := func() {
		if *webdriverQuit {
			wd.Quit()
			if internalChromeServer != nil {
				internalChromeServer.StopOrFatal()
			}
		}
	}

	return wd, quit, nil
}
Beispiel #6
0
func make_webdriver() selenium.WebDriver {
	var (
		webdriver selenium.WebDriver
		err       error
	)
	caps := selenium.Capabilities(wd.MakeChromeCapabilities("Windows"))

	webdriver, err = selenium.NewRemote(caps, env.web_driver)
	panic_error(err)

	webdriver.SetAsyncScriptTimeout(time.Duration(env.timeout) * time.Millisecond)
	webdriver.SetImplicitWaitTimeout(time.Millisecond * time.Duration(env.timeout))
	return webdriver
}
func TestTrafficOpsLogin(t *testing.T) {
	env, err := environment.Get(environment.DefaultPath)
	if err != nil {
		t.Fatalf("Failed to get environment: %v\n", err)
	}

	caps := selenium.Capabilities{"browserName": "firefox"}
	wd, err := selenium.NewRemote(caps, "")
	if err != nil {
		t.Fatalf("Error creating selenium Remote: %v\n", err)
	}
	defer wd.Quit()

	if err := wd.Get(env.TrafficOps.URI); err != nil {
		t.Fatalf("Error getting URI: %v\n", err)
	}

	elem, err := wd.FindElement(selenium.ByID, "u")
	if err != nil {
		t.Fatalf("Error finding element: %v\n", err)
	}
	elem.Clear()
	elem.SendKeys(env.TrafficOps.User)

	elem, err = wd.FindElement(selenium.ByID, "p")
	if err != nil {
		t.Fatalf("Error Finding element: %v\n", err)
	}

	elem.Clear()
	elem.SendKeys(env.TrafficOps.Password)

	btn, _ := wd.FindElement(selenium.ByID, "login_button")
	if err != nil {
		t.Fatalf("Error Finding element: %v\n", err)
	}
	btn.Click()

	loadingDiv, err := wd.FindElement(selenium.ByID, "utcclock")
	if err != nil {
		t.Fatalf("Error finding Element: %v\n", err)
	}
	for {
		if output, err := loadingDiv.Text(); err != nil {
			t.Fatalf("Error getting output: %v\n", err)
		} else if output != "loading..." {
			break
		}
		time.Sleep(time.Millisecond * 100)
	}

	div, err := wd.FindElement(selenium.ByClassName, "dataTables_scroll")
	if err != nil {
		t.Fatalf("Error finding Element: %v\n", err)
	}

	//	txt, err := div.Text()
	_, err = div.Text()
	if err != nil {
		t.Fatalf("Error getting Text: %v\n", err)
	}
	//	fmt.Printf("Got: %s\n", txt)
}