Not everything works but added most of the old features
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Firefox;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using OpenQA.Selenium.Support.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -16,7 +18,7 @@ namespace Test_Merge
|
||||
{
|
||||
public const string COOKIE_HOST = ".formula1.com";
|
||||
public const string PYTHON_COOKIE_RETRIEVAL_FILENAME = "recoverCookiesCSV.py";
|
||||
public const string GECKODRIVER_FILENAME = @"geckodriver-v0.27.0-win32\geckodriver.exe";
|
||||
public const string GECKODRIVER_FILENAME = @"geckodriver-v0.27.0-win64\geckodriver.exe";
|
||||
//BE CAREFULL IF YOU CHANGE IT HERE YOU NEED TO CHANGE IT IN THE PYTHON SCRIPT TOO
|
||||
public const string COOKIES_CSV_FILENAME = "cookies.csv";
|
||||
|
||||
@@ -82,20 +84,29 @@ namespace Test_Merge
|
||||
}
|
||||
public async Task<int> Start()
|
||||
{
|
||||
var service = FirefoxDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory + @"geckodriver-v0.27.0-win64\geckodriver.exe");
|
||||
Ready = false;
|
||||
|
||||
string loginCookieName = "login";
|
||||
string loginSessionCookieName = "login-session";
|
||||
string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName);
|
||||
string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName);
|
||||
|
||||
int windowWidth = 1920;
|
||||
int windowHeight = 1200;
|
||||
|
||||
var service = FirefoxDriverService.CreateDefaultService(GECKODRIVER_FILENAME);
|
||||
service.Host = "127.0.0.1";
|
||||
service.Port = 5555;
|
||||
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
options.AcceptInsecureCertificates = true;
|
||||
options.AddArgument("--headless");
|
||||
options.AddArgument("--width=1920");
|
||||
options.AddArgument("--height=1200");
|
||||
options.AddArgument("--width="+windowWidth);
|
||||
options.AddArgument("--height="+windowHeight);
|
||||
|
||||
try
|
||||
{
|
||||
Driver = new FirefoxDriver(service, options);
|
||||
Ready = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -103,27 +114,132 @@ namespace Test_Merge
|
||||
return 101;
|
||||
}
|
||||
|
||||
Driver.Navigate().GoToUrl("https://f1tv.formula1.com/");
|
||||
Thread.Sleep(2000);
|
||||
Screenshot("AAAAAAAAAAA");
|
||||
Actions actions = new Actions(Driver);
|
||||
var loginCookie = new Cookie(loginCookieName, loginCookieValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5));
|
||||
var loginSessionCookie = new Cookie(loginSessionCookieName, loginSessionValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5));
|
||||
|
||||
Driver.Navigate().GoToUrl("https://f1tv.formula1.com/");
|
||||
|
||||
Driver.Manage().Cookies.AddCookie(loginCookie);
|
||||
Driver.Manage().Cookies.AddCookie(loginSessionCookie);
|
||||
|
||||
try
|
||||
{
|
||||
Driver.Navigate().GoToUrl(GrandPrixUrl);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//The url is not a valid url
|
||||
Driver.Dispose();
|
||||
return 103;
|
||||
}
|
||||
|
||||
//Waits for the page to fully load
|
||||
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);
|
||||
|
||||
//Removes the cookie prompt
|
||||
try
|
||||
{
|
||||
IWebElement conscentButton = Driver.FindElement(By.Id("truste-consent-button"));
|
||||
conscentButton.Click();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Could not locate the cookie button
|
||||
Driver.Dispose();
|
||||
return 104;
|
||||
}
|
||||
|
||||
//Again waits for the page to fully load (when you accept cookies it takes a little time for the page to load)
|
||||
//Cannot use The timeout because the feed loading is not really loading so there is not event or anything
|
||||
Thread.Sleep(5000);
|
||||
|
||||
//Switches to the Data channel
|
||||
try
|
||||
{
|
||||
IWebElement dataChannelButton = Driver.FindElement(By.ClassName("data-button"));
|
||||
dataChannelButton.Click();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//If the data button does not exists its because the user is not connected
|
||||
Screenshot("ERROR102");
|
||||
Driver.Dispose();
|
||||
return 102;
|
||||
}
|
||||
|
||||
//Open settings
|
||||
// Press the space key, this should make the setting button visible
|
||||
// It does not matter if the feed is paused because when changing channel it autoplays
|
||||
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
|
||||
//Clicks on the settings Icon
|
||||
|
||||
int tries = 0;
|
||||
bool success = false;
|
||||
while (tries < 50 && !success)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
try
|
||||
{
|
||||
IWebElement settingsButton = Driver.FindElement(By.ClassName("bmpui-ui-settingstogglebutton"));
|
||||
settingsButton.Click();
|
||||
IWebElement selectElement = Driver.FindElement(By.ClassName("bmpui-ui-videoqualityselectbox"));
|
||||
SelectElement select = new SelectElement(selectElement);
|
||||
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
|
||||
selectOption.Click();
|
||||
success = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Sometimes it can crash because it could not get the options to show up in time. When it happens just retry
|
||||
success = false;
|
||||
tries++;
|
||||
}
|
||||
}
|
||||
|
||||
if(success = false)
|
||||
{
|
||||
Screenshot("ERROR105");
|
||||
Driver.Dispose();
|
||||
return 105;
|
||||
}
|
||||
|
||||
|
||||
//Makes the feed fullscreen
|
||||
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
|
||||
try
|
||||
{
|
||||
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
|
||||
fullScreenButton.Click();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Screenshot("ERROR106");
|
||||
Driver.Dispose();
|
||||
return 106;
|
||||
}
|
||||
|
||||
//STARTUP FINISHED READY TO SCREENSHOT
|
||||
Ready = true;
|
||||
return 0;
|
||||
}
|
||||
public Bitmap Screenshot(string name = "TEST")
|
||||
{
|
||||
Bitmap result = new Bitmap(100, 100);
|
||||
if (Ready)
|
||||
Bitmap result = new Bitmap(4242, 6969);
|
||||
try
|
||||
{
|
||||
//IWebElement element = Driver.FindElement(By.Id("bitmovinplayer-video-slave-embeddedPlayer"));
|
||||
//Screenshot scrsht = ((ITakesScreenshot)element).GetScreenshot();
|
||||
Screenshot scrsht = ((ITakesScreenshot)Driver).GetScreenshot();
|
||||
|
||||
byte[] screenshotBytes = Convert.FromBase64String(scrsht.AsBase64EncodedString);
|
||||
MemoryStream stream = new MemoryStream(screenshotBytes);
|
||||
|
||||
result = new Bitmap(stream);
|
||||
result.Save(name + ".png");
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Nothing for now
|
||||
}
|
||||
result.Save(name+".png");
|
||||
return result;
|
||||
}
|
||||
public void Stop()
|
||||
|
||||
@@ -329,6 +329,9 @@ namespace Test_Merge
|
||||
case 105:
|
||||
message = "Error " + errorCode + " There has been an error trying to emulate button presses. Please try again";
|
||||
break;
|
||||
case 106:
|
||||
message = "Error " + errorCode + " There has been an error trying to emulate button presses. Please try again";
|
||||
break;
|
||||
default:
|
||||
message = "Could not start the emulator Error " + errorCode;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user