コード例 #1
0
func findLatestVersion() (string, error) {
	downloadLink := "http://docs.seleniumhq.org/download/"
	tmp := os.TempDir()
	err := common.Download(downloadLink, tmp)
	if err != nil {
		return "", errors.New(fmt.Sprintf("Failed to download %s\n", downloadLink))
	}
	downloadedFileContents := common.ReadFileContents(filepath.Join(tmp, "download"))
	seleniumDownloadLinkPattern := regexp.MustCompile("http://selenium-release.storage.googleapis.com/.*/selenium-server-standalone-.*.jar")
	latestVersion := strings.Split((seleniumDownloadLinkPattern.FindString(downloadedFileContents)), "-")
	seleniumVersion := strings.Split((latestVersion[len(latestVersion)-1]), ".jar")[0]
	return seleniumVersion, nil
}
コード例 #2
0
func setupJavaVersion(versionParts []string) {
	downloadLink := fmt.Sprintf("http://selenium-release.storage.googleapis.com/%s.%s/selenium-server-standalone-%s.%s.%s.jar",
		versionParts[0], versionParts[1], versionParts[0], versionParts[1], versionParts[2])
	if !common.DirExists("libs") {
		err := os.Mkdir("libs", common.NewDirectoryPermissions)
		if err != nil {
			fmt.Printf("Failed to create libs directory. %s\n", err.Error())
			os.Exit(1)
		}
	}
	absLibs, _ := filepath.Abs("libs")
	err := common.Download(downloadLink, absLibs)
	if err != nil {
		fmt.Printf("Failed to download %s. %s\n", downloadLink, err.Error())
		os.Exit(1)
	}

	// Copies Files WebdriverBrowserFactory.java && WebdriverHooks.java into project src
	pluginsPath, err := common.GetPluginsPath()
	if err != nil {
		fmt.Printf("Could not find plugins path")
		os.Exit(1)
	}
	javaPluginsPath := filepath.Join(pluginsPath, "selenium-webdriver", "0.0.0", "skel", "java")
	projectRoot, err := common.GetProjectRoot()
	if err != nil {
		fmt.Printf("failed to get Project Source")
		os.Exit(1)
	}
	projectSrc := filepath.Join(projectRoot, "src")
	err = common.CopyFile(filepath.Join(javaPluginsPath, WebdriverBrowserFactory), filepath.Join(projectSrc, WebdriverBrowserFactory))
	if err != nil {
		fmt.Printf("failed to Copy File %s ", WebdriverBrowserFactory)
		os.Exit(1)
	}
	err = common.CopyFile(filepath.Join(javaPluginsPath, WebdriverHooks), filepath.Join(projectSrc, WebdriverHooks))
	if err != nil {
		fmt.Printf("failed to Copy File %s ", WebdriverHooks)
		os.Exit(1)
	}
	projectEnv := filepath.Join(projectRoot, "env", "default")
	err = common.CopyFile(filepath.Join(javaPluginsPath, WebdriverPropertiesFile), filepath.Join(projectEnv, WebdriverPropertiesFile))
	if err != nil {
		fmt.Printf("failed to Copy File %s ", WebdriverPropertiesFile)
		os.Exit(1)
	}
}