Created
August 2, 2020 11:52
-
-
Save BashkaMen/5d2479949ef5eee5614880439fd8b4ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type BuilderStep = | |
| | SetupProxy = 1 | |
| | SetupTimeouts = 2 | |
| type DriverBuilder() = | |
| let steps = Dictionary() | |
| let driverOpt = ChromeOptions() | |
| do | |
| driverOpt.AddAdditionalCapability("enableVNC", true, true); | |
| driverOpt.AddAdditionalCapability("screenResolution", "1920x1080x24", true); | |
| driverOpt.AddArgument("--no-sandbox"); | |
| member this.Buid(remoteDriverUrl) = async { | |
| let url = remoteDriverUrl + "/wd/hub" |> Uri | |
| let driver = new RemoteWebDriver(url, driverOpt) | |
| steps | |
| |> Seq.sortBy (fun s -> s.Key) | |
| |> Seq.iter (fun s -> s.Value(driver)) | |
| driver.Manage().Window.Maximize() | |
| return driver | |
| } | |
| member this.WithSessionName(name) = | |
| driverOpt.AddAdditionalCapability("name", name, true) | |
| this | |
| member this.WithTimeouts(findElement, pageLoad) = | |
| let applyTimeouts (driver: IWebDriver) = | |
| driver.Manage().Timeouts().PageLoad <- pageLoad | |
| driver.Manage().Timeouts().ImplicitWait <- findElement | |
| steps.Add(BuilderStep.SetupTimeouts, applyTimeouts) | |
| this | |
| member this.WithProxy(address, port, login, pass) = | |
| driverOpt.AddExtension(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/Proxy-Auto-Auth_v2.0.crx")) | |
| driverOpt.AddArgument(sprintf "--proxy-server=%s:%i" address port) | |
| let applyProxy (driver: IWebDriver) = | |
| if driver.Url = "data;," then | |
| driver.Close() | |
| driver.SwitchTo().Window (Seq.head driver.WindowHandles) |> ignore | |
| Thread.Sleep(500) | |
| driver.FindElement(By.Id("login")).Clear() | |
| driver.FindElement(By.Id("login")).SendKeys(login) | |
| driver.FindElement(By.Id("password")).Clear() | |
| driver.FindElement(By.Id("password")).SendKeys(pass) | |
| driver.FindElement(By.Id("save")).Click() | |
| Thread.Sleep(500) | |
| steps.Add(BuilderStep.SetupProxy, applyProxy) | |
| this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment