[
  {
    "path": ".gitignore",
    "content": "# Compiled Object files, Static and Dynamic libs (Shared Objects)\n*.o\n*.a\n*.so\n\n# Folders\n_obj\n_test\n\n# Architecture specific extensions/prefixes\n*.[568vq]\n[568vq].out\n\n*.cgo1.go\n*.cgo2.c\n_cgo_defun.c\n_cgo_gotypes.go\n_cgo_export.*\n\n_testmain.go\n\n*.exe\n*.test\n*.prof\n*.swp\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: go\ngo:\n    - 1.x\nscript: go test ./*.go -v\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) Bunsen 2016 \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# go-selenium\n\n[![Build Status](https://travis-ci.org/bunsenapp/go-selenium.svg?branch=master)](https://travis-ci.org/bunsenapp/go-selenium)\n[![GoDoc](https://godoc.org/github.com/bunsenapp/go-selenium?status.svg)](https://godoc.org/github.com/bunsenapp/go-selenium)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bunsenapp/go-selenium)](https://goreportcard.com/report/github.com/bunsenapp/go-selenium)\n\n## Maintainer Required\n\nThis package is no longer maintained. The author no longer writes automated tests with Selenium, and will only fix this package should there be a major security issue.\n\nIf you or someone you know is interested in maintaining this package, please raise an issue and tag me (@elsyms) in it.\n\n## Introduction\n\nYes, yet another Selenium Web Driver library has been brought to the table. This one, however, is slightly different. \n\n* Easy to understand.\n* Full test coverage by unit tests and integration tests.\n* Excellent support; we use this in our main project so if you find an issue - it'll likely impact us!\n* Idiomatic, structured code with no gimmicks.\n* Simple errors that describe what has happened and why.\n\n## Installation\n\nAs with all Go libraries, go-selenium is easy to install. Simply run the below command:\n\n`go get github.com/bunsenapp/go-selenium`\n\nand then import the library in your project:\n\n`import \"github.com/bunsenapp/go-selenium\"`\n\n## Getting started\n\nPrior to using this library you need to ensure that you have a Selenium instance running (standalone or grid is fine). If you don't know how to do this, there is a small section called 'Getting Selenium running' below.\n\nPlease see the [examples/getting-started/main.go](https://github.com/bunsenapp/go-selenium/blob/master/examples/getting-started/main.go) file.\n\n## Examples\n\nFurther examples, including tests of HackerNews (c), are available within the `examples` directory.\n\n## Documentation\n\nAll documentation is available on the godoc.org website: [https://godoc.org/github.com/bunsenapp/go-selenium](https://godoc.org/github.com/bunsenapp/go-selenium). \n\n## Getting Selenium running\n\n### With Docker\n\n1. Choose an image from the following URL: https://github.com/SeleniumHQ/docker-selenium\n2. Execute the following Docker command replacing the image with your chosen one: `docker run -d -p 4444:4444 --name selenium selenium/standalone-firefox`.\n\n### Without Docker\n\n1. Download the Selenium standalone server from the following URL: http://www.seleniumhq.org/download/\n2. Download the appropriate web driver executable and include it in your path. For Firefox, that will be the Gecko driver. \n3. Run the Selenium server with the following command: `java -jar selenium-server-standalone-3.0.1.jar`.\n"
  },
  {
    "path": "api_service.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\n\t\"errors\"\n)\n\ntype apiServicer interface {\n\tperformRequest(string, string, io.Reader) ([]byte, error)\n}\n\ntype requestError struct {\n\tState string            `json:\"state\"`\n\tValue requestErrorValue `json:\"value\"`\n}\n\nfunc (r requestError) Error() string {\n\treturn fmt.Sprintf(\"Invalid status code returned, message: %v, information: %v\", r.State, r.Value.Message)\n}\n\ntype requestErrorValue struct {\n\tMessage string `json:\"localizedMessage\"`\n}\n\ntype seleniumAPIService struct{}\n\nfunc (a seleniumAPIService) performRequest(url string, method string, body io.Reader) ([]byte, error) {\n\trequest, err := http.NewRequest(method, url, body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclient := http.Client{}\n\tresp, err := client.Do(request)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: an unexpected communication failure occurred, error: %s\", method, err.Error())\n\t}\n\n\tdefer resp.Body.Close()\n\n\tvar buf bytes.Buffer\n\tbuf.ReadFrom(resp.Body)\n\tr := buf.Bytes()\n\n\tif resp.StatusCode != 200 {\n\t\tvar reqErr requestError\n\t\tvar errStr string\n\n\t\terr := json.Unmarshal(r, &reqErr)\n\t\tif err == nil {\n\t\t\treturn nil, &reqErr\n\t\t}\n\n\t\terrStr = fmt.Sprintf(\"Status code %v returned with no body\", resp.StatusCode)\n\t\treturn nil, errors.New(errStr)\n\t}\n\n\treturn r, nil\n}\n"
  },
  {
    "path": "capabilities.go",
    "content": "package goselenium\n\nimport \"encoding/json\"\n\n// Browser defines a supported selenium enabled browser.\ntype Browser interface {\n\tBrowserName() string\n}\n\n// Browser represents a browser to run within Selenium.\ntype browser struct {\n\tbrowserName string\n}\n\n// BrowserName returns the browser name assigned to the current browser object.\nfunc (b browser) BrowserName() string {\n\treturn b.browserName\n}\n\n// FirefoxBrowser returns a Firefox browser object.\nfunc FirefoxBrowser() Browser {\n\treturn browser{\"firefox\"}\n}\n\n// ChromeBrowser returns a Chrome browser object.\nfunc ChromeBrowser() Browser {\n\treturn browser{\"chrome\"}\n}\n\n// AndroidBrowser returns an Android browser object.\nfunc AndroidBrowser() Browser {\n\treturn browser{\"android\"}\n}\n\n// HTMLUnitBrowser returns a HTMLUnit browser object.\nfunc HTMLUnitBrowser() Browser {\n\treturn browser{\"htmlunit\"}\n}\n\n// InternetExplorerBrowser returns an IE browser object.\nfunc InternetExplorerBrowser() Browser {\n\treturn browser{\"internetexplorer\"}\n}\n\n// IPhoneBrowser returns an IPhone browser object.\nfunc IPhoneBrowser() Browser {\n\treturn browser{\"iphone\"}\n}\n\n// IPadBrowser returns an IPad browser object.\nfunc IPadBrowser() Browser {\n\treturn browser{\"ipad\"}\n}\n\n// OperaBrowser returns an Opera browser object.\nfunc OperaBrowser() Browser {\n\treturn browser{\"opera\"}\n}\n\n// SafariBrowser returns a Safari browser object.\nfunc SafariBrowser() Browser {\n\treturn browser{\"safari\"}\n}\n\n// Capabilities represents the capabilities defined in the W3C specification.\n// The main capability is the browser, which can be set by calling one of the\n// \\wBrowser\\(\\) methods.\ntype Capabilities struct {\n\tbrowser Browser\n}\n\n// Browser yields the browser capability assigned to the current Capabilities\n// object..\nfunc (c *Capabilities) Browser() Browser {\n\tif c.browser != nil {\n\t\treturn c.browser\n\t}\n\n\treturn browser{}\n}\n\n// SetBrowser sets the browser capability to be one of the allowed browsers.\nfunc (c *Capabilities) SetBrowser(b Browser) {\n\tc.browser = b\n}\n\nfunc (c *Capabilities) toJSON() (string, error) {\n\tcapabilities := map[string]map[string]interface{}{\n\t\t\"desiredCapabilities\": {\n\t\t\t\"browserName\": c.browser.BrowserName(),\n\t\t},\n\t}\n\n\tcapabilitiesJSON, err := json.Marshal(capabilities)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn string(capabilitiesJSON), nil\n}\n"
  },
  {
    "path": "doc.go",
    "content": "// Package goselenium is a Selenium web driver library written in Go.\npackage goselenium\n"
  },
  {
    "path": "errors.go",
    "content": "package goselenium\n\nimport \"fmt\"\n\n// ErrorResponse is what is returned from the Selenium API when an error\n// occurs.\ntype ErrorResponse struct {\n\tMessage string\n\tState   string\n}\n\n// CommunicationError is the result of a communication failure between\n// this library and the WebDriver API.\ntype CommunicationError struct {\n\turl      string\n\tResponse *ErrorResponse\n\tmethod   string\n}\n\n// Error returns a formatted communication error string.\nfunc (c CommunicationError) Error() string {\n\treturn fmt.Sprintf(\"%s: api error, url: %s, err: %+v\", c.method, c.url, c.Response)\n}\n\n// IsCommunicationError checks whether an error is a selenium communication\n// error.\nfunc IsCommunicationError(err error) bool {\n\t_, ok := err.(CommunicationError)\n\treturn ok\n}\n\nfunc newCommunicationError(err error, method string, url string, resp []byte) CommunicationError {\n\tvar convertedResponse ErrorResponse\n\n\treqErr, ok := err.(*requestError)\n\tif ok {\n\t\tconvertedResponse = ErrorResponse{\n\t\t\tMessage: reqErr.Value.Message,\n\t\t\tState:   reqErr.State,\n\t\t}\n\t}\n\n\treturn CommunicationError{\n\t\turl:      url,\n\t\tResponse: &convertedResponse,\n\t\tmethod:   method,\n\t}\n}\n\n// UnmarshallingError is the result of an unmarshalling failure of a JSON\n// string.\ntype UnmarshallingError struct {\n\terr    error\n\tjson   string\n\tmethod string\n}\n\n// Error returns a formatted unmarshalling error string.\nfunc (u UnmarshallingError) Error() string {\n\treturn fmt.Sprintf(\"%s: unmarshalling error, json: %s, err: %s\", u.method, u.json, u.err)\n}\n\n// IsUnmarshallingError checks whether an error is a selenium unmarshalling\n// error.\nfunc IsUnmarshallingError(err error) bool {\n\t_, ok := err.(UnmarshallingError)\n\treturn ok\n}\n\nfunc newUnmarshallingError(err error, method string, json string) UnmarshallingError {\n\treturn UnmarshallingError{\n\t\terr:    err,\n\t\tjson:   json,\n\t\tmethod: method,\n\t}\n}\n\n// MarshallingError is an error that is returned when a json.Marshal error occurs.\ntype MarshallingError struct {\n\terr    error\n\tobject interface{}\n\tmethod string\n}\n\n// Error returns a formatted marshalling error string.\nfunc (m MarshallingError) Error() string {\n\treturn fmt.Sprintf(\"%s: marshalling error for object %+v, err: %s\", m.method, m.object, m.err.Error())\n}\n\n// IsMarshallingError checks whether an error is a marshalling error.\nfunc IsMarshallingError(err error) bool {\n\t_, ok := err.(MarshallingError)\n\treturn ok\n}\n\nfunc newMarshallingError(err error, method string, obj interface{}) MarshallingError {\n\treturn MarshallingError{\n\t\terr:    err,\n\t\tobject: obj,\n\t\tmethod: method,\n\t}\n}\n\n// SessionIDError is an error that is returned when the session id is\n// invalid. This value will contain the method that the session error occurred\n// in.\ntype SessionIDError string\n\n// Error returns a formatted session error string.\nfunc (s SessionIDError) Error() string {\n\treturn fmt.Sprintf(\"%s: session id is invalid (have you created a session yet?)\", string(s))\n}\n\n// IsSessionIDError checks whether an error is due to a session ID not being\n// set.\nfunc IsSessionIDError(err error) bool {\n\t_, ok := err.(SessionIDError)\n\treturn ok\n}\n\nfunc newSessionIDError(method string) SessionIDError {\n\treturn SessionIDError(method)\n}\n\n// InvalidURLError is an error that is returned whenever a URL is not correctly\n// formatted.\ntype InvalidURLError string\n\n// Error returns the formatted invalid error string.\nfunc (i InvalidURLError) Error() string {\n\treturn fmt.Sprintf(\"invalid url: %s\", string(i))\n}\n\n// IsInvalidURLError checks whether an error is due to the URL being incorrectly\n// formatted.\nfunc IsInvalidURLError(err error) bool {\n\t_, ok := err.(InvalidURLError)\n\treturn ok\n}\n\n// InvalidURLError\nfunc newInvalidURLError(url string) InvalidURLError {\n\treturn InvalidURLError(url)\n}\n"
  },
  {
    "path": "errors_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\nfunc communicationError() error {\n\treturn newCommunicationError(errors.New(\":<\"), \"Test\", \"\", nil)\n}\n\nfunc sessionError() error {\n\treturn newSessionIDError(\"Test\")\n}\n\nfunc unmarshallingError() error {\n\treturn newUnmarshallingError(errors.New(\":<\"), \"Test\", \"\")\n}\n\nfunc marshallingError() error {\n\treturn newMarshallingError(errors.New(\":<\"), \"Test\", \"test\")\n}\n\nfunc Test_Errors_CommunicationErrorCanBeCastSuccessfully(t *testing.T) {\n\te := communicationError()\n\n\tback, ok := e.(CommunicationError)\n\tif !ok || back.method != \"Test\" {\n\t\tt.Errorf(\"Could not assert error\")\n\t}\n}\n\nfunc Test_Errors_SessionErrorCanBeCastSuccessfully(t *testing.T) {\n\te := sessionError()\n\n\t_, ok := e.(SessionIDError)\n\tif !ok {\n\t\tt.Errorf(\"Could not assert error\")\n\t}\n}\n\nfunc Test_Errors_UnmarshallingErrorCanBeCastSuccessfully(t *testing.T) {\n\te := unmarshallingError()\n\n\tbody, ok := e.(UnmarshallingError)\n\tif !ok || body.method != \"Test\" {\n\t\tt.Errorf(\"Could not assert error\")\n\t}\n}\n\nfunc Test_Errors_MarshallingErrorCanBeCastSuccessfully(t *testing.T) {\n\te := marshallingError()\n\n\tbody, ok := e.(MarshallingError)\n\tif !ok || body.method != \"Test\" {\n\t\tt.Errorf(\"Could not assert error\")\n\t}\n}\n"
  },
  {
    "path": "examples/error-handling/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc main() {\n\t// Create the capabilities.\n\tcapabilities := goselenium.Capabilities{}\n\tcapabilities.SetBrowser(goselenium.FirefoxBrowser())\n\n\t// Create the driver.\n\tdriver, err := goselenium.NewSeleniumWebDriver(\"http://localhost:4444/wd/hub/\", capabilities)\n\tif err != nil {\n\t\tfmt.Println(\"Error creating web driver.\")\n\t\treturn\n\t}\n\n\t// Create the session.\n\t_, err = driver.CreateSession()\n\tif err != nil {\n\t\tfmt.Println(\"Error creating session.\")\n\t\treturn\n\t}\n\n\t// Navigate to Google.\n\t_, err = driver.Go(\"https://www.google.com\")\n\tif err != nil {\n\t\tfmt.Println(\"An error occurred whilst visiting URL.\")\n\t\treturn\n\t}\n\n\t// Find a non existent element for it to error.\n\t_, err = driver.FindElement(goselenium.ByCSSSelector(\"mynonexistentelement\"))\n\tif err != nil {\n\t\t// Switch the different types of errors. You do not need to do this in\n\t\t// every call and can simply abstract it behind a function. If you\n\t\t// don't want to handle the custom errors, they all implement the\n\t\t// Error interface meaning it'll work anywhere your normal errors do.\n\t\tswitch err.(type) {\n\t\tcase goselenium.CommunicationError:\n\t\t\te := err.(goselenium.CommunicationError)\n\t\t\t// Switch the different states that we want to handle.\n\t\t\tswitch e.Response.State {\n\t\t\tcase goselenium.UnknownError:\n\t\t\t\tfmt.Println(\"An unknown error occurred.\")\n\t\t\tcase goselenium.SessionNotCreated:\n\t\t\t\tfmt.Println(\"The session was not created.\")\n\t\t\tcase goselenium.NoSuchElement:\n\t\t\t\tfmt.Println(\"Failed to find element. Example passed!\")\n\t\t\t}\n\t\tcase goselenium.UnmarshallingError:\n\t\t\tfmt.Println(\"An unmarshalling error occurred :<\")\n\t\t}\n\t}\n\n\t// Delete the session.\n\tdriver.DeleteSession()\n}\n"
  },
  {
    "path": "examples/getting-started/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc main() {\n\t// Create a capabilities object.\n\tcapabilities := goselenium.Capabilities{}\n\n\t// Populate it with the browser you wish to use.\n\tcapabilities.SetBrowser(goselenium.FirefoxBrowser())\n\n\t// Initialise a new web driver.\n\tdriver, err := goselenium.NewSeleniumWebDriver(\"http://localhost:4444/wd/hub\", capabilities)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Create a session.\n\t_, err = driver.CreateSession()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Defer the deletion of the session.\n\tdefer driver.DeleteSession()\n\n\t// Navigate to Google.\n\t_, err = driver.Go(\"https://www.google.com\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\t// Hooray, we navigated to Google!\n\tfmt.Println(\"Successfully navigated to Google!\")\n}\n"
  },
  {
    "path": "examples/hackernews/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc main() {\n\t// Create capabilities, driver etc.\n\tcapabilities := goselenium.Capabilities{}\n\tcapabilities.SetBrowser(goselenium.FirefoxBrowser())\n\n\tdriver, err := goselenium.NewSeleniumWebDriver(\"http://localhost:4444/wd/hub\", capabilities)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t_, err = driver.CreateSession()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Delete the session once this function is completed.\n\tdefer driver.DeleteSession()\n\n\t// Navigate to the HackerNews website.\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Click the 'new' link at the top\n\tel, err := driver.FindElement(goselenium.ByCSSSelector(\"a[href='newest']\"))\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Click the link.\n\t_, err = el.Click()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Wait until the URL has changed with a timeout of 1 second and a check\n\t// interval of 10ms..\n\tnewLink := \"https://news.ycombinator.com/newest\"\n\tok := driver.Wait(goselenium.UntilURLIs(newLink), 1*time.Second, 10*time.Millisecond)\n\tif !ok {\n\t\tfmt.Println(\"Wait timed out :<\")\n\t\treturn\n\t}\n\n\t// Woohoo! We have successfully navigated to a page.\n\tfmt.Println(\"Successfully navigated to URL \" + newLink)\n}\n"
  },
  {
    "path": "remote_driver.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"io\"\n\t\"strings\"\n\n\t\"errors\"\n)\n\n// NewSeleniumWebDriver creates a new instance of a Selenium web driver with a\n// service URL (usually http://domain:port/wd/hub) and a Capabilities object.\n// This method will return validation errors if the Selenium URL is invalid or\n// the required capabilities (BrowserName) are not set.\nfunc NewSeleniumWebDriver(serviceURL string, capabilities Capabilities) (WebDriver, error) {\n\tif serviceURL == \"\" {\n\t\treturn nil, errors.New(\"Provided Selenium URL is invalid\")\n\t}\n\n\turlValid := strings.HasPrefix(serviceURL, \"http://\") || strings.HasPrefix(serviceURL, \"https://\")\n\tif !urlValid {\n\t\treturn nil, errors.New(\"Provided Selenium URL is invalid.\")\n\t}\n\n\tbrowser := capabilities.Browser()\n\thasBrowserCapability := browser.BrowserName() != \"\"\n\tif !hasBrowserCapability {\n\t\treturn nil, errors.New(\"An invalid capabilities object was provided.\")\n\t}\n\n\tif strings.HasSuffix(serviceURL, \"/\") {\n\t\tserviceURL = strings.TrimSuffix(serviceURL, \"/\")\n\t}\n\n\tdriver := &seleniumWebDriver{\n\t\tseleniumURL:  serviceURL,\n\t\tcapabilities: &capabilities,\n\t\tapiService:   &seleniumAPIService{},\n\t}\n\n\treturn driver, nil\n}\n\n// SessionScriptTimeout creates an appropriate Timeout implementation for the\n// script timeout.\nfunc SessionScriptTimeout(to int) Timeout {\n\treturn timeout{\n\t\ttimeoutType: \"script\",\n\t\ttimeout:     to,\n\t}\n}\n\n// SessionPageLoadTimeout creates an appropriate Timeout implementation for the\n// page load timeout.\nfunc SessionPageLoadTimeout(to int) Timeout {\n\treturn timeout{\n\t\ttimeoutType: \"page load\",\n\t\ttimeout:     to,\n\t}\n}\n\n// SessionImplicitWaitTimeout creates an appropriate timeout implementation for the\n// session implicit wait timeout.\nfunc SessionImplicitWaitTimeout(to int) Timeout {\n\treturn timeout{\n\t\ttimeoutType: \"implicit\",\n\t\ttimeout:     to,\n\t}\n}\n\n// ByIndex accepts an integer that represents what the index of an element is\n// and returns the appropriate By implementation.\nfunc ByIndex(index uint) By {\n\treturn by{\n\t\tt:     \"index\",\n\t\tvalue: index,\n\t}\n}\n\n// ByCSSSelector accepts a CSS selector (i.e. ul#id > a) for use in the\n// FindElement(s) functions.\nfunc ByCSSSelector(selector string) By {\n\treturn by{\n\t\tt:     \"css selector\",\n\t\tvalue: selector,\n\t}\n}\n\n// ByLinkText is used to find an anchor element by its innerText.\nfunc ByLinkText(text string) By {\n\treturn by{\n\t\tt:     \"link text\",\n\t\tvalue: text,\n\t}\n}\n\n// ByPartialLinkText works the same way as ByLinkText but performs a search\n// where the link text contains the string passed in instead of a full match.\nfunc ByPartialLinkText(text string) By {\n\treturn by{\n\t\tt:     \"partial link text\",\n\t\tvalue: text,\n\t}\n}\n\n// ByXPath utilises the xpath to find elements (see http://www.guru99.com/xpath-selenium.html).\nfunc ByXPath(path string) By {\n\treturn by{\n\t\tt:     \"xpath\",\n\t\tvalue: path,\n\t}\n}\n\ntype seleniumWebDriver struct {\n\tseleniumURL  string\n\tsessionID    string\n\tcapabilities *Capabilities\n\tapiService   apiServicer\n}\n\nfunc (s *seleniumWebDriver) DriverURL() string {\n\treturn s.seleniumURL\n}\n\nfunc (s *seleniumWebDriver) stateRequest(req *request) (*stateResponse, error) {\n\tvar response stateResponse\n\tvar err error\n\n\tresp, err := s.apiService.performRequest(req.url, req.method, req.body)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, req.callingMethod, req.url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, req.callingMethod, string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) valueRequest(req *request) (*valueResponse, error) {\n\tvar response valueResponse\n\tvar err error\n\n\tresp, err := s.apiService.performRequest(req.url, req.method, req.body)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, req.callingMethod, req.url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, req.callingMethod, string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) elementRequest(req *elRequest) ([]byte, error) {\n\tb := map[string]interface{}{\n\t\t\"using\": req.by.Type(),\n\t\t\"value\": req.by.Value(),\n\t}\n\tbJSON, err := json.Marshal(b)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, req.callingMethod, bJSON)\n\t}\n\n\tbody := bytes.NewReader(bJSON)\n\tresp, err := s.apiService.performRequest(req.url, req.method, body)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, req.callingMethod, req.url, resp)\n\t}\n\n\treturn resp, nil\n}\n\nfunc (s *seleniumWebDriver) scriptRequest(script string, url string, method string) (*ExecuteScriptResponse, error) {\n\tr := map[string]interface{}{\n\t\t\"script\": script,\n\t\t\"args\":   []string{\"\"},\n\t}\n\tb, err := json.Marshal(r)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, method, r)\n\t}\n\tbody := bytes.NewReader(b)\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          body,\n\t\tcallingMethod: method,\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ExecuteScriptResponse{State: resp.State, Response: resp.Value}, nil\n}\n\ntype timeout struct {\n\ttimeoutType string\n\ttimeout     int\n}\n\nfunc (t timeout) Type() string {\n\treturn t.timeoutType\n}\n\nfunc (t timeout) Timeout() int {\n\treturn t.timeout\n}\n\ntype request struct {\n\turl           string\n\tmethod        string\n\tbody          io.Reader\n\tcallingMethod string\n}\n\ntype elRequest struct {\n\turl           string\n\tby            By\n\tmethod        string\n\tcallingMethod string\n}\n\ntype stateResponse struct {\n\tState string `json:\"state\"`\n}\n\ntype valueResponse struct {\n\tState string `json:\"state\"`\n\tValue string `json:\"value\"`\n}\n\ntype by struct {\n\tt     string\n\tvalue interface{}\n}\n\nfunc (b by) Type() string {\n\treturn b.t\n}\n\nfunc (b by) Value() interface{} {\n\treturn b.value\n}\n"
  },
  {
    "path": "remote_driver_alert.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\n// DismissAlertResponse is the response returned from calling the DismissAlert\n// method.\ntype DismissAlertResponse struct {\n\tState string\n}\n\n// AcceptAlertResponse is the response returned from calling the AcceptAlert\n// method.\ntype AcceptAlertResponse struct {\n\tState string\n}\n\n// AlertTextResponse is the response returned from calling the AlertText\n// method.\ntype AlertTextResponse struct {\n\tState string\n\tText  string\n}\n\n// SendAlertTextResponse is the response returned from calling the\n// SendAlertText method.\ntype SendAlertTextResponse struct {\n\tState string\n}\n\nfunc (s *seleniumWebDriver) DismissAlert() (*DismissAlertResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"DismissAlert\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/alert/dismiss\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"DismissAlert\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &DismissAlertResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) AcceptAlert() (*AcceptAlertResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"AcceptAlert\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/alert/accept\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"AcceptAlert\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &AcceptAlertResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) AlertText() (*AlertTextResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"AlertTextResponse\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/alert/text\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"AlertText\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &AlertTextResponse{State: resp.State, Text: resp.Value}, nil\n}\n\nfunc (s *seleniumWebDriver) SendAlertText(text string) (*SendAlertTextResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"SendAlertText\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/alert/text\", s.seleniumURL, s.sessionID)\n\n\tb := map[string]string{\n\t\t\"text\": text,\n\t}\n\tjson, err := json.Marshal(b)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"SendAlertText\", b)\n\t}\n\n\tbody := bytes.NewReader(json)\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          body,\n\t\tcallingMethod: \"SendAlertText\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SendAlertTextResponse{State: resp.State}, nil\n}\n"
  },
  {
    "path": "remote_driver_alert_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tDismissAlert() Tests\n*/\n\nfunc Test_AlertDismissAlert_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.DismissAlert()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_AlertDismissAlert_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.DismissAlert()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_AlertDismissAlert_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.DismissAlert()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_AlertDismissAlert_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"8\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.DismissAlert()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tAcceptAlert() Tests\n*/\n\nfunc Test_AlertAcceptAlert_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.AcceptAlert()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_AlertAcceptAlert_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AcceptAlert()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_AlertAcceptAlert_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AcceptAlert()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_AlertAcceptAlert_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"8\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.AcceptAlert()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tAlertText() Tests\n*/\n\nfunc Test_AlertAlertText_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.AlertText()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_AlertAlertText_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AlertText()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_AlertAlertText_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AlertText()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_AlertAlertText_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"this is text\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.AlertText()\n\tif err != nil || resp.State != \"success\" || resp.Text != \"this is text\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tSendAlertText() Tests\n*/\nfunc Test_AlertSendAlertText_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.SendAlertText(\"test\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_AlertSendAlertText_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.SendAlertText(\"test\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_AlertSendAlertText_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.SendAlertText(\"test\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_AlertSendAlertText_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.SendAlertText(\"test\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_command.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n)\n\n// WindowHandleResponse is the response returned from the WindowHandle() method.\n// The handle is the current active window. Should you switch windows,\n// any value returned prior to that call will be invalid.\ntype WindowHandleResponse struct {\n\tState  string\n\tHandle string\n}\n\n// CloseWindowResponse is the response returned from the CloseWindow() method.\n// As per the W3C specification, it yields all of the available window handles\n// minus the active one that closes as a result of the CloseWindow() call.\ntype CloseWindowResponse struct {\n\tState   string   `json:\"state\"`\n\tHandles []string `json:\"value\"`\n}\n\n// SwitchToWindowResponse is the response returned from the SwitchToWindow()\n// method. You can verify that this result is correct by calling the\n// WindowHandle() method. The two should match.\ntype SwitchToWindowResponse struct {\n}\n\n// WindowHandlesResponse is the response returned from the WindowHandles()\n// method. This is essentially an array of available window handlers that\n// aren't necessarily active.\ntype WindowHandlesResponse struct {\n\tState   string   `json:\"state\"`\n\tHandles []string `json:\"value\"`\n}\n\n// SwitchToFrameResponse is the response returned from the SwitchToFrame()\n// method. For now, according to the specification, it only returns a state.\ntype SwitchToFrameResponse struct {\n\tState string\n}\n\n// SwitchToParentFrameResponse represents the response from attempting to\n// switch the top level browsing context to the parent of the current top level\n// browsing context.\ntype SwitchToParentFrameResponse struct {\n\tState string\n}\n\n// WindowSizeResponse is the response returned from calling the WindowSize\n// method. The definitions are in CSS pixels.\ntype WindowSizeResponse struct {\n\tState      string     `json:\"state\"`\n\tDimensions Dimensions `json:\"value\"`\n}\n\n// Dimensions is a type that is both returned and accept by functions. It is\n// usually only used for the window size components.\ntype Dimensions struct {\n\tWidth  uint `json:\"width\"`\n\tHeight uint `json:\"height\"`\n}\n\n// SetWindowSizeResponse is the response that is returned from setting the\n// window size of the current top level browsing context.\ntype SetWindowSizeResponse struct {\n\tState string\n}\n\n// MaximizeWindowResponse is the response that is returned from increasing the\n// browser to match the viewport.\ntype MaximizeWindowResponse struct {\n\tState string\n}\n\nfunc (s *seleniumWebDriver) WindowHandle() (*WindowHandleResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"WindowHandle\")\n\t}\n\n\tvar response WindowHandleResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"WindowHandle\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresponse = WindowHandleResponse{\n\t\tState:  resp.State,\n\t\tHandle: resp.Value,\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) CloseWindow() (*CloseWindowResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"CloseWindow\")\n\t}\n\n\tvar response CloseWindowResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.apiService.performRequest(url, \"DELETE\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"CloseWindow\", url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"CloseWindow\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) SwitchToWindow(handle string) (*SwitchToWindowResponse, error) {\n\treturn nil, nil\n}\n\nfunc (s *seleniumWebDriver) WindowHandles() (*WindowHandlesResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"WindowHandles\")\n\t}\n\n\tvar response WindowHandlesResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window/handles\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"WindowHandles\", url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"WindowHandles\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) SwitchToFrame(by By) (*SwitchToFrameResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"SwitchToFrame\")\n\t}\n\tif by == nil || (by.Type() != \"index\") {\n\t\treturn nil, errors.New(\"switchtoframe: invalid by argument\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/frame\", s.seleniumURL, s.sessionID)\n\n\tparams := map[string]interface{}{\n\t\t\"id\": by.Value(),\n\t}\n\trequestJSON, err := json.Marshal(params)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"SwitchToFrame\", params)\n\t}\n\n\tbody := bytes.NewReader(requestJSON)\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          body,\n\t\tcallingMethod: \"SwitchToFrame\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SwitchToFrameResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) SwitchToParentFrame() (*SwitchToParentFrameResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"SwitchToParentFrame\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/frame/parent\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"SwitchToParentFrame\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SwitchToParentFrameResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) WindowSize() (*WindowSizeResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"WindowSize\")\n\t}\n\n\tvar response WindowSizeResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window/size\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"WindowSize\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"WindowSize\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) SetWindowSize(dimension *Dimensions) (*SetWindowSizeResponse, error) {\n\tif dimension == nil {\n\t\treturn nil, errors.New(\"setwindowsize: invalid dimension argument\")\n\t} else if len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"SetWindowSize\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window/size\", s.seleniumURL, s.sessionID)\n\n\tbody := map[string]uint{\n\t\t\"width\":  dimension.Width,\n\t\t\"height\": dimension.Height,\n\t}\n\tjson, err := json.Marshal(body)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"SetWindowSize\", body)\n\t}\n\n\tjsonBytes := bytes.NewReader(json)\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          jsonBytes,\n\t\tcallingMethod: \"SetWindowSize\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SetWindowSizeResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) MaximizeWindow() (*MaximizeWindowResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"MaximizeWindow\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/window/maximize\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"MaximizeWindow\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &MaximizeWindowResponse{State: resp.State}, nil\n}\n"
  },
  {
    "path": "remote_driver_command_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tWindowHandle() Tests\n*/\n\nfunc Test_CommandWindowHandle_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.WindowHandle()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandle_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.WindowHandle()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandle_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.WindowHandle()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandle_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"8\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.WindowHandle()\n\tif err != nil || resp.State != \"success\" || resp.Handle != \"8\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCloseWindow() Tests\n*/\nfunc Test_CommandCloseWindow_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.CloseWindow()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandCloseWindow_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.CloseWindow()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n\n}\n\nfunc Test_CommandCloseWindow_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.CloseWindow()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\n/*\n\tSwitchToWindow() Tests\n*/\n\n/*\n\tWindowHandles() Tests\n*/\nfunc Test_CommandWindowHandles_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.WindowHandles()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandles_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.WindowHandles()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandles_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.WindowHandles()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandles_SingleResultCanBeReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": [\n\t\t\t\t\"8\"\n\t\t\t]\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.WindowHandles()\n\tif err != nil || resp.State != \"success\" || resp.Handles[0] != \"8\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_CommandWindowHandles_MultipleResultsCanBeReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": [\n\t\t\t\t\"8\",\n\t\t\t\t\"9\"\n\t\t\t]\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.WindowHandles()\n\tif err != nil || resp.State != \"success\" || resp.Handles[0] != \"8\" || resp.Handles[1] != \"9\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tSwitchToFrame Tests\n*/\nfunc Test_CommandSwitchToFrame_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.SwitchToFrame(nil)\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandSwitchToFrame_InvalidByResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tinvalidBys := []By{\n\t\tnil,\n\t\tByCSSSelector(\"test\"),\n\t}\n\n\tfor _, i := range invalidBys {\n\t\t_, err := d.SwitchToFrame(i)\n\t\tif err == nil {\n\t\t\tt.Errorf(argumentErrorText)\n\t\t}\n\t}\n}\n\nfunc Test_CommandSwitchToFrame_APICommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.SwitchToFrame(ByIndex(1))\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandSwitchToFrame_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\t\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.SwitchToFrame(ByIndex(32))\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tSwitchToParentFrame tests\n*/\nfunc Test_CommandSwitchToParentFrame_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.SwitchToFrame(nil)\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandSwitchToParentFrame_ApiCommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.SwitchToParentFrame()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandSwitchToParentFrame_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.SwitchToParentFrame()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandSwitchToParentFrame_CorrectResponseCanBeReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.SwitchToParentFrame()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tWindowSize tests\n*/\nfunc Test_CommandWindowSize_InvalidSessionIDResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.WindowSize()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandWindowSize_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.WindowSize()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandWindowSize_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.WindowSize()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandWindowSize_CorrectResultIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": {\n\t\t\t\t\"width\": 800,\n\t\t\t\t\"height\": 600\n\t\t\t}\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.WindowSize()\n\tif err != nil || resp.State != \"success\" || resp.Dimensions.Width == 0 || resp.Dimensions.Height == 0 {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tSetWindowSize tests\n*/\n\nfunc Test_CommandSetWindowSize_NullDimensionResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.SetWindowSize(nil)\n\tif err == nil {\n\t\tt.Errorf(argumentErrorText)\n\t}\n}\n\nfunc Test_CommandSetWindowSize_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\tdimensions := &Dimensions{\n\t\tWidth:  830,\n\t\tHeight: 255,\n\t}\n\n\t_, err := d.SetWindowSize(dimensions)\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandSetWindowSize_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tdimensions := &Dimensions{\n\t\tWidth:  830,\n\t\tHeight: 255,\n\t}\n\n\t_, err := d.SetWindowSize(dimensions)\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandSetWindowSize_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tdimensions := &Dimensions{\n\t\tWidth:  830,\n\t\tHeight: 255,\n\t}\n\n\t_, err := d.SetWindowSize(dimensions)\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandSetWindowSize_ResultIsReturnedSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tdimensions := &Dimensions{\n\t\tWidth:  830,\n\t\tHeight: 255,\n\t}\n\n\tresp, err := d.SetWindowSize(dimensions)\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tMaximizeWindow tests\n*/\nfunc Test_CommandMaximizeWindow_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.MaximizeWindow()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandMaximizeWindow_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.MaximizeWindow()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandMaximizeWindow_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.MaximizeWindow()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandMaximizeWindow_ResultIsReturnedSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.MaximizeWindow()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_cookie.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\n// AllCookiesResponse is the response returned from the AllCookies method.\ntype AllCookiesResponse struct {\n\tState   string   `json:\"state\"`\n\tCookies []Cookie `json:\"value\"`\n}\n\n// CookieResponse is the response returned from the Cookie method.\ntype CookieResponse struct {\n\tState  string `json:\"state\"`\n\tCookie Cookie `json:\"value\"`\n}\n\n// Cookie represents a browser cookie.\ntype Cookie struct {\n\tName       string `json:\"name\"`\n\tValue      string `json:\"value\"`\n\tPath       string `json:\"path\"`\n\tDomain     string `json:\"domain\"`\n\tSecureOnly bool   `json:\"secure\"`\n\tHTTPOnly   bool   `json:\"httpOnly\"`\n}\n\n// AddCookieResponse is the result returned from calling the AddCookie method.\ntype AddCookieResponse struct {\n\tState string\n}\n\n// DeleteCookieResponse is the result returned from calling the DeleteCookie\n// method.\ntype DeleteCookieResponse struct {\n\tState string\n}\n\nfunc (s *seleniumWebDriver) AllCookies() (*AllCookiesResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"AllCookies\")\n\t}\n\n\tvar response AllCookiesResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/cookie\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"AllCookies\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"AllCookies\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) Cookie(name string) (*CookieResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Cookie\")\n\t}\n\n\tvar response CookieResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/cookie/%s\", s.seleniumURL, s.sessionID, name)\n\n\tresp, err := s.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"Cookie\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"Cookie\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) AddCookie(c *Cookie) (*AddCookieResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"AddCookie\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/cookie\", s.seleniumURL, s.sessionID)\n\n\tj := map[string]Cookie{\n\t\t\"cookie\": *c,\n\t}\n\tb, err := json.Marshal(j)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"AddCookie\", c)\n\t}\n\n\tbody := bytes.NewReader(b)\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tbody:          body,\n\t\tmethod:        \"POST\",\n\t\tcallingMethod: \"AddCookie\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &AddCookieResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) DeleteCookie(name string) (*DeleteCookieResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"DeleteCookie\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/cookie/%s\", s.seleniumURL, s.sessionID, name)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tbody:          nil,\n\t\tmethod:        \"DELETE\",\n\t\tcallingMethod: \"DeleteCookie\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &DeleteCookieResponse{State: resp.State}, nil\n}\n"
  },
  {
    "path": "remote_driver_cookie_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tAllCookies tests\n*/\nfunc Test_CookieAllCookies_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.AllCookies()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CookieAllCookies_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AllCookies()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CookieAllCookies_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AllCookies()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CookieAllCookies_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": [\n\t\t\t\t{\n\t\t\t\t\t\"name\": \"Test Cookie\",\n\t\t\t\t\t\"value\": \"Test Value\",\n\t\t\t\t\t\"path\": \"/\",\n\t\t\t\t\t\"domain\": \"www.google.com\",\n\t\t\t\t\t\"secure\": true,\n\t\t\t\t\t\"httpOnly\": true,\n\t\t\t\t\t\"expiry\": \"2016-12-25T00:00:00Z\"\n\t\t\t\t}\n\t\t\t]\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.AllCookies()\n\tif err != nil || resp.State != \"success\" || resp.Cookies[0].Name != \"Test Cookie\" ||\n\t\tresp.Cookies[0].Value != \"Test Value\" || resp.Cookies[0].Path != \"/\" ||\n\t\tresp.Cookies[0].Domain != \"www.google.com\" || !resp.Cookies[0].SecureOnly ||\n\t\t!resp.Cookies[0].HTTPOnly {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCookie tests\n*/\nfunc Test_CookieCookie_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Cookie(\"test\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CookieCookie_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Cookie(\"test\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CookieCookie_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Cookie(\"test\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CookieCookie_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": { \n\t\t\t\t\t\"name\": \"Test Cookie\",\n\t\t\t\t\t\"value\": \"Test Value\",\n\t\t\t\t\t\"path\": \"/\",\n\t\t\t\t\t\"domain\": \"www.google.com\",\n\t\t\t\t\t\"secure\": true,\n\t\t\t\t\t\"httpOnly\": true,\n\t\t\t\t\t\"expiry\": \"2016-12-25T00:00:00Z\"\n\t\t\t}\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.Cookie(\"test\")\n\tif err != nil || resp.State != \"success\" || resp.Cookie.Name != \"Test Cookie\" ||\n\t\tresp.Cookie.Value != \"Test Value\" || resp.Cookie.Path != \"/\" ||\n\t\tresp.Cookie.Domain != \"www.google.com\" || !resp.Cookie.SecureOnly ||\n\t\t!resp.Cookie.HTTPOnly {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tAddCookie tests\n*/\nfunc Test_CookieAddCookie_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.AddCookie(nil)\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CookieAddCookie_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AddCookie(&Cookie{Name: \"cookie\", Path: \"/\"})\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CookieAddCookie_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.AddCookie(&Cookie{Name: \"cookie\", Path: \"/\"})\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CookieAddCookie_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.AddCookie(&Cookie{Name: \"cookie\", Path: \"/\"})\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tDeleteCookie tests\n*/\nfunc Test_CookieDeleteCookie_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.DeleteCookie(\"\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CookieDeleteCookie_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.DeleteCookie(\"\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CookieDeleteCookie_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.DeleteCookie(\"\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CookieDeleteCookie_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.DeleteCookie(\"\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_document.go",
    "content": "package goselenium\n\nimport \"fmt\"\n\n// PageSourceResponse is the response returned from calling the PageSource\n// method.\ntype PageSourceResponse struct {\n\tState  string\n\tSource string\n}\n\n// ExecuteScriptResponse is the response returned from calling the ExecuteScript\n// method.\ntype ExecuteScriptResponse struct {\n\tState    string\n\tResponse string\n}\n\nfunc (s *seleniumWebDriver) PageSource() (*PageSourceResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"PageSource\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/source\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"PageSource\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &PageSourceResponse{State: resp.State, Source: resp.Value}, nil\n}\n\nfunc (s *seleniumWebDriver) ExecuteScript(script string) (*ExecuteScriptResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"ExecuteScript\")\n\t}\n\n\turl := fmt.Sprintf(\"%s/session/%s/execute\", s.seleniumURL, s.sessionID)\n\n\treturn s.scriptRequest(script, url, \"ExecuteScript\")\n}\n\nfunc (s *seleniumWebDriver) ExecuteScriptAsync(script string) (*ExecuteScriptResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"ExecuteScriptAsync\")\n\t}\n\n\turl := fmt.Sprintf(\"%s/session/%s/execute_async\", s.seleniumURL, s.sessionID)\n\n\treturn s.scriptRequest(script, url, \"ExecuteScriptAsync\")\n}\n"
  },
  {
    "path": "remote_driver_document_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tPageSource tests\n*/\nfunc Test_DocumentPageSource_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.PageSource()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_DocumentPageSource_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.PageSource()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_DocumentPageSource_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.PageSource()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_DocumentPageSource_ResultIsReturnedSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"this would be HTML\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.PageSource()\n\tif err != nil || resp.State != \"success\" || resp.Source != \"this would be HTML\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tExecuteScript tests\n*/\nfunc Test_CommandExecuteScript_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.ExecuteScript(\"alert('test');\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScript_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.ExecuteScript(\"alert('test');\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScript_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.ExecuteScript(\"alert('test');\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScript_ResultIsReturnedSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.ExecuteScript(\"alert('test');\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tExecuteScriptAsync tests\n*/\nfunc Test_CommandExecuteScriptAsync_InvalidSessionIDResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.ExecuteScriptAsync(\"alert('test');\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScriptAsync_CommunicationErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.ExecuteScriptAsync(\"alert('test');\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScriptAsync_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.ExecuteScriptAsync(\"alert('test');\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_CommandExecuteScriptAsync_ResultIsReturnedSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.ExecuteScriptAsync(\"alert('test');\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_element.go",
    "content": "package goselenium\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n)\n\ntype findElementResponse struct {\n\tE element `json:\"value\"`\n}\n\ntype findElementsResponse struct {\n\tE []element `json:\"value\"`\n}\n\ntype element struct {\n\tID string `json:\"element\"`\n}\n\nfunc (s *seleniumWebDriver) FindElement(by By) (Element, error) {\n\tif by.Type() == \"index\" {\n\t\treturn nil, errors.New(\"findelement: invalid by argument\")\n\t}\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"FindElement\")\n\t}\n\n\tvar response findElementResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.elementRequest(&elRequest{\n\t\turl:           url,\n\t\tby:            by,\n\t\tmethod:        \"POST\",\n\t\tcallingMethod: \"FindElement\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"FindElement\", string(resp))\n\t}\n\n\tel := newSeleniumElement(response.E.ID, s)\n\treturn el, nil\n}\n\nfunc (s *seleniumWebDriver) FindElements(by By) ([]Element, error) {\n\tif by.Type() == \"index\" {\n\t\treturn nil, errors.New(\"findelements: invalid by argument\")\n\t}\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"FindElements\")\n\t}\n\n\tvar response findElementsResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/elements\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.elementRequest(&elRequest{\n\t\turl:           url,\n\t\tby:            by,\n\t\tmethod:        \"POST\",\n\t\tcallingMethod: \"FindElements\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"FindElements\", string(resp))\n\t}\n\n\telements := make([]Element, len(response.E))\n\tfor i := range response.E {\n\t\telements[i] = newSeleniumElement(response.E[i].ID, s)\n\t}\n\n\treturn elements, nil\n}\n"
  },
  {
    "path": "remote_driver_element_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tFIND ELEMENT TESTS\n*/\nfunc Test_ElementFindElement_ByIndexResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.FindElement(ByIndex(32))\n\tif err == nil {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_ElementFindElement_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.FindElement(ByCSSSelector(\"test\"))\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_ElementFindElement_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.FindElement(ByCSSSelector(\"iframe > ul\"))\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementFindElement_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.FindElement(ByCSSSelector(\"iframe > ul\"))\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementFindElement_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": {\n\t\t\t\t\"ELEMENT\": \"0\"\n\t\t\t}\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.FindElement(ByCSSSelector(\"iframe > ul\"))\n\tif err != nil || resp.ID() != \"0\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tFIND ELEMENTS TESTS\n*/\nfunc Test_ElementFindElements_ByIndexResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.FindElements(ByIndex(32))\n\tif err == nil {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_ElementFindElements_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.FindElements(ByCSSSelector(\"test\"))\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_ElementFindElements_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.FindElements(ByCSSSelector(\"iframe > ul\"))\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementFindElements_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.FindElements(ByCSSSelector(\"iframe > ul\"))\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementFindElements_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": [\n\t\t\t\t{\"ELEMENT\": \"0\"},\n\t\t\t\t{\"ELEMENT\": \"1\"}\n\t\t\t]\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.FindElements(ByCSSSelector(\"iframe > ul\"))\n\tif err != nil || len(resp) <= 1 || resp[1].ID() != \"1\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_helpers.go",
    "content": "package goselenium\n\nimport \"time\"\n\n// Until represents a function that will be continuously repeated until it\n// succeeds or a timeout is reached.\ntype Until func(w WebDriver) bool\n\n// UntilElementPresent attempts to locate an element on the page. It is\n// determined as existing if the state is 'Success' and the error is nil.\nfunc UntilElementPresent(by By) Until {\n\treturn func(w WebDriver) bool {\n\t\t_, err := w.FindElement(by)\n\t\treturn err == nil\n\t}\n}\n\n// UntilURLIs checks whether or not the page's URL has changed.\nfunc UntilURLIs(url string) Until {\n\treturn func(w WebDriver) bool {\n\t\tresp, err := w.CurrentURL()\n\t\treturn err == nil && resp.URL == url\n\t}\n}\n\nfunc (s *seleniumWebDriver) Wait(u Until, timeout time.Duration, sleep time.Duration) bool {\n\tresponse := make(chan bool, 1)\n\tquit := make(chan bool, 1)\n\n\tgo func() {\n\touter:\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase <-quit:\n\t\t\t\tbreak outer\n\t\t\tdefault:\n\t\t\t\te := u(s)\n\t\t\t\tif e {\n\t\t\t\t\tresponse <- true\n\t\t\t\t\tbreak outer\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttime.Sleep(sleep)\n\t\t}\n\t}()\n\n\tselect {\n\tcase r := <-response:\n\t\treturn r\n\tcase <-time.After(timeout):\n\t\tclose(quit)\n\t\treturn false\n\t}\n}\n"
  },
  {
    "path": "remote_driver_navigation.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n)\n\n// GoResponse is the response returned from the selenium web driver when calling\n// the Go() call. Unfortunately, the W3C specification defines that the response\n// should only be whether the call succeeded or not. Should there be any redirects\n// they will not be catered for in this response. Should you expect any redirects\n// to happen, call the CurrentURL() method.\ntype GoResponse struct {\n\tState string\n}\n\n// CurrentURLResponse is the response returned from the GET Url call.\ntype CurrentURLResponse struct {\n\tState string\n\tURL   string\n}\n\n// BackResponse is the response returned from the Back call.\ntype BackResponse struct {\n\tState string\n}\n\n// ForwardResponse is the response returned from the Forward call.\ntype ForwardResponse struct {\n\tState string\n}\n\n// RefreshResponse is the response returned from the Refresh call.\ntype RefreshResponse struct {\n\tState string\n}\n\n// TitleResponse is the response returned from the Title call.\ntype TitleResponse struct {\n\tState string\n\tTitle string\n}\n\nfunc (s *seleniumWebDriver) Go(goURL string) (*GoResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Go\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/url\", s.seleniumURL, s.sessionID)\n\n\tinvalidURL := goURL == \"\"\n\tvalidProtocol := strings.HasPrefix(goURL, \"https://\") || strings.HasPrefix(goURL, \"http://\")\n\tif invalidURL || !validProtocol {\n\t\treturn nil, newInvalidURLError(goURL)\n\t}\n\n\tparams := map[string]string{\n\t\t\"url\": goURL,\n\t}\n\tmarshalledJSON, err := json.Marshal(params)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"Go\", params)\n\t}\n\n\tbodyReader := bytes.NewReader([]byte(marshalledJSON))\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          bodyReader,\n\t\tcallingMethod: \"Go\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &GoResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) CurrentURL() (*CurrentURLResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"CurrentURL\")\n\t}\n\n\tvar response CurrentURLResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/url\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"CurrentURL\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresponse = CurrentURLResponse{\n\t\tState: resp.State,\n\t\tURL:   resp.Value,\n\t}\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) Back() (*BackResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Back\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/back\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Back\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &BackResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) Forward() (*ForwardResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Forward\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/forward\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Forward\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ForwardResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) Refresh() (*RefreshResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Refresh\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/refresh\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Refresh\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &RefreshResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) Title() (*TitleResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Title\")\n\t}\n\n\tvar response TitleResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/title\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Title\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresponse = TitleResponse{\n\t\tState: resp.State,\n\t\tTitle: resp.Value,\n\t}\n\treturn &response, nil\n}\n"
  },
  {
    "path": "remote_driver_navigation_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n   Navigation Go Tests\n*/\nfunc Test_NavigateGo_NoSessionIdCausesError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Go(\"http://google.com\")\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateGo_InvalidURLFormatResultsInError(t *testing.T) {\n\tinvalidURLs := []string{\n\t\t\"\",\n\t\t\"google.com\",\n\t\t\"htt://google.com\",\n\t\t\"://google.com\",\n\t\t\"/\\\\\",\n\t}\n\n\tfor _, i := range invalidURLs {\n\t\tapi := &testableAPIService{\n\t\t\tjsonToReturn:  \"\",\n\t\t\terrorToReturn: nil,\n\t\t}\n\n\t\td := setUpDriver(setUpDefaultCaps(), api)\n\t\td.sessionID = \"12345\"\n\n\t\t_, err := d.Go(i)\n\t\tif err == nil || !IsInvalidURLError(err) {\n\t\t\tt.Errorf(\"URL error was not returned\")\n\t\t}\n\t}\n}\n\nfunc Test_NavigateGo_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error! :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Go(\"https://www.google.com\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateGo_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Go(\"https://www.google.com\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateGo_ResultIsUnmarshalledSuccessfully(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n            \"state\": \"success\"\n        }`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.Go(\"https://www.google.com\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCurrentURL tests\n*/\nfunc Test_NavigateCurrentURL_InvalidSessionIdResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.CurrentURL()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateCurrentURL_CommunicationFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"AN error :< \"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.CurrentURL()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateCurrentURL_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.CurrentURL()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateCurrentURL_SuccessfulResultGetsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"http://google.com\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.CurrentURL()\n\tif err != nil || resp.URL != \"http://google.com\" || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tBack tests\n*/\nfunc Test_NavigateBack_InvalidSessionIdResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Back()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateBack_CommunicationFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"AN error :< \"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Back()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateBack__UnmarshallingFailureResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Back()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateBack_SuccessfulResultGetsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.Back()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tForward tests\n*/\nfunc Test_NavigateForward_InvalidSessionIdResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Forward()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateForward_CommunicationFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"AN error :< \"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Forward()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateForward__UnmarshallingFailureResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Forward()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateForward_SuccessfulResultGetsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.Forward()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tRefresh tests\n*/\nfunc Test_NavigateRefresh_InvalidSessionIdResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Refresh()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateRefresh_CommunicationFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"AN error :< \"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Refresh()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateRefresh_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Refresh()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateRefresh_SuccessfulResultGetsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.Refresh()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tTitle tests\n*/\nfunc Test_NavigateTitle_InvalidSessionIdResultsInAnError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.Title()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_NavigateTitle_CommunicationFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"AN error :< \"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Title()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_NavigateTitle_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.Title()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_NavigateTitle_SuccessfulResultGetsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"Google\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.Title()\n\tif err != nil || resp.State != \"success\" || resp.Title != \"Google\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_screenshot.go",
    "content": "package goselenium\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n)\n\n// ScreenshotResponse is the response returned from the Screenshot and\n// ScreenshotElement methods.\ntype ScreenshotResponse struct {\n\tState        string\n\tEncodedImage string\n}\n\n// ImageBytes is a helpful function for decoding the base64 encoded image URL.\n// The image returned is a PNG image and as such can be manipulated by the\n// image/png package. Trying to save this as any other image type will\n// result in it failing to open.\nfunc (s *ScreenshotResponse) ImageBytes() ([]byte, error) {\n\treturn base64.StdEncoding.DecodeString(s.EncodedImage)\n}\n\nfunc (s *seleniumWebDriver) Screenshot() (*ScreenshotResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"Screenshot\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/screenshot\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Screenshot\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ScreenshotResponse{State: resp.State, EncodedImage: resp.Value}, nil\n}\n"
  },
  {
    "path": "remote_driver_screenshot_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\nfunc Test_ScreenshotScreenshot_NoSessionIdCausesError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\n\t_, err := d.Screenshot()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_ScreenshotScreenshot_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error! :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Screenshot()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ScreenshotScreenshot_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\t_, err := d.Screenshot()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ScreenshotScreen_CorrectResponseCanBeReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"dGVzdA==\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.Screenshot()\n\tif err != nil || resp.State != \"success\" || resp.EncodedImage != \"dGVzdA==\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_ScreenshotScreenshot_Base64StringCanBeDecoded(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"dGVzdA==\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tresp, err := d.Screenshot()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n\n\tbytes, err := resp.ImageBytes()\n\tif err != nil || len(bytes) == 0 {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "remote_driver_session.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\n// CreateSessionResponse is the response returned from the API when the\n// CreateSession() method does not throw an error.\ntype CreateSessionResponse struct {\n\tCapabilities CreateSessionCapabilities `json:\"value\"`\n\tSessionID    string                    `json:\"sessionId\"`\n}\n\n// CreateSessionCapabilities is a summarisation of the capabilities returned\n// from the CreateSession method.\ntype CreateSessionCapabilities struct {\n\tAcceptInsecureCerts bool   `json:\"acceptSslCerts\"`\n\tBrowserName         string `json:\"browserName\"`\n\tBrowserVersion      string `json:\"browserVersion\"`\n\tPlatformName        string `json:\"platformVersion\"`\n}\n\n// DeleteSessionResponse is the response returned from the API when the\n// DeleteSession() method does not thrown an error.\ntype DeleteSessionResponse struct {\n\tState     string `json:\"state\"`\n\tSessionID string `json:\"sessionId\"`\n}\n\n// SessionStatusResponse is the response returned from the API when the\n// SessionStatus() method is called.\ntype SessionStatusResponse struct {\n\tState string\n}\n\n// SetSessionTimeoutResponse is the response returned from the API when the\n// SetSessionTimeoutResponse() method is called.\ntype SetSessionTimeoutResponse struct {\n\tState string\n}\n\nfunc (s *seleniumWebDriver) CreateSession() (*CreateSessionResponse, error) {\n\tvar response CreateSessionResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session\", s.seleniumURL)\n\n\tcapabilitiesJSON, err := s.capabilities.toJSON()\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"CreateSession\", s.capabilities)\n\t}\n\n\tbody := bytes.NewReader([]byte(capabilitiesJSON))\n\tresp, err := s.apiService.performRequest(url, \"POST\", body)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"CreateSession\", url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"CreateSession\", string(resp))\n\t}\n\n\ts.sessionID = response.SessionID\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) DeleteSession() (*DeleteSessionResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"DeleteSession\")\n\t}\n\n\tvar response DeleteSessionResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s\", s.seleniumURL, s.sessionID)\n\n\tresp, err := s.apiService.performRequest(url, \"DELETE\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"DeleteSession\", url, resp)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"DeleteSession\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumWebDriver) SessionStatus() (*SessionStatusResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/status\", s.seleniumURL)\n\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"SessionStatus\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SessionStatusResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumWebDriver) SetSessionTimeout(to Timeout) (*SetSessionTimeoutResponse, error) {\n\tif len(s.sessionID) == 0 {\n\t\treturn nil, newSessionIDError(\"SetSessionTimeout\")\n\t}\n\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/timeouts\", s.seleniumURL, s.sessionID)\n\n\tparams := map[string]interface{}{\n\t\t\"type\": to.Type(),\n\t\t\"ms\":   to.Timeout(),\n\t}\n\tmarshalledJSON, err := json.Marshal(params)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"SetSessionTimeout\", params)\n\t}\n\n\tbodyReader := bytes.NewReader([]byte(marshalledJSON))\n\tresp, err := s.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          bodyReader,\n\t\tcallingMethod: \"SetSessionTimeout\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &SetSessionTimeoutResponse{State: resp.State}, nil\n}\n"
  },
  {
    "path": "remote_driver_session_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\n/*\n\tCREATE SESSION TESTS\n*/\nfunc Test_CreateSession_FailedAPIRequestResultsInAnErrorBeingReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.CreateSession()\n\tif !IsCommunicationError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_CreateSession_ResultGetsUnmarshalledCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n            \"sessionId\": \"a45a54d3-5413-425c-84ef-d1190cc0521c\"\n        }`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\tresp, err := d.CreateSession()\n\tif err != nil || resp.SessionID == \"\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_CreateSession_ResultIsAssignedToWebDriver(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n            \"sessionId\": \"a45a54d3-5413-425c-84ef-d1190cc0521c\"\n        }`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.CreateSession()\n\tif err != nil || d.sessionID != \"a45a54d3-5413-425c-84ef-d1190cc0521c\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_CreateSession_UnmarshallingErrorIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.CreateSession()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\n/*\n\tDELETE SESSION TESTS\n*/\nfunc Test_DeleteSession_WhenSessionIDIsNotSetAnErrorIsThrown(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.DeleteSession()\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_DeleteSession_ApiFailureIsHandled(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"This is an error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.DeleteSession()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_DeleteSession_ResponseIsUnmarshalledCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"sessionId\": \"3cebaef3-4fd0-464f-bd24-0a7170074ad4\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\tresp, err := d.DeleteSession()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_DeleteSession_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\t_, err := d.DeleteSession()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\n/*\n\tSession Status Test\n*/\nfunc Test_SessionStatus_ApiFailureIsHandled(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"This is an error\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.SessionStatus()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_SessionStatusResponse_IsUnmarshalledCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\t\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\tresp, err := d.SessionStatus()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\nfunc Test_SessionStatusResponse_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.SessionStatus()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\n/*\n\tSession Set Timeout Test\n*/\nfunc Test_SetSessionTimeout_ErrorIsThrownIfSessionIdNotSet(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\t_, err := d.SetSessionTimeout(nil)\n\tif err == nil || !IsSessionIDError(err) {\n\t\tt.Errorf(sessionIDErrorText)\n\t}\n}\n\nfunc Test_SetSessionTimeout_ApiCommunicationErrorIsHandled(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error!\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"1\"\n\n\tvar timeouts = []Timeout{\n\t\tSessionScriptTimeout(25000),\n\t\tSessionPageLoadTimeout(25000),\n\t\tSessionImplicitWaitTimeout(25000),\n\t}\n\n\tfor _, i := range timeouts {\n\t\t_, err := d.SetSessionTimeout(i)\n\t\tif err == nil || !IsCommunicationError(err) {\n\t\t\tt.Errorf(apiCommunicationErrorText)\n\t\t}\n\t}\n}\n\nfunc Test_SetSessionTimeout_ResponseIsUnmarshalledCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"1\"\n\n\tvar timeouts = []Timeout{\n\t\tSessionScriptTimeout(25000),\n\t\tSessionPageLoadTimeout(25000),\n\t\tSessionImplicitWaitTimeout(25000),\n\t}\n\n\tfor _, i := range timeouts {\n\t\tresp, err := d.SetSessionTimeout(i)\n\t\tif err != nil || resp.State != \"success\" {\n\t\t\tt.Errorf(correctResponseErrorText)\n\t\t}\n\t}\n}\n\nfunc Test_SetSessionTimeout_UnmarshallingFailureResultsInError(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"1\"\n\n\tvar timeouts = []Timeout{\n\t\tSessionScriptTimeout(25000),\n\t\tSessionPageLoadTimeout(25000),\n\t\tSessionImplicitWaitTimeout(25000),\n\t}\n\n\tfor _, i := range timeouts {\n\t\t_, err := d.SetSessionTimeout(i)\n\t\tif err == nil || !IsUnmarshallingError(err) {\n\t\t\tt.Errorf(unmarshallingErrorText)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "remote_driver_test.go",
    "content": "package goselenium\n\nimport (\n\t\"io\"\n\t\"strings\"\n\t\"testing\"\n)\n\nconst (\n\tapiCommunicationErrorText = \"An error was not returned or was not of the API communication type\"\n\tsessionIDErrorText        = \"An error was not returned or was not of the SessionIDError type\"\n\tcorrectResponseErrorText  = \"An error was returned or the result was not what was expected\"\n\targumentErrorText         = \"An error was not returned or was not of the ArgumentError type\"\n\tunmarshallingErrorText    = \"An error was not returned or was not of the UnmarshallingError type\"\n)\n\nfunc setUpDefaultCaps() *Capabilities {\n\tcaps := Capabilities{}\n\tcaps.SetBrowser(FirefoxBrowser())\n\treturn &caps\n}\n\nfunc setUpDriver(caps *Capabilities, api apiServicer) *seleniumWebDriver {\n\treturn &seleniumWebDriver{\n\t\tseleniumURL:  \"http://localhost:4444/wd/hub/\",\n\t\tcapabilities: caps,\n\t\tapiService:   api,\n\t}\n}\n\ntype testableAPIService struct {\n\tjsonToReturn  string\n\terrorToReturn error\n\tbodyNilError  error\n}\n\nfunc (t *testableAPIService) performRequest(url string, method string, body io.Reader) ([]byte, error) {\n\tjson := []byte(t.jsonToReturn)\n\treturn json, t.errorToReturn\n}\n\nfunc Test_NewSelenium_WebDriverCreatesErrorIfSeleniumURLIsInvalid(t *testing.T) {\n\tinvalidSeleniumUrls := []string{\n\t\t\"\",\n\t\t\" \",\n\t\t\"myRequirementWithoutProtocol\",\n\t}\n\tfor _, i := range invalidSeleniumUrls {\n\t\tcaps := setUpDefaultCaps()\n\t\t_, err := NewSeleniumWebDriver(i, *caps)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Passing an invalid remote Selenium URL did not cause an error\")\n\t\t}\n\t}\n}\n\nfunc Test_NewSelenium_WebDriverCreatesSuccessfullyIfSeleniumURLIsValid(t *testing.T) {\n\tvalidSeleniumUrls := []string{\n\t\t\"http://google.com\",\n\t\t\"https://google.com\",\n\t}\n\tfor _, i := range validSeleniumUrls {\n\t\tcaps := setUpDefaultCaps()\n\t\tw, err := NewSeleniumWebDriver(i, *caps)\n\t\tif w == nil || err != nil {\n\t\t\tt.Errorf(\"Passing a valid remote Selenium URL caused an error or did not return a valid driver.\")\n\t\t}\n\t}\n}\n\nfunc Test_NewSelenium_WebDriverCreatesErrorIfCapabilitiesAreEmpty(t *testing.T) {\n\t_, err := NewSeleniumWebDriver(\"http://google.com\", Capabilities{})\n\tif err == nil {\n\t\tt.Errorf(\"Passing an empty capabilities object did not cause an error.\")\n\t}\n}\n\nfunc Test_NewSelenium_TrailingSlashIsRemovedIfTheUserDoesNotSpecifyOne(t *testing.T) {\n\tinvalidUrls := []string{\n\t\t\"http://localhost/\",\n\t\t\"http://localhost:444/\",\n\t}\n\tfor _, i := range invalidUrls {\n\t\tcaps := setUpDefaultCaps()\n\t\td, err := NewSeleniumWebDriver(i, *caps)\n\t\tif err != nil || strings.HasSuffix(d.DriverURL(), \"/\") {\n\t\t\tt.Errorf(\"Trailing slash was not removed from URL or an error was returned.\")\n\t\t}\n\t}\n}\n\n/*\n\tBy tests\n*/\nfunc Test_ByByIndex_CorrectIndexReturnsAsExpected(t *testing.T) {\n\tcorrectIndexes := []uint{\n\t\t1,\n\t\t58,\n\t\t65535,\n\t}\n\tfor _, i := range correctIndexes {\n\t\tr := ByIndex(i)\n\t\tif r.Type() != \"index\" || r.Value().(uint) != i {\n\t\t\tt.Errorf(correctResponseErrorText)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "remote_element.go",
    "content": "package goselenium\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\nfunc newSeleniumElement(i string, w *seleniumWebDriver) *seleniumElement {\n\treturn &seleniumElement{\n\t\tid: i,\n\t\twd: w,\n\t}\n}\n\n// ElementSelectedResponse is the response returned from the Selected() call.\n// The result /should/ always be successfully returned unless there is a\n// server error.\ntype ElementSelectedResponse struct {\n\tState    string `json:\"state\"`\n\tSelected bool   `json:\"value\"`\n}\n\n// ElementAttributeResponse is the response returned from the Attribute call.\ntype ElementAttributeResponse struct {\n\tState string\n\tValue string\n}\n\n// ElementCSSValueResponse is the response returned when the CSSValue method\n// is called on an Element implementation.\ntype ElementCSSValueResponse struct {\n\tState string\n\tValue string\n}\n\n// ElementTextResponse is the response returned from calling the Text method.\ntype ElementTextResponse struct {\n\tState string\n\tText  string\n}\n\n// ElementTagNameResponse is the response returned from calling the TagName method.\ntype ElementTagNameResponse struct {\n\tState string\n\tTag   string\n}\n\n// ElementRectangleResponse is the response returned from calling the Rectangle\n// method.\ntype ElementRectangleResponse struct {\n\tState     string\n\tRectangle Rectangle `json:\"value\"`\n}\n\n// Rectangle repsents an elements size and position on the page.\ntype Rectangle struct {\n\tDimensions\n\n\tX int `json:\"x\"`\n\tY int `json:\"y\"`\n}\n\n// ElementEnabledResponse is the response returned from calling the Enabled method.\ntype ElementEnabledResponse struct {\n\tState   string `json:\"state\"`\n\tEnabled bool   `json:\"value\"`\n}\n\n// ElementClickResponse is the response returned from calling the Click method.\ntype ElementClickResponse struct {\n\tState string\n}\n\n// ElementClearResponse is the response returned from calling the Clear method.\ntype ElementClearResponse struct {\n\tState string\n}\n\n// ElementSendKeysResponse is the response returned from calling the SendKeys method.\ntype ElementSendKeysResponse struct {\n\tState string\n}\n\ntype seleniumElement struct {\n\tid string\n\twd *seleniumWebDriver\n}\n\nfunc (s *seleniumElement) ID() string {\n\treturn s.id\n}\n\nfunc (s *seleniumElement) Selected() (*ElementSelectedResponse, error) {\n\tvar el ElementSelectedResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/selected\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"Selected\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &el)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"Selected\", string(resp))\n\t}\n\n\treturn &el, nil\n}\n\nfunc (s *seleniumElement) Attribute(att string) (*ElementAttributeResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/attribute/%s\", s.wd.seleniumURL, s.wd.sessionID, s.ID(), att)\n\n\tresp, err := s.wd.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Attribute\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementAttributeResponse{State: resp.State, Value: resp.Value}, nil\n}\n\nfunc (s *seleniumElement) CSSValue(prop string) (*ElementCSSValueResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/css/%s\", s.wd.seleniumURL, s.wd.sessionID, s.ID(), prop)\n\n\tresp, err := s.wd.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"CSSValue\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementCSSValueResponse{State: resp.State, Value: resp.Value}, nil\n}\n\nfunc (s *seleniumElement) Text() (*ElementTextResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/text\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Text\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementTextResponse{State: resp.State, Text: resp.Value}, nil\n}\n\nfunc (s *seleniumElement) TagName() (*ElementTagNameResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/name\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.valueRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"GET\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"TagName\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementTagNameResponse{State: resp.State, Tag: resp.Value}, nil\n}\n\nfunc (s *seleniumElement) Rectangle() (*ElementRectangleResponse, error) {\n\tvar response ElementRectangleResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/rect\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"Rectangle\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"Rectangle\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumElement) Enabled() (*ElementEnabledResponse, error) {\n\tvar response ElementEnabledResponse\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/enabled\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.apiService.performRequest(url, \"GET\", nil)\n\tif err != nil {\n\t\treturn nil, newCommunicationError(err, \"Enabled\", url, nil)\n\t}\n\n\terr = json.Unmarshal(resp, &response)\n\tif err != nil {\n\t\treturn nil, newUnmarshallingError(err, \"Enabled\", string(resp))\n\t}\n\n\treturn &response, nil\n}\n\nfunc (s *seleniumElement) Click() (*ElementClickResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/click\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Click\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementClickResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumElement) Clear() (*ElementClearResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/clear\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tresp, err := s.wd.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          nil,\n\t\tcallingMethod: \"Clear\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementClearResponse{State: resp.State}, nil\n}\n\nfunc (s *seleniumElement) SendKeys(keys string) (*ElementSendKeysResponse, error) {\n\tvar err error\n\n\turl := fmt.Sprintf(\"%s/session/%s/element/%s/value\", s.wd.seleniumURL, s.wd.sessionID, s.ID())\n\n\tkeyChars := make([]string, len(keys))\n\tfor i, k := range keys {\n\t\tkeyChars[i] = string(k)\n\t}\n\tdict := map[string][]string{\n\t\t\"value\": keyChars,\n\t}\n\tbody, err := json.Marshal(dict)\n\tif err != nil {\n\t\treturn nil, newMarshallingError(err, \"SendKeys\", dict)\n\t}\n\n\treader := bytes.NewReader(body)\n\tresp, err := s.wd.stateRequest(&request{\n\t\turl:           url,\n\t\tmethod:        \"POST\",\n\t\tbody:          reader,\n\t\tcallingMethod: \"SendKeys\",\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &ElementSendKeysResponse{State: resp.State}, nil\n}\n"
  },
  {
    "path": "remote_element_test.go",
    "content": "package goselenium\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\nfunc Test_RemoteElement_IDCanBeRetrieved(t *testing.T) {\n\tel := newSeleniumElement(\"test\", nil)\n\tif el.ID() != \"test\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/* SELECTED TESTS\n */\nfunc Test_ElementSelected_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Selected()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementSelected_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Selected()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementSelected_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": true\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Selected()\n\tif err != nil || resp.State != \"success\" || resp.Selected != true {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tATTRIBUTE TESTS\n*/\nfunc Test_ElementAttribute_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Attribute(\"test\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementAttribute_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Attribute(\"test\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementAttribute_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test value\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Attribute(\"test\")\n\tif err != nil || resp.State != \"success\" || resp.Value != \"test value\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCSSVALUE TESTS\n*/\nfunc Test_ElementCSSValue_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.CSSValue(\"test\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementCSSValue_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.CSSValue(\"test\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementCSSValue_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test value\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.CSSValue(\"test\")\n\tif err != nil || resp.State != \"success\" || resp.Value != \"test value\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tTEXT TESTS\n*/\nfunc Test_ElementText_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Text()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementText_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Text()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementText_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test value\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Text()\n\tif err != nil || resp.State != \"success\" || resp.Text != \"test value\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tTAG NAME TESTS\n*/\nfunc Test_ElementTagName_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.TagName()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementTagName_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.TagName()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementTagName_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": \"test value\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.TagName()\n\tif err != nil || resp.State != \"success\" || resp.Tag != \"test value\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tRECTANGLE TESTS\n*/\nfunc Test_ElementRectangle_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Rectangle()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementRectangle_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Rectangle()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementRectangle_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": {\n\t\t\t\t\"x\": 100,\n\t\t\t\t\"y\": 200,\n\t\t\t\t\"width\": 50,\n\t\t\t\t\"height\": 50\n\t\t\t}\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Rectangle()\n\tif err != nil || resp.State != \"success\" || resp.Rectangle.X != 100 || resp.Rectangle.Height != 50 {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tENABLED TESTS\n*/\nfunc Test_ElementEnabled_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Enabled()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementEnabled_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Enabled()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementEnabled_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\",\n\t\t\t\"value\": true\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Enabled()\n\tif err != nil || resp.State != \"success\" || !resp.Enabled {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCLICK TESTS\n*/\nfunc Test_ElementClick_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Click()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementClick_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Click()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementClick_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Click()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tCLEAR TESTS\n*/\nfunc Test_ElementClear_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Clear()\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementClear_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.Clear()\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementClear_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.Clear()\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n\n/*\n\tSEND KEYS TESTS\n*/\nfunc Test_ElementSendKeys_CommunicationErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"\",\n\t\terrorToReturn: errors.New(\"An error :<\"),\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.SendKeys(\"test\")\n\tif err == nil || !IsCommunicationError(err) {\n\t\tt.Errorf(apiCommunicationErrorText)\n\t}\n}\n\nfunc Test_ElementSendKeys_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn:  \"Invalid JSON!\",\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\t_, err := el.SendKeys(\"test\")\n\tif err == nil || !IsUnmarshallingError(err) {\n\t\tt.Errorf(unmarshallingErrorText)\n\t}\n}\n\nfunc Test_ElementSendKeys_CorrectResponseIsReturned(t *testing.T) {\n\tapi := &testableAPIService{\n\t\tjsonToReturn: `{\n\t\t\t\"state\": \"success\"\n\t\t}`,\n\t\terrorToReturn: nil,\n\t}\n\n\td := setUpDriver(setUpDefaultCaps(), api)\n\td.sessionID = \"12345\"\n\n\tel := newSeleniumElement(\"0\", d)\n\tresp, err := el.SendKeys(\"test\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(correctResponseErrorText)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/alert_acceptalert_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_AlertAcceptAlert_CanAcceptAnAlertCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Create session error\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/alert.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error navigating to URL\", err)\n\t}\n\n\tresp, err := driver.AcceptAlert()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error accepting alert\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/alert_alerttext_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_AlertAlertText_CanGetTheAlertText(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/alert.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error visiting URL.\", err)\n\t}\n\n\tresp, err := driver.AlertText()\n\tif err != nil || resp.State != \"success\" || resp.Text != \"this is an alert\" {\n\t\terrorAndWrap(t, \"Error getting alert text.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/alert_dismissalert_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_AlertDismissAlert_CanDismissAnAlertCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/alert.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error visiting URL\", err)\n\t}\n\n\tresp, err := driver.DismissAlert()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Alert response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_AlertDismissAlert_DismissingAnInvalidAlertResultsInAnError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://google.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error visiting URL\", err)\n\t}\n\n\tresp, err := driver.DismissAlert()\n\tif err != nil {\n\t\tcomErr := err.(goselenium.CommunicationError)\n\t\tif comErr.Response.State != goselenium.NoSuchAlert {\n\t\t\terrorAndWrap(t, \"Incorrect result returned\", err)\n\t\t}\n\t} else {\n\t\terrorAndWrap(t, \"Incorrect result returned\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/alert_sendalerttext_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_AlertSendAlertText_CanSendAlertTextCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/prompt.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error visiting URL\", err)\n\t}\n\n\tresp, err := driver.SendAlertText(\"test\")\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error sending alert text\", err)\n\t}\n\n\t_, err = driver.AcceptAlert()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error accepting alert\", err)\n\t}\n\n\t_, err = driver.AlertText()\n\tif err != nil {\n\t\tcomErr := err.(goselenium.CommunicationError)\n\t\tif comErr.Response.State != goselenium.NoSuchAlert {\n\t\t\terrorAndWrap(t, \"Error returned was not correct\", err)\n\t\t}\n\t} else {\n\t\terrorAndWrap(t, \"Error returned was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_closewindow_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CommandCloseWindow_CanCloseTheWindow(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.CloseWindow()\n\tif err != nil || resp.State != \"success\" || len(resp.Handles) > 0 {\n\t\terrorAndWrap(t, \"Error was returned or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_maximizewindow_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CommandMaximizeWindow_CorrectResultIsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.MaximizeWindow()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was returned or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_setwindowsize_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_CommandSetWindowSize_CorrectResponseIsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tdimensions := &goselenium.Dimensions{\n\t\tWidth:  600,\n\t\tHeight: 400,\n\t}\n\tresp, err := driver.SetWindowSize(dimensions)\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was returned or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_switchtoframe_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_CommandSwitchToFrame_CorrectResponseIsReturnedByIndex(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/iframe.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.SwitchToFrame(goselenium.ByIndex(0))\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown or result was not a success\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_CommandSwitchToFrame_InvalidByResultsInAnError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/iframe.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.SwitchToFrame(goselenium.ByCSSSelector(\"iframe\"))\n\tif err == nil {\n\t\terrorAndWrap(t, \"Error was not thrown or was not the expected type.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_switchtoparentframe_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_CommandSwitchToParentFrame_CorrectResponseCanBeReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/iframe.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating.\", err)\n\t}\n\n\t_, err = driver.SwitchToFrame(goselenium.ByIndex(0))\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst switching to frame 0.\", err)\n\t}\n\n\tresp, err := driver.SwitchToParentFrame()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown or response was not a success.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_windowhandle_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CommandWindowHandle_CorrectResponseIsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.WindowHandle()\n\tif err != nil || resp.State != \"success\" || resp.Handle == \"\" {\n\t\terrorAndWrap(t, \"Error was returned or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_windowhandles_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CommandWindowHandles_WindowHandlesAreReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tresp, err := driver.WindowHandles()\n\tif err != nil || resp.State != \"success\" || resp.Handles[0] == \"\" {\n\t\terrorAndWrap(t, \"Error thrown or result was not what was expected.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/command_windowsize_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CommandWindowSize_CorrectResultIsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.WindowSize()\n\tif err != nil || resp.State != \"success\" || resp.Dimensions.Width == 0 || resp.Dimensions.Height == 0 {\n\t\terrorAndWrap(t, \"Error was returned or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/cookie_addcookie_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_CookieAddCookie_CanAddCookieWithCorrectFields(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst trying to create session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.AddCookie(&goselenium.Cookie{\n\t\tName:       \"cookie\",\n\t\tValue:      \"cookieValue\",\n\t\tPath:       \"/\",\n\t\tDomain:     \".ycombinator.com\",\n\t\tSecureOnly: false,\n\t\tHTTPOnly:   true,\n\t})\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst retrieving cookies\", err)\n\t}\n\n\tprintObjectResult(resp)\n\n}\n"
  },
  {
    "path": "test/integration_tests/cookie_allcookies_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CookieAllCookies_CanRetrieveAllCookiesFromWebPage(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst trying to create session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.AllCookies()\n\tif err != nil || resp.State != \"success\" || resp.Cookies[0].Name == \"\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst retrieving cookies\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/cookie_cookie_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CookieCookie_CanRetrieveCookieFromWebPage(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst trying to create session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.Cookie(\"__cfduid\")\n\tif err != nil || resp.State != \"success\" || resp.Cookie.Name == \"\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst retrieving cookie\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/cookie_deletecookie_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_CookieDeleteCookie_CanDeleteSpecifiedCookie(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl        string\n\t\tcookieName string\n\t}{\n\t\t{\n\t\t\turl:        \"https://news.ycombinator.com\",\n\t\t\tcookieName: \"__cfduid\",\n\t\t},\n\t\t{\n\t\t\turl:        \"https://www.google.com\",\n\t\t\tcookieName: \"CONSENT\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\tt.Errorf(\"Session creation failed\")\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\tt.Errorf(\"Navigation failed\")\n\t\t}\n\n\t\tresp, err := driver.DeleteCookie(te.cookieName)\n\t\tif err != nil || resp.State != \"success\" {\n\t\t\tt.Errorf(\"Error whilst deleting cookie or was not a success.\")\n\t\t}\n\n\t\tcookie, err := driver.Cookie(te.cookieName)\n\t\tif err != nil || cookie.Cookie.Name == te.cookieName {\n\t\t\tt.Errorf(\"Cookie still exists or an error occurred.\")\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n\nfunc Test_CookieDeleteCookie_CanDeleteAllCookies(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\tt.Errorf(\"Session creation failed\")\n\t}\n\n\t_, err = driver.Go(\"https://www.google.com\")\n\tif err != nil {\n\t\tt.Errorf(\"Navigation failed\")\n\t}\n\n\tresp, err := driver.DeleteCookie(\"\")\n\tif err != nil || resp.State != \"success\" {\n\t\tt.Errorf(\"Error whilst deleting cookie or was not a success.\")\n\t}\n\n\tcookies, err := driver.AllCookies()\n\tif err != nil || len(cookies.Cookies) != 0 {\n\t\tt.Errorf(\"Cookies still exist or error was returned.\")\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/document_executescript_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_DocumentExecuteScript_CanExecuteScriptsSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.ExecuteScript(\"return \\\"Test\\\";\")\n\tif err != nil || resp.Response != \"Test\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst executing script or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_DocumentExecuteScriptAsync_CanExecuteScriptsSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tresp, err := driver.ExecuteScriptAsync(\"var callback = arguments[arguments.length - 1]; callback('Test');\")\n\tif err != nil || resp.Response != \"Test\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst executing script or response was not correct\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/document_pagesource_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_DocumentPageSource_PageSourceIsCorrectlyRetrieved(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tsauce, err := driver.PageSource()\n\tif err != nil || len(sauce.Source) == 0 {\n\t\terrorAndWrap(t, \"Error was thrown or page source was empty\", err)\n\t}\n\n\tprintObjectResult(sauce)\n}\n"
  },
  {
    "path": "test/integration_tests/element_attribute_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementAttribute_CanRetrieveAttributeCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl  string\n\t\tby   goselenium.By\n\t\tattr string\n\t\tval  string\n\t}{\n\t\t{\n\t\t\turl:  \"https://www.google.com\",\n\t\t\tby:   goselenium.ByCSSSelector(\"input#lst-ib\"),\n\t\t\tattr: \"maxlength\",\n\t\t\tval:  \"2048\",\n\t\t},\n\t\t{\n\t\t\turl:  \"https://news.ycombinator.com\",\n\t\t\tby:   goselenium.ByCSSSelector(\"b.hnname > a\"),\n\t\t\tattr: \"href\",\n\t\t\tval:  \"news\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tatt, err := el.Attribute(te.attr)\n\t\tif err != nil || !strings.Contains(att.Value, te.val) {\n\t\t\terrorAndWrap(t, \"Error whilst retrieving attribute or attribute value was not correct\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(att)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_clear_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementClear_ElementsAreClearedSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\n\t\t\turl: \"https://bunsenapp.github.io/go-selenium/helpers/clear.html\",\n\t\t\tby:  goselenium.ByCSSSelector(\"input#should-clear\"),\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Create session failed\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Navigating to URL failed\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Retrieving element failed\", err)\n\t\t}\n\n\t\t_, err = el.Clear()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Clearing element failed\", err)\n\t\t}\n\n\t\tresp, err := el.Text()\n\t\tif err != nil || len(resp.Text) > 0 {\n\t\t\terrorAndWrap(t, \"Retrieving text failed or text was not cleared\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_click_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementClick_ClickSuccessfullyNavigates(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl      string\n\t\tby       goselenium.By\n\t\texpTitle string\n\t}{\n\t\t{\n\t\t\turl:      \"https://www.google.com\",\n\t\t\tby:       goselenium.ByLinkText(\"Privacy\"),\n\t\t\texpTitle: \"Privacy Policy – Privacy & Terms – Google\",\n\t\t},\n\t\t{\n\t\t\turl:      \"https://news.ycombinator.com\",\n\t\t\tby:       goselenium.ByLinkText(\"new\"),\n\t\t\texpTitle: \"New Links | Hacker News\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error visiting URL.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error finding element\", err)\n\t\t}\n\n\t\t_, err = el.Click()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error clicking element\", err)\n\t\t}\n\n\t\t// TODO: Unfortunate Selenium flaw - will need the helpers to get around\n\t\t// an explicit wait. Also occurs in Python library.\n\t\ttime.Sleep(1 * time.Second)\n\n\t\tresp, err := driver.Title()\n\t\tif err != nil || resp.Title != te.expTitle {\n\t\t\terrorAndWrap(t, \"Error retrieving title or title was not correct\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_cssclass_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementCSSValue_CanGetCorrectCSSValue(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl     string\n\t\tby      goselenium.By\n\t\tcssName string\n\t\tcssVal  string\n\t}{\n\t\t{\n\t\t\turl:     \"https://www.google.com\",\n\t\t\tby:      goselenium.ByCSSSelector(\"input[name='btnK']\"),\n\t\t\tcssName: \"font-family\",\n\t\t\tcssVal:  \"arial,sans-serif\",\n\t\t},\n\t\t{\n\t\t\turl:     \"https://news.ycombinator.com\",\n\t\t\tby:      goselenium.ByCSSSelector(\"a[href='news']\"),\n\t\t\tcssName: \"color\",\n\t\t\tcssVal:  \"rgb(0, 0, 0)\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tatt, err := el.CSSValue(te.cssName)\n\t\tif err != nil || !strings.Contains(att.Value, te.cssVal) {\n\t\t\tfmt.Println(att)\n\t\t\terrorAndWrap(t, \"Error whilst retrieving CSS class or value was not correct\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(att)\n\t}\n}\n\nfunc Test_ElementCSSValue_CSSValueThatDoesNotExistDoesNotCauseAnError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl     string\n\t\tby      goselenium.By\n\t\tcssName string\n\t}{\n\t\t{\n\t\t\turl:     \"https://www.google.com\",\n\t\t\tby:      goselenium.ByCSSSelector(\"input[name='btnK']\"),\n\t\t\tcssName: \"background\",\n\t\t},\n\t\t{\n\t\t\turl:     \"https://news.ycombinator.com\",\n\t\t\tby:      goselenium.ByCSSSelector(\"a[href='news']\"),\n\t\t\tcssName: \"border-radius\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tatt, err := el.CSSValue(te.cssName)\n\t\tif err != nil {\n\t\t\tfmt.Println(att)\n\t\t\terrorAndWrap(t, \"Error whilst retrieving CSS class\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(att)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_enabled_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementEnabled_EnabledElementIsReturnedCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://google.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t}\n\n\tel, err := driver.FindElement(goselenium.ByCSSSelector(\"input#lst-ib\"))\n\tif err != nil || el == nil {\n\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t}\n\n\tresp, err := el.Enabled()\n\tif err != nil || !resp.Enabled {\n\t\terrorAndWrap(t, \"Error whilst retrieving response or element was not enabled\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_ElementEnabled_DisabledElementIsReturnedCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t\texp bool\n\t}{\n\t\t{\n\t\t\turl: \"https://news.ycombinator.com\",\n\t\t\tby:  goselenium.ByCSSSelector(\"a[href='news']\"),\n\t\t\texp: true,\n\t\t},\n\t\t{\n\t\t\turl: \"https://bunsenapp.github.io/go-selenium/helpers/disabled.html\",\n\t\t\tby:  goselenium.ByCSSSelector(\"input\"),\n\t\t\texp: false,\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tresp, err := el.Enabled()\n\t\tif err != nil || resp.Enabled != te.exp {\n\t\t\terrorAndWrap(t, \"Error whilst retrieving response or the element's enabled property was not correct\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_findelement_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementFindElement_CanFindElementByCSSSelector(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByCSSSelector(\"input#lst-ib\")},\n\t\t{\"https://www.reddit.com\", goselenium.ByCSSSelector(\"input[name=q]\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByCSSSelector(\"#hnmain\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElement_CanFindElementByLinkText(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByLinkText(\"Gmail\")},\n\t\t{\"https://www.reddit.com\", goselenium.ByLinkText(\"new\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByLinkText(\"submit\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElement_CanFindElementByPartialLinkText(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByPartialLinkText(\"Gmai\")},\n\t\t{\"https://www.reddit.com\", goselenium.ByPartialLinkText(\"ew\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByPartialLinkText(\"ubmit\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElement_CanFindElementByXPath(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByXPath(\"//input[@id='lst-ib']\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByXPath(\"//b[@class='hnname']/a[@href='news']\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_findelements_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementFindElements_CanFindElementsByCSSSelector(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByCSSSelector(\"input\")},\n\t\t{\"https://www.reddit.com\", goselenium.ByCSSSelector(\"a\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByCSSSelector(\".storylink\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElements(te.by)\n\t\tif err != nil || el == nil || len(el) <= 1 {\n\t\t\terrorAndWrap(t, \"Error whilst finding elements or element was not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElements_CanFindElementsByLinkText(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.reddit.com\", goselenium.ByLinkText(\"share\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByLinkText(\"hide\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElements(te.by)\n\t\tif err != nil || el == nil || len(el) <= 1 {\n\t\t\terrorAndWrap(t, \"Error whilst finding elements or elements were not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElements_CanFindElementsByPartialLinkText(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByPartialLinkText(\"a\")},\n\t\t{\"https://www.reddit.com\", goselenium.ByPartialLinkText(\"hi\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByPartialLinkText(\"comment\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElements(te.by)\n\t\tif err != nil || el == nil || len(el) <= 1 {\n\t\t\terrorAndWrap(t, \"Error whilst finding elements or elements were not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n\nfunc Test_ElementFindElements_CanFindElementsByXPath(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t}{\n\t\t{\"https://www.google.com\", goselenium.ByXPath(\"//input\")},\n\t\t{\"https://news.ycombinator.com\", goselenium.ByXPath(\"//a\")},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElements(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding elements or element were not found\", err)\n\t\t}\n\n\t\tprintObjectResult(el)\n\n\t\tdriver.DeleteSession()\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_rectangle_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementRectangle_SizeIsReturnedCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/size.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t}\n\n\tel, err := driver.FindElement(goselenium.ByCSSSelector(\"div\"))\n\tif err != nil || el == nil {\n\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t}\n\n\tresp, err := el.Rectangle()\n\tif err != nil || resp.Rectangle.Width != 100 || resp.Rectangle.Height != 100 {\n\t\terrorAndWrap(t, \"Error was returned or element's size was not correct.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_ElementRectangle_PositionIsReturnedCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://google.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t}\n\n\tel, err := driver.FindElement(goselenium.ByCSSSelector(\"input#lst-ib\"))\n\tif err != nil || el == nil {\n\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t}\n\n\tresp, err := el.Rectangle()\n\tif err != nil || resp.Rectangle.X == 0 || resp.Rectangle.Height == 0 {\n\t\terrorAndWrap(t, \"Error was returned or element's size was not correct.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/element_selected_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementSelected_CheckedElementReturnsCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []goselenium.By{\n\t\tgoselenium.ByCSSSelector(\"input[name='i_am_checked']\"),\n\t\tgoselenium.ByCSSSelector(\"input[name='i_am_selected']\"),\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/selected.html\")\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tresp, err := el.Selected()\n\t\tif err != nil || !resp.Selected {\n\t\t\terrorAndWrap(t, \"Error was returned or element was not selected.\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n\nfunc Test_ElementSelected_UncheckedElementReturnsCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []goselenium.By{\n\t\tgoselenium.ByCSSSelector(\"input[name='i_am_not_checked']\"),\n\t\tgoselenium.ByCSSSelector(\"input[name='i_am_not_selected']\"),\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/selected.html\")\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tresp, err := el.Selected()\n\t\tif err != nil || resp.Selected {\n\t\t\terrorAndWrap(t, \"Error was returned or element was selected.\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n\nfunc Test_ElementSelected_RandomElementsDoNotError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []goselenium.By{\n\t\tgoselenium.ByCSSSelector(\"a.storylink\"),\n\t\tgoselenium.ByCSSSelector(\".title\"),\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(\"https://news.ycombinator.com\")\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tresp, err := el.Selected()\n\t\tif err != nil || resp.Selected {\n\t\t\terrorAndWrap(t, \"Error was returned or element was selected.\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_sendkeys_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementSendKeys_CanSendKeysToInputField(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://www.google.com\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error navigating to URL\", err)\n\t}\n\n\tel, err := driver.FindElement(goselenium.ByCSSSelector(\"input#lst-ib\"))\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error finding element\", err)\n\t}\n\n\t_, err = el.SendKeys(\"test\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error sending keys to element\", err)\n\t}\n\n\t_, err = el.SendKeys(goselenium.EnterKey)\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error sending enter key to element\", err)\n\t}\n\n\turl, err := driver.CurrentURL()\n\tif err != nil || !strings.Contains(url.URL, \"test\") {\n\t\terrorAndWrap(t, \"Error retrieving current URL or it did not contain the correct value\", err)\n\t}\n\n\tprintObjectResult(url)\n}\n"
  },
  {
    "path": "test/integration_tests/element_tagname_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementTagName_CanRetrieveCorrectTagName(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t\texp string\n\t}{\n\t\t{\n\t\t\turl: \"https://news.ycombinator.com\",\n\t\t\tby:  goselenium.ByCSSSelector(\"a[href='submit']\"),\n\t\t\texp: \"a\",\n\t\t},\n\t\t{\n\t\t\turl: \"https://google.com\",\n\t\t\tby:  goselenium.ByCSSSelector(\"input#lst-ib\"),\n\t\t\texp: \"input\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\tresp, err := el.TagName()\n\t\tif err != nil || resp.Tag != te.exp {\n\t\t\terrorAndWrap(t, \"Error was returned or tag name was incorrect.\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(resp)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/element_text_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementText_CorrectElementTextGetsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\ttests := []struct {\n\t\turl string\n\t\tby  goselenium.By\n\t\texp string\n\t}{\n\t\t{\n\t\t\turl: \"https://google.com\",\n\t\t\tby:  goselenium.ByCSSSelector(\"input#lst-ib\"),\n\t\t\texp: \"\",\n\t\t},\n\t\t{\n\t\t\turl: \"https://news.ycombinator.com\",\n\t\t\tby:  goselenium.ByCSSSelector(\"a[href='submit']\"),\n\t\t\texp: \"submit\",\n\t\t},\n\t}\n\tfor _, te := range tests {\n\t\tdriver := createDriver(t)\n\t\t_, err := driver.CreateSession()\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t\t}\n\n\t\t_, err = driver.Go(te.url)\n\t\tif err != nil {\n\t\t\terrorAndWrap(t, \"Error thrown whilst visiting url.\", err)\n\t\t}\n\n\t\tel, err := driver.FindElement(te.by)\n\t\tif err != nil || el == nil {\n\t\t\terrorAndWrap(t, \"Error whilst finding element or element was not found\", err)\n\t\t}\n\n\t\ttxt, err := el.Text()\n\t\tif err != nil || txt.Text != te.exp {\n\t\t\terrorAndWrap(t, \"Error whilst getting element text or text was not correct\", err)\n\t\t}\n\n\t\tdriver.DeleteSession()\n\n\t\tprintObjectResult(txt)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/helpers_elementpresent_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\t\"time\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_ElementWaitUntilElementPresent_CanSucceed(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/element-present.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error navigating to URL\", err)\n\t}\n\n\tby := goselenium.ByCSSSelector(\"#not-present-div\")\n\tresp := driver.Wait(goselenium.UntilElementPresent(by), 20*time.Second, 0)\n\tif !resp {\n\t\terrorAndWrap(t, \"Error waiting for element to be visible or it timed out\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_ElementWaitUntilElementPresent_NotFoundPriorToTimeoutFails(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/element-present.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error navigating to URL\", err)\n\t}\n\n\tby := goselenium.ByCSSSelector(\"#not-present-div\")\n\tresp := driver.Wait(goselenium.UntilElementPresent(by), 1*time.Second, 0)\n\tif resp {\n\t\terrorAndWrap(t, \"Error was not thrown when it should have been\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/helpers_untilurlis_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\t\"time\"\n\n\tgoselenium \"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_WaitUntilURLIs_WorksCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error whilst creating session\", err)\n\t}\n\n\t_, err = driver.Go(\"https://bunsenapp.github.io/go-selenium/helpers/url-change.html\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error whilst navigating\", err)\n\t}\n\n\tok := driver.Wait(goselenium.UntilURLIs(\"https://bunsenapp.github.io/test\"), 30*time.Second, 0)\n\tif !ok {\n\t\terrorAndWrap(t, \"Timeout was exceeded\", nil)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/navigate_back_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n)\n\nfunc Test_NavigateBack_NavigateBackWorksCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tgoResp, err := driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tgoResp, err = driver.Go(\"https://google.co.uk\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tbackResp, err := driver.Back()\n\tif err != nil || backResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating back or results was not a success.\", err)\n\t}\n\n\tcurrentURLResp, err := driver.CurrentURL()\n\tif err != nil || !strings.HasPrefix(currentURLResp.URL, \"https://news.ycombinator.com\") {\n\t\terrorAndWrap(t, \"Error was thrown or URL was not what it should have been.\", err)\n\t}\n\n\tprintObjectResult(currentURLResp)\n}\n"
  },
  {
    "path": "test/integration_tests/navigate_forward_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n)\n\nfunc Test_NavigateForward_NavigateFowardWorksCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tgoResp, err := driver.Go(\"https://google.co.uk\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tgoResp, err = driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tbackResp, err := driver.Back()\n\tif err != nil || backResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating backwards or results was not a success.\", err)\n\t}\n\n\tforwardResp, err := driver.Forward()\n\tif err != nil || forwardResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating forwards or result was not a success.\", err)\n\t}\n\n\tcurrentURLResp, err := driver.CurrentURL()\n\tif err != nil || !strings.HasPrefix(currentURLResp.URL, \"https://news.ycombinator.com\") {\n\t\terrorAndWrap(t, \"Error was thrown or URL was not what it should have been.\", err)\n\t}\n\n\tprintObjectResult(currentURLResp)\n}\n"
  },
  {
    "path": "test/integration_tests/navigate_go_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_NavigateGo_CanNavigateSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.Go(\"https://www.google.com\")\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown or result was not a success.\", err)\n\t}\n}\n\nfunc Test_NavigateGo_InvalidURLIsReturned(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tresp, err := driver.Go(\"www.google.com\")\n\tif err != nil {\n\t\tif !goselenium.IsInvalidURLError(err) {\n\t\t\terrorAndWrap(t, \"Error was thrown or result was not a success.\", err)\n\t\t}\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_NavigateGo_CanGetCurrentURL(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\t_, err = driver.Go(\"https://github.com/\")\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error was thrown when it shouldn't have been.\", err)\n\t}\n\n\tresp, err := driver.CurrentURL()\n\tif err != nil || resp.URL != \"https://github.com/\" {\n\t\terrorAndWrap(t, \"Error was thrown or URL was not what was sent.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/navigate_refresh_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n)\n\nfunc Test_NavigateRefresh_RefreshWorksCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tgoResp, err := driver.Go(\"https://news.ycombinator.com\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\trefreshResp, err := driver.Refresh()\n\tif err != nil || refreshResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst refreshing or result was not a success.\", err)\n\t}\n\n\tcurrentURLResp, err := driver.CurrentURL()\n\tif err != nil || !strings.HasPrefix(currentURLResp.URL, \"https://news.ycombinator.com\") {\n\t\terrorAndWrap(t, \"Error was thrown or URL was not what it should have been.\", err)\n\t}\n\n\tprintObjectResult(currentURLResp)\n}\n"
  },
  {
    "path": "test/integration_tests/navigate_title_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_NavigateTitle_TitleCanBeRetrievedSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tgoResp, err := driver.Go(\"https://google.com\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\ttitleResponse, err := driver.Title()\n\tif err != nil || titleResponse.Title != \"Google\" {\n\t\terrorAndWrap(t, \"Error was thrown or URL was not what it should have been.\", err)\n\t}\n\n\tprintObjectResult(titleResponse)\n}\n"
  },
  {
    "path": "test/integration_tests/screenshot_screenshot_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_ScreenshotScreenshot_ScreenshotCanBeTakenSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error thrown whilst creating session.\", err)\n\t}\n\n\tgoResp, err := driver.Go(\"https://google.com\")\n\tif err != nil || goResp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error was thrown whilst navigating or result was not a success.\", err)\n\t}\n\n\tscs, err := driver.Screenshot()\n\tif err != nil || scs.State != \"success\" || len(scs.EncodedImage) == 0 {\n\t\terrorAndWrap(t, \"Error thrown whilst taking screenshot.\", err)\n\t}\n\n\tdec, err := scs.ImageBytes()\n\tif err != nil || len(dec) == 0 {\n\t\terrorAndWrap(t, \"Error thrown whilst getting image bytes of screenshot.\", err)\n\t}\n\n\tprintObjectResult(dec)\n}\n"
  },
  {
    "path": "test/integration_tests/session_create_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"strings\"\n\t\"testing\"\n)\n\nfunc Test_SessionCreate_ANewSessionCanBeCreated(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\tsession, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Creation of session yielded an error.\", err)\n\t} else if session.SessionID == \"\" || session.Capabilities.BrowserName != \"firefox\" {\n\t\terrorAndWrap(t, \"Returned object was not set correctly.\", err)\n\t}\n\n\tprintObjectResult(session)\n}\n\nfunc Test_SessionCreate_TrailingSlashIsAdded(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif strings.HasSuffix(driver.DriverURL(), \"/\") || err != nil {\n\t\terrorAndWrap(t, \"Driver URL did not get a slash appended or an error occurred.\", err)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/session_delete_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_SessionDelete_CallingDeleteSessionMethodWithoutASessionIdResultsInAnError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.DeleteSession()\n\tif err == nil || !goselenium.IsSessionIDError(err) {\n\t\terrorAndWrap(t, \"Session error was not returned when it should have been.\", err)\n\t}\n}\n\nfunc Test_SessionDelete_DeleteSessionMethodWorksCorrectly(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error returned whilst creating session\", err)\n\t}\n\n\tresp, err := driver.DeleteSession()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error returned or state was not success whilst deleting session.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/session_general_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_Session_CanCreateAndDeleteSession(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Creation of session yielded an error.\", err)\n\t}\n\n\t_, err = driver.DeleteSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Creation of session yielded an error.\", err)\n\t}\n}\n\nfunc Test_Session_CanCreateSessionAndGetStatus(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Creation of session yielded an error.\", err)\n\t}\n\n\tresp, err := driver.SessionStatus()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error occurred or the state was not a success\", err)\n\t}\n}\n"
  },
  {
    "path": "test/integration_tests/session_settimeout_test.go",
    "content": "package integrationtests\n\nimport (\n\t\"testing\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n)\n\nfunc Test_SessionSetTimeout_CallingSetTimeoutWithoutSessionCausesAnError(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.SetSessionTimeout(goselenium.SessionPageLoadTimeout(20000))\n\tif err == nil || !goselenium.IsSessionIDError(err) {\n\t\terrorAndWrap(t, \"Session error was not returned.\", err)\n\t}\n}\n\nfunc Test_SessionSetTimeout_CanSetScriptTimeout(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error returned whilst creating session\", err)\n\t}\n\n\tresp, err := driver.SetSessionTimeout(goselenium.SessionScriptTimeout(20000))\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error returned or state was not success whilst setting script timeout.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_SessionSetTimeout_CanSetPageLoadTimeout(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error returned whilst creating session\", err)\n\t}\n\n\tresp, err := driver.SetSessionTimeout(goselenium.SessionPageLoadTimeout(20000))\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error returned or state was not success whilst setting page load timeout.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n\nfunc Test_SessionSetTimeout_CanSetImplicitWaitTimeout(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\t_, err := driver.CreateSession()\n\tif err != nil {\n\t\terrorAndWrap(t, \"Error returned whilst creating session\", err)\n\t}\n\n\tresp, err := driver.SetSessionTimeout(goselenium.SessionImplicitWaitTimeout(20000))\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error returned or state was not success whilst setting implicit wait timeout.\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/session_status_test.go",
    "content": "package integrationtests\n\nimport \"testing\"\n\nfunc Test_SessionStatus_CanRetrieveStatusOfDriverSuccessfully(t *testing.T) {\n\tsetUp()\n\tdefer tearDown()\n\n\tdriver := createDriver(t)\n\tresp, err := driver.SessionStatus()\n\tif err != nil || resp.State != \"success\" {\n\t\terrorAndWrap(t, \"Error occurred or state is incorrect\", err)\n\t}\n\n\tprintObjectResult(resp)\n}\n"
  },
  {
    "path": "test/integration_tests/test.go",
    "content": "package integrationtests\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strconv\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/bunsenapp/go-selenium\"\n\t\"github.com/pkg/errors\"\n)\n\nfunc setUp() {\n\tcommand := exec.Command(\"docker\", \"run\", \"-d\", \"--name=goselenium-tests\", \"-p=4444:4444\", \"selenium/standalone-firefox\")\n\tcommand.CombinedOutput()\n\ttime.Sleep(2000 * time.Millisecond)\n}\n\nfunc tearDown() {\n\tcommand := exec.Command(\"docker\", \"rm\", \"goselenium-tests\", \"-f\")\n\tcommand.CombinedOutput()\n}\n\nfunc errorAndWrap(t *testing.T, message string, oldError error) {\n\tif oldError == nil {\n\t\tt.Errorf(errors.New(message).Error())\n\t} else {\n\t\terr := errors.Wrap(oldError, message)\n\t\tt.Errorf(err.Error())\n\t}\n}\n\nfunc printObjectResult(obj interface{}) {\n\tenvResult := os.Getenv(\"GOSELENIUM_TEST_DETAIL\")\n\tshouldShowDetailedResults, err := strconv.ParseBool(envResult)\n\tif shouldShowDetailedResults && err == nil {\n\t\tfmt.Println(fmt.Sprintf(\"Object returned: %+v\", obj))\n\t}\n}\n\nfunc createDriver(t *testing.T) goselenium.WebDriver {\n\tcaps := goselenium.Capabilities{}\n\tcaps.SetBrowser(goselenium.FirefoxBrowser())\n\n\tdriver, err := goselenium.NewSeleniumWebDriver(\"http://localhost:4444/wd/hub/\", caps)\n\tif err != nil {\n\t\tt.Errorf(\"Driver creation threw an error.\")\n\t}\n\n\treturn driver\n}\n"
  },
  {
    "path": "web_driver.go",
    "content": "package goselenium\n\nimport \"time\"\n\n// Keyboard keys converted from the ASCII code.\nconst (\n\tUnidentifiedKey   = string('\\uE000')\n\tCancelKey         = string('\\uE001')\n\tHelpKey           = string('\\uE002')\n\tBackspaceKey      = string('\\uE003')\n\tTabKey            = string('\\uE004')\n\tClearKey          = string('\\uE005')\n\tReturnKey         = string('\\uE006')\n\tEnterKey          = string('\\uE007')\n\tShiftKey          = string('\\uE008')\n\tControlKey        = string('\\uE009')\n\tAltKey            = string('\\uE00A')\n\tPauseKey          = string('\\uE00B')\n\tEscapeKey         = string('\\uE00C')\n\tSpaceKey          = string('\\uE00D')\n\tPageUpKey         = string('\\uE00E')\n\tPageDownKey       = string('\\uE00F')\n\tEndKey            = string('\\uE010')\n\tHomeKey           = string('\\uE011')\n\tArrowLeftKey      = string('\\uE012')\n\tArrowUpKey        = string('\\uE013')\n\tArrowRightKey     = string('\\uE014')\n\tArrowDownKey      = string('\\uE015')\n\tInsertKey         = string('\\uE016')\n\tDeleteKey         = string('\\uE017')\n\tSemiColonKey      = string('\\uE018')\n\tEqualsKey         = string('\\uE019')\n\tAsteriskKey       = string('\\uE024')\n\tPlusKey           = string('\\uE025')\n\tCommaKey          = string('\\uE026')\n\tMinusKey          = string('\\uE027')\n\tPeriodKey         = string('\\uE028')\n\tForwardSlashKey   = string('\\uE029')\n\tF1Key             = string('\\uE031')\n\tF2Key             = string('\\uE032')\n\tF3Key             = string('\\uE033')\n\tF4Key             = string('\\uE034')\n\tF5Key             = string('\\uE035')\n\tF6Key             = string('\\uE036')\n\tF7Key             = string('\\uE037')\n\tF8Key             = string('\\uE038')\n\tF9Key             = string('\\uE039')\n\tF10Key            = string('\\uE03A')\n\tF11Key            = string('\\uE03B')\n\tF12Key            = string('\\uE03C')\n\tMetaKey           = string('\\uE03D')\n\tZenkakuHankakuKey = string('\\uE040')\n)\n\n// Error codes that are returned from Selenium. Infer that the\n// type of the error returned is CommunicationError, then do a comparison\n// on the err.Response.State field to one of the below constants.\nconst (\n\tElementNotSelectable   = \"element not selectable\"\n\tElementNotInteractable = \"element not interactable\"\n\tInsecureCertificate    = \"insecure certificate\"\n\tInvalidArgument        = \"invalid argument\"\n\tInvalidCookieDomain    = \"invalid cookie domain\"\n\tInvalidCoordinates     = \"invalid coordinates\"\n\tInvalidElementState    = \"invalid element state\"\n\tInvalidSelector        = \"invalid selector\"\n\tInvalidSessionID       = \"invalid session id\"\n\tJavascriptError        = \"javascript error\"\n\tMoveTargetOutOfBounds  = \"move target out of bounds\"\n\tNoSuchAlert            = \"no such alert\"\n\tNoSuchCookie           = \"no such cookie\"\n\tNoSuchElement          = \"no such element\"\n\tNoSuchFrame            = \"no such frame\"\n\tNoSuchWindow           = \"no such window\"\n\tScriptTimeout          = \"script timeout\"\n\tSessionNotCreated      = \"session not created\"\n\tStaleElementReference  = \"stale element reference\"\n\tTimeoutError           = \"timeout\"\n\tUnableToSetCookie      = \"unable to set cookie\"\n\tUnableToCaptureScreen  = \"unable to capture screen\"\n\tUnexpectedAlertOpen    = \"unexpected alert open\"\n\tUnknownCommand         = \"unknown command\"\n\tUnknownError           = \"unknown error\"\n\tUnknownMethod          = \"unknown method\"\n\tUnsupportedOperation   = \"unsupported operation\"\n)\n\n// WebDriver is an interface which adheres to the W3C specification\n// for WebDrivers (https://w3c.github.io/webdriver/webdriver-spec.html).\ntype WebDriver interface {\n\t/*\n\t\tPROPERTY ACCESS METHODS\n\t*/\n\n\t// DriverURL returns the URL where the W3C compliant web driver is hosted.\n\tDriverURL() string\n\n\t/*\n\t\tSESSION METHODS\n\t*/\n\n\t// CreateSession creates a session in the remote driver with the\n\t// desired capabilities.\n\tCreateSession() (*CreateSessionResponse, error)\n\n\t// DeleteSession deletes the current session associated with the web driver.\n\tDeleteSession() (*DeleteSessionResponse, error)\n\n\t// SessionStatus gets the status about whether a remove end is in a state\n\t// which it can create new sessions.\n\tSessionStatus() (*SessionStatusResponse, error)\n\n\t// SetSessionTimeout sets a timeout for one of the 3 options.\n\t// Call SessionScriptTimeout() to generate a script timeout.\n\t// Call SessionPageLoadTimeout() to generate a page load timeout.\n\t// Call SessionImplicitWaitTimeout() to generate an implicit wait timeout.\n\tSetSessionTimeout(to Timeout) (*SetSessionTimeoutResponse, error)\n\n\t/*\n\t\tNAVIGATION METHODS\n\t*/\n\n\t// Go forces the browser to perform a GET request on a URL.\n\tGo(url string) (*GoResponse, error)\n\n\t// CurrentURL returns the current URL of the top level browsing context.\n\tCurrentURL() (*CurrentURLResponse, error)\n\n\t// Back instructs the web driver to go one step back in the page history.\n\tBack() (*BackResponse, error)\n\n\t// Forward instructs the web driver to go one step forward in the page history.\n\tForward() (*ForwardResponse, error)\n\n\t// Refresh instructs the web driver to refresh the page that it is currently on.\n\tRefresh() (*RefreshResponse, error)\n\n\t// Title gets the title of the current page of the web driver.\n\tTitle() (*TitleResponse, error)\n\n\t/*\n\t\tCOMMAND METHODS\n\t*/\n\n\t// WindowHandle retrieves the current active browsing string for the current session.\n\tWindowHandle() (*WindowHandleResponse, error)\n\n\t// CloseWindow closes the current active window (see WindowHandle() for what\n\t// window that will be).\n\tCloseWindow() (*CloseWindowResponse, error)\n\n\t// SwitchToWindow switches the current browsing context to a specified window\n\t// handle.\n\tSwitchToWindow(handle string) (*SwitchToWindowResponse, error)\n\n\t// WindowHandles gets all of the window handles for the current session.\n\t// To retrieve the currently active window handle, see WindowHandle().\n\tWindowHandles() (*WindowHandlesResponse, error)\n\n\t// SwitchToFrame switches to a frame determined by the \"by\" parameter.\n\t// You can use ByIndex to find the frame to switch to. Any other\n\t// By implementation will yield an InvalidByParameter error.\n\tSwitchToFrame(by By) (*SwitchToFrameResponse, error)\n\n\t// SwitchToParentFrame switches to the parent of the current top level\n\t// browsing context.\n\tSwitchToParentFrame() (*SwitchToParentFrameResponse, error)\n\n\t// WindowSize retrieves the current browser window size for the\n\t// active session.\n\tWindowSize() (*WindowSizeResponse, error)\n\n\t// SetWindowSize sets the current browser window size for the active\n\t// session.\n\tSetWindowSize(dimensions *Dimensions) (*SetWindowSizeResponse, error)\n\n\t// Maximize increases the current browser window to its maximum size.\n\tMaximizeWindow() (*MaximizeWindowResponse, error)\n\n\t/*\n\t\tELEMENT METHODS\n\t*/\n\n\t// FindElement finds an element via a By implementation (i.e. CSS selector,\n\t// x-path). Attempting to find via index will result in an argument error\n\t// being thrown.\n\tFindElement(by By) (Element, error)\n\n\t// FindElements works the same way as FindElement but can return more than\n\t// one result.\n\tFindElements(by By) ([]Element, error)\n\n\t/*\n\t\tDOCUMENT HANDLING METHODS\n\t*/\n\n\t// PageSource retrieves the outerHTML value of the current URL.\n\tPageSource() (*PageSourceResponse, error)\n\n\t// ExecuteScript executes a Javascript script on the currently active\n\t// page.\n\tExecuteScript(script string) (*ExecuteScriptResponse, error)\n\n\t// ExecuteScriptAsync executes a Javascript script asynchronously on the\n\t// currently active page. If you do not have experience with this call,\n\t// there is an example below.\n\t//\n\t// The async handler runs on the concept of a callback; meaning it will run\n\t// your code asynchronously and if it completes, will call the callback.\n\t//\n\t// Selenium helpfully provides a callback function which is passed in\n\t// to the 'arguments' array that you can access within your script. The\n\t// callback function is always the LAST element of the array. You can\n\t// access it like the below:\n\t//\t\tvar callback = arguments[arguments.length - 1];\n\t// The callback function also accepts one argument as a parameter, this\n\t// can be anything and will be assigned to the Response property of\n\t// ExecuteScriptResponse.\n\t//\n\t// An example:\n\t//\t\tvar callback = arguments[arguments.length - 1];\n\t//\t\tdoLongWindedTask();\n\t//\t\tcallback();\n\tExecuteScriptAsync(script string) (*ExecuteScriptResponse, error)\n\n\t/*\n\t\tCOOKIE METHODS\n\t*/\n\n\t// AllCookies returns all cookies associated with the active URL of the\n\t// current browsing context.\n\tAllCookies() (*AllCookiesResponse, error)\n\n\t// Cookie gets a single named cookie associated with the active URL of the\n\t// current browsing context.\n\tCookie(name string) (*CookieResponse, error)\n\n\t// AddCookie adds a cookie to the current browsing context.\n\tAddCookie(c *Cookie) (*AddCookieResponse, error)\n\n\t// DeleteCookie deletes a cookie from the current browsing session. If name\n\t// is passed as an empty string, all cookies for the current address will\n\t// be deleted.\n\tDeleteCookie(name string) (*DeleteCookieResponse, error)\n\n\t/*\n\t\tALERT METHODS\n\t*/\n\n\t// DismissAlert dismisses an alert if there is one present. If not, it will\n\t// throw an error.\n\tDismissAlert() (*DismissAlertResponse, error)\n\n\t// AcceptAlertResponse accepts an alert if there is one present. If not,\n\t// it will throw an error.\n\tAcceptAlert() (*AcceptAlertResponse, error)\n\n\t// AlertText gets the text associated with the current alert. If there is\n\t// not an alert, it will throw an error.\n\tAlertText() (*AlertTextResponse, error)\n\n\t// SendAlertText enters the text specified into the value box.\n\t//\n\t// If the prompt is of type 'alert' or 'confirm', a communication error\n\t// with code 'element not interactable' will be returned.\n\t//\n\t// If the prompt is anything other than 'prompt', a communication error with\n\t// code 'unsupported operation' will be returned.\n\tSendAlertText(text string) (*SendAlertTextResponse, error)\n\n\t/*\n\t\tSCREEN CAPTURE METHODS\n\t*/\n\n\t// Screenshot takes a screenshot of the window of the current top level\n\t// browsing context. The image returned will be a PNG image.\n\tScreenshot() (*ScreenshotResponse, error)\n\n\t/*\n\t\tHELPER METHODS\n\t*/\n\n\t// Wait repeats an action until the action yields a valid result or\n\t// until the timeout is reached. If the timeout is reached without\n\t// the until function returning a satisfactory result, this method\n\t// will return false.\n\t//\n\t// time.Sleep will be called with the sleep parameter after every\n\t// u iteration.\n\tWait(u Until, timeout time.Duration, sleep time.Duration) bool\n}\n\n// Element is an interface which specifies what all WebDriver elements\n// must do. Any requests which involve this element (i.e. FindElements that\n// are children of the current element) will be specified. Anything not related\n// will exist within the WebDriver interface/implementation.\ntype Element interface {\n\t// ID is the assigned ID for the element returned from the Selenium driver.\n\tID() string\n\n\t// Selected gets whether or not the current element is selected. This only\n\t// makes sense for inputs such as radio buttons and checkboxes.\n\tSelected() (*ElementSelectedResponse, error)\n\n\t// Attribute retrieves an attribute (i.e. href, class) of the current\n\t// active element.\n\tAttribute(att string) (*ElementAttributeResponse, error)\n\n\t// CSSValue retrieves a CSS property associated with the current element.\n\t// As an example, this could be the 'background' or 'font-family' properties.\n\tCSSValue(prop string) (*ElementCSSValueResponse, error)\n\n\t// Text gets the value of element.innerText for the current element.\n\tText() (*ElementTextResponse, error)\n\n\t// TagName gets the HTML element name (i.e. p, div) of the currently selected\n\t// element.\n\tTagName() (*ElementTagNameResponse, error)\n\n\t// Rectangle gets the dimensions and co-ordinates of the currently selected\n\t// element.\n\tRectangle() (*ElementRectangleResponse, error)\n\n\t// Enabled gets whether or not the current selected elemented is enabled.\n\tEnabled() (*ElementEnabledResponse, error)\n\n\t// Click clicks the currently selected element. Please note, you may have to\n\t// implement your own wait to ensure the page actually navigates. This is due to\n\t// Selenium having no idea whether or not your click will be interrupted by JS.\n\t// Alternatively, you can use the WaitUntil(TitleEquals(\"title\"), 20) to\n\t// automatically wait until the page title has changed.\n\tClick() (*ElementClickResponse, error)\n\n\t// Clear clears the currently selected element according to the specification.\n\tClear() (*ElementClearResponse, error)\n\n\t// SendKeys sends a set of keystrokes to the currently selected element.\n\tSendKeys(keys string) (*ElementSendKeysResponse, error)\n}\n\n// Timeout is an interface which specifies what all timeout requests must follow.\ntype Timeout interface {\n\t// Type is the type of the timeout that is being used.\n\tType() string\n\n\t// Timeout is the timeout in milliseconds.\n\tTimeout() int\n}\n\n// By is an interface that defines what all 'ByX' methods must return.\ntype By interface {\n\t// Type is the type of by (i.e. id, xpath, class, name, index).\n\tType() string\n\n\t// Value is the actual value to retrieve something by (i.e. #test, 1).\n\tValue() interface{}\n}\n"
  }
]