Skip to content

Commit

Permalink
Merge pull request #8 from pmahend1/dev
Browse files Browse the repository at this point in the history
changes and fixes
  • Loading branch information
pmahend1 authored Sep 29, 2020
2 parents ca9a6a7 + 3560532 commit 3d47d6c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 19 deletions.
8 changes: 8 additions & 0 deletions .Net Core/MSRewards/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using OpenQA.Selenium.DevTools.DOM;

namespace MSRewards
{
public static class Constants
Expand All @@ -24,6 +26,12 @@ public static class Constants

public const string IdSIButton9 = "idSIButton9";

public const string EdgeUserAgentArgument = "--user-agent";

public const string MHamburger = "mHamburger";

public const string HbS = "hb_s";

public const string TitleDetailXPath = ".//div[@class='title-detail']";

public const string PointDetailXpath = ".//p[@class='pointsDetail c-subheading-3 ng-binding']";
Expand Down
91 changes: 72 additions & 19 deletions .Net Core/MSRewards/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private async Task Login(IWebDriver driverlocal, WebDriverWait localwait)
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
passwordEntry.SendKeys(password);

Expand All @@ -99,17 +100,17 @@ private async Task Login(IWebDriver driverlocal, WebDriverWait localwait)
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
try
{
var yesButton = localwait.Until(d => d.FindElement(By.Id(Constants.IdSIButton9)));
yesButton?.Click();
}
catch (Exception ex2)
{

Debug.WriteLine(ex2.Message);
Debug.WriteLine(ex2.StackTrace);
}

}

await Task.Delay(3000);
Expand Down Expand Up @@ -153,9 +154,9 @@ private async Task Run(bool useFirefox = false)
{
Console.WriteLine("Starting Bing Search for " + keyvalue.Key);
await BingSearch(keyvalue.Key, current, expected, useFirefox);
Environment.Exit(0);
}
}
Environment.Exit(0);
}

private Dictionary<RewardType, (int x, int y)> CheckBreakDown(IWebDriver webDriver, WebDriverWait waiter)
Expand All @@ -177,7 +178,7 @@ private async Task Run(bool useFirefox = false)
try
{
var pointSplits = pointDetailsList.FirstOrDefault()?.Text?.Replace(" ", "").Split("/");
if (pointSplits != null)
if (pointSplits != null && pointSplits?.Length >= 2)
{
int.TryParse(pointSplits[0].Trim(), out var current);
int.TryParse(pointSplits[1].Trim(), out var total);
Expand All @@ -197,7 +198,8 @@ private async Task Run(bool useFirefox = false)
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.InnerException?.Message);
Console.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
return result;
Expand All @@ -217,26 +219,50 @@ private async Task BingSearch(RewardType rewardType, int current, int target, bo
UseChromium = true,
};

var edgeDriver = new EdgeDriver(options);
if (rewardType == RewardType.Mobile)
options.AddArgument($"{ Constants.EdgeUserAgentArgument}={Constants.MobileUserAgent}");

var edgeDriver = new EdgeDriver(options);
edgeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
var edgeWait = new WebDriverWait(edgeDriver, TimeSpan.FromSeconds(60));

await Login(edgeDriver, edgeWait);

Search(edgeDriver, edgeWait, Constants.BingSearchURL + "Give me Edge points");
Search(edgeDriver, edgeWait, Constants.BingSearchURL + "Give me Edge points" );

await Task.Delay(4000);
await Task.Delay(2000);

var id_p = edgeWait.Until(d => d.FindElement(By.Id(Constants.ID_P)));
if (id_p != null)
try
{
id_p?.Click();
if (rewardType == RewardType.Mobile)
{
var hamburg = edgeWait.Until(d => d.FindElement(By.Id(Constants.MHamburger)));
hamburg?.Click();

var signin = edgeWait.Until(d => d.FindElement(By.Id(Constants.HbS)));
signin?.Click();

await Task.Delay(3000);
}
else
{
var id_p = edgeWait.Until(d => d.FindElement(By.Id(Constants.ID_P)));
if (id_p != null)
{
id_p?.Click();
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}

while (current < target)
{
Search(edgeDriver, edgeWait, Constants.BingSearchURL + wordList[rand.Next(wordList.Count)]);
var nextInt = rand.Next(wordList.Count);
Search(edgeDriver, edgeWait, Constants.BingSearchURL + wordList[nextInt <= wordList.Count ? nextInt : 0]);
current += 5;
if (current >= target)
{
Expand All @@ -257,27 +283,53 @@ private async Task BingSearch(RewardType rewardType, int current, int target, bo
else
{
var options = new FirefoxOptions();
TimeSpan timeout = TimeSpan.FromSeconds(60);
if (rewardType == RewardType.Mobile)
{
options.SetPreference(Constants.UserAgentKey, Constants.MobileUserAgent);
timeout = TimeSpan.FromSeconds(30);
}

options.SetPreference(Constants.PrivateBrowsingKey, true);
using var firefoxDriver = new FirefoxDriver(options);
WebDriverWait driverWait = new WebDriverWait(firefoxDriver, TimeSpan.FromSeconds(120));
WebDriverWait driverWait = new WebDriverWait(firefoxDriver, timeout);
await Login(firefoxDriver, driverWait);

firefoxDriver.Navigate().GoToUrl(Constants.BingSearchURL + "Give me edge points");

await Task.Delay(4000);
await Task.Delay(2000);

var id_p = driverWait.Until(d => d.FindElement(By.Id(Constants.ID_P)));
if (id_p != null)
try
{
id_p.Click();
if (rewardType == RewardType.Mobile)
{
var hamburg = driverWait.Until(d => d.FindElement(By.Id(Constants.MHamburger)));
hamburg?.Click();

var signin = driverWait.Until(d => d.FindElement(By.Id(Constants.HbS)));
signin?.Click();

await Task.Delay(3000);
}
else
{
var id_p = driverWait.Until(d => d.FindElement(By.Id(Constants.ID_P)));
if (id_p != null)
{
id_p.Click();
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}

while (current < target)
{
Search(firefoxDriver, driverWait, Constants.BingSearchURL + wordList[rand.Next(wordList.Count)]);
var nextInt = rand.Next(wordList.Count);
Search(firefoxDriver, driverWait, Constants.BingSearchURL + wordList[nextInt <= wordList.Count ? nextInt : 0]);
current += 5;
if (current >= target)
{
Expand Down Expand Up @@ -313,7 +365,8 @@ private void Search(IWebDriver driver, WebDriverWait wait, string url)
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.InnerException?.Message);
Console.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
}
Expand Down

0 comments on commit 3d47d6c

Please sign in to comment.