<commit_before>package selenium

import (
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"net/http"

	"strings"
	"testing"
)

var caps = Capabilities{
	"browserName": "firefox",
}

type sauceCfg struct {
	User string
	Key  string
}

var serverPort = ":4793"
var serverURL = "http://localhost" + serverPort + "/"

var runOnSauce *bool = flag.Bool("saucelabs", false, "run on sauce")

func readSauce() (*sauceCfg, error) {
	data, err := ioutil.ReadFile("sauce.json")
	if err != nil {
		message := fmt.Sprintf("can't open sauce.json - %s\n", err)
		return nil, errors.New(message)
	}
	cfg := &sauceCfg{}
	if err = json.Unmarshal(data, cfg); err != nil {
		return nil, errors.New(fmt.Sprintf("bad JSON- %s\n", err))
	}

	return cfg, nil
}

func newRemote(testName string, t *testing.T) WebDriver {
	executor := ""
	// FIXME: Since we use internal http server, we can use SauceLabs ...
	//if *runOnSauce {
	if false {
		cfg, err := readSauce()
		if err != nil {
			t.Fatalf("can't read sauce config - %s", err)
		}
		caps["name"] = testName // SauceLabs
		urlTemplate := "http://%s:%s@ondemand.saucelabs.com:80/wd/hub"
		executor = fmt.Sprintf(urlTemplate, cfg.User, cfg.Key)
	}
	wd, err := NewRemote(caps, executor)
	if err != nil {
		t.Fatalf("can't start session - %s", err)
	}

	return wd
}

func TestStatus(t *testing.T) {
	wd := newRemote("TestStatus", t)
	defer wd.Quit()

	status, err := wd.Status()
	if err != nil {
		t.Fatal(err)
	}

	if len(status.OS.Name) == 0 {
		t.Fatal("No OS")
	}
}

func TestNewSession(t *testing.T) {
	if *runOnSauce {
		return
	}
	wd := &remoteWD{capabilities: caps, executor: DEFAULT_EXECUTOR}
	sid, err := wd.NewSession()
	defer wd.Quit()

	if err != nil {
		t.Fatalf("error in new session - %s", err)
	}

	if len(sid) == 0 {
		t.Fatal("Empty session id")
	}

	if wd.id != sid {
		t.Fatal("Session id mismatch")
	}
}

func TestCapabilities(t *testing.T) {
	wd := newRemote("TestCapabilities", t)
	defer wd.Quit()

	c, err := wd.Capabilities()
	if err != nil {
		t.Fatal(err)
	}

	if c["browserName"] != caps["browserName"] {
		t.Fatalf("bad browser name - %s", c["browserName"])
	}
}

func TestSetAsyncScriptTimeout(t *testing.T) {
	wd := newRemote("TestSetAsyncScriptTimeout", t)
	defer wd.Quit()

	err := wd.SetAsyncScriptTimeout(200)
	if err != nil {
		t.Fatal(err)
	}
}

func TestSetImplicitWaitTimeout(t *testing.T) {
	wd := newRemote("TestSetImplicitWaitTimeout", t)
	defer wd.Quit()

	err := wd.SetImplicitWaitTimeout(200)
	if err != nil {
		t.Fatal(err)
	}
}
<commit_msg>Remove (dead) Sauce code and brower flag<commit_after>package selenium

import (
	"flag"
	"fmt"
	"net/http"
	"strings"
	"testing"
)

var serverPort = ":4793"
var serverURL = "http://localhost" + serverPort + "/"
var browserName = *flag.String("browser", "firefox", "browser to use [firefox]")

func getCaps() Capabilities {
	return Capabilities{
		"browserName": browserName,
	}
}

func newRemote(testName string, t *testing.T) WebDriver {
	executor := ""
	wd, err := NewRemote(getCaps(), executor)
	if err != nil {
		t.Fatalf("can't start session - %s", err)
	}

	return wd
}

func TestStatus(t *testing.T) {
	wd := newRemote("TestStatus", t)
	defer wd.Quit()

	status, err := wd.Status()
	if err != nil {
		t.Fatal(err)
	}

	if len(status.OS.Name) == 0 {
		t.Fatal("No OS")
	}
}

func TestNewSession(t *testing.T) {
	wd := &remoteWD{capabilities: getCaps(), executor: DEFAULT_EXECUTOR}
	sid, err := wd.NewSession()
	defer wd.Quit()

	if err != nil {
		t.Fatalf("error in new session - %s", err)
	}

	if len(sid) == 0 {
		t.Fatal("Empty session id")
	}

	if wd.id != sid {
		t.Fatal("Session id mismatch")
	}
}

func TestCapabilities(t *testing.T) {
	wd := newRemote("TestCapabilities", t)
	defer wd.Quit()

	c, err := wd.Capabilities()
	if err != nil {
		t.Fatal(err)
	}

	browser := getCaps()["browserName"]

	if c["browserName"] != browser {
		t.Fatalf("bad browser name - %s (should be %s)", c["browserName"], browser)
	}
}

func TestSetAsyncScriptTimeout(t *testing.T) {
	wd := newRemote("TestSetAsyncScriptTimeout", t)
	defer wd.Quit()

	err := wd.SetAsyncScriptTimeout(200)
	if err != nil {
		t.Fatal(err)
	}
}

func TestSetImplicitWaitTimeout(t *testing.T) {
	wd := newRemote("TestSetImplicitWaitTimeout", t)
	defer wd.Quit()

	err := wd.SetImplicitWaitTimeout(200)
	if err != nil {
		t.Fatal(err)
	}
}

{'fraction_non_alphanumeric': 0.1700900069236095, 'fraction_numerical': 0.006000461573967228, 'mean_word_length': 3.7995570321151715, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5776938', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1710, 'n_words': 407}