|
using OpenQA.Selenium; |
|
using OpenQA.Selenium.Edge; |
|
|
|
internal class Runner |
|
{ |
|
private int index; |
|
private bool headless; |
|
private string url; |
|
private IWebDriver driver; |
|
private Thread thread; |
|
|
|
public Runner(int index, bool headless, string url) |
|
{ |
|
this.index = index; |
|
this.url = url; |
|
|
|
driver = CreateDriver(index, headless); |
|
thread = new Thread(() => Navigate(driver, url, index)); |
|
} |
|
|
|
public void Start() |
|
{ |
|
Console.WriteLine($"DRIVER {index} START"); |
|
thread.Start(); |
|
Console.WriteLine($"DRIVER {index} STARTED"); |
|
} |
|
|
|
public void Join() |
|
{ |
|
Console.WriteLine($"DRIVER {index} JOIN"); |
|
thread.Join(); |
|
Console.WriteLine($"DRIVER {index} JOINED"); |
|
} |
|
|
|
public void Quit() |
|
{ |
|
Console.WriteLine($"DRIVER {index} QUIT"); |
|
driver.Quit(); |
|
driver.Dispose(); |
|
Console.WriteLine($"DRIVER {index} QUITTED"); |
|
} |
|
|
|
public static EdgeDriver CreateDriver(int index, bool headless = false) |
|
{ |
|
var service = EdgeDriverService.CreateDefaultService(@".", @"msedgedriver.exe"); |
|
service.Start(); |
|
Console.WriteLine($"service.Port: {service.Port}"); |
|
|
|
var options = new EdgeOptions(); |
|
|
|
if (headless) |
|
options.AddArgument("headless"); |
|
|
|
options.AddArguments( |
|
"--disable-extensions", |
|
"--window-size=1920,1080", |
|
"inprivate", |
|
"no-sandbox", |
|
"inprivate", |
|
"disable-gpu", |
|
"ignore-certificate-errors", |
|
"no-default-browser-check", |
|
"disable-web-security", |
|
"allow-insecure-localhost", |
|
"allow-running-insecure-content", |
|
"acceptInsecureCerts=true", |
|
"proxy-server='direct://'", |
|
"proxy-bypass-list=*", |
|
"disable-extensions", |
|
"disable-infobars" |
|
); |
|
|
|
options.AddArgument($"remote-debugging-port={9222+index}"); |
|
|
|
options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; |
|
options.LeaveBrowserRunning = false; |
|
options.AcceptInsecureCertificates = true; |
|
|
|
options.AddArgument($@"--user-data-dir={Directory.GetCurrentDirectory()}\tmp\prof-{index}"); |
|
|
|
return new EdgeDriver(service, options); |
|
} |
|
|
|
public static void Navigate(IWebDriver driver, string url, int index) |
|
{ |
|
driver.Navigate().GoToUrl(url); |
|
driver.Manage().Window.Maximize(); |
|
Thread.Sleep(1000); |
|
((EdgeDriver)driver).GetScreenshot().SaveAsFile($@"tmp\{index}.png"); |
|
Thread.Sleep(1000); |
|
} |
|
} |