Skip to content

Commit

Permalink
update selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
cpatsel committed Jul 15, 2016
1 parent 157db6d commit e7d2d2d
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 18 deletions.
Binary file modified ShowdownBot.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions ShowdownBot/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void initialise(bool browser=true)
FirefoxProfileManager pm = new FirefoxProfileManager();
FirefoxProfile ffp = pm.GetProfile(Global.FF_PROFILE);
mainBrowser = new FirefoxDriver(ffp);

mainBrowser.Manage().Timeouts().ImplicitlyWait(System.TimeSpan.FromSeconds(10));
DesiredCapabilities d = new DesiredCapabilities();
}

Expand Down Expand Up @@ -181,6 +181,7 @@ public void Kill()
}
c.write("Bot is shutting down.");
// changeState(State.BUSY);
closeBrowser();
isRunning = false;


Expand Down Expand Up @@ -272,7 +273,6 @@ private void Update()
private bool OpenSite(string site)
{
mainBrowser.Navigate().GoToUrl(site);
mainBrowser.Manage().Timeouts().ImplicitlyWait(System.TimeSpan.FromSeconds(10));
mainBrowser.FindElement(By.Name(LoginButton)).Click();
mainBrowser.FindElement(By.Name(nameField)).SendKeys(username);
mainBrowser.FindElement(By.Name(nameField)).Submit();
Expand Down
10 changes: 6 additions & 4 deletions ShowdownBot/ShowdownBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver">
<HintPath>..\..\..\selenium\net40\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=2.53.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\selenium\2-53-1\net40\WebDriver.dll</HintPath>
</Reference>
<Reference Include="WebDriver.Support">
<HintPath>..\..\..\selenium\net40\WebDriver.Support.dll</HintPath>
<Reference Include="WebDriver.Support, Version=2.53.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\selenium\2-53-1\net40\WebDriver.Support.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
16 changes: 12 additions & 4 deletions ShowdownBot/changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
## Changelog ##


### **v0.2.0** ###
### **v0.2.1 / 2016-07-15** ###
---
Fixes

* Modules will now correctly choose leads when necessary.
* Bot will close the browser when killed.
* Fixed compatibility issues with Firefox 47.0.1
* Updated selenium to 2.53.1

### **v0.2.0 / _2016-07-12_** ###
----
_2016-07-12_


Added

Expand All @@ -24,9 +33,8 @@ Fixes



### **v0.1.0** ###
### **v0.1.0** *2016-06-29* ###
----
*2016-06-29*

* Initial development release.

Expand Down
9 changes: 7 additions & 2 deletions ShowdownBot/modules/AnalyticModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ public override void battle()
System.Threading.Thread.Sleep(5000); //let page load

//TODO: actually pick this analytically.
lead = browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='0']")).Text;
browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='0']")).Click();
if (browser.FindElements(By.CssSelector("button[name='chooseTeamPreview']")).Count != 0)
{
lead = browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='0']")).Text;
browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='0']")).Click();
}
else
lead = "error";

Pokemon active = Global.lookup(lead);
Pokemon enemy = null;
Expand Down
24 changes: 22 additions & 2 deletions ShowdownBot/modules/BiasedModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ public BiasedModule(Bot m, IWebDriver b)
public override void battle()
{
int turn = 1;
wait(10000);
if (format != "randombattle")
{
while (browser.FindElements(By.CssSelector("button[name='chooseTeamPreview']")).Count == 0)
{
//todo terminate this if after a while.
wait();
}
pickLeadBiased();
}

do
{
battleBiased(ref turn);
Expand Down Expand Up @@ -89,7 +98,7 @@ private int pickMoveBiased()
HashSet<int> exclude = new HashSet<int>();
int choice;
choice = getIndexBiased();
while (browser.FindElements(By.CssSelector("button[value='"+choice.ToString()+"']")).Count == 0)
while (browser.FindElements(By.CssSelector("button[name=chooseMove][value='" + choice.ToString() + "']")).Count == 0)
{
//If the move we've chosen does not exist, just cycle through until we get one.
c.writef("Bad move choice: " + choice.ToString() + "Picking another", "[DEBUG]", Global.okColor);
Expand Down Expand Up @@ -126,6 +135,17 @@ private int getIndexBiased()

}

private void pickLeadBiased()
{
int lead = getIndexBiased() - 1;
while (browser.FindElements(By.CssSelector("button[name='chooseTeamPreview']")).Count == 0)
{
wait();
c.writef("Picking lead...", Global.botInfoColor);
}
browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='" + lead + "']")).Click();
}

public override void printInfo()
{
c.writef("Biased mode info:\n" +
Expand Down
18 changes: 14 additions & 4 deletions ShowdownBot/modules/RandomModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ public RandomModule(Bot m, IWebDriver b)
public override void battle()
{
int turn = 1;
wait(10000);
if (format != "randombattle")
{
while (browser.FindElements(By.CssSelector("button[name='chooseTeamPreview']")).Count == 0)
{
//todo terminate this if after a while.
wait();
}
int val = new Random().Next(0, 5);
browser.FindElement(By.CssSelector("button[name='chooseTeamPreview'][value='" + val + "']")).Click();
}

do
{
battleRandomly(ref turn);
Expand Down Expand Up @@ -62,15 +72,15 @@ private bool battleRandomly(ref int turn)
pokeSelection = pickPokeRandomly();
c.writef("New pokemon selected: " + pokeSelection.ToString(), Global.botInfoColor);
browser.FindElement(By.CssSelector("button[value='" + pokeSelection.ToString() + "']")).Click();
System.Threading.Thread.Sleep(2000);
//System.Threading.Thread.Sleep(2000);
}
else if (checkBattleEnd())
{
return true;
}
else
{
//c.write("Sleeping for 2 secs");
c.writef("Sleeping for 2 secs","debug",Global.defaultColor);
System.Threading.Thread.Sleep(2000);
}
return false;
Expand All @@ -82,7 +92,7 @@ private int determineMoveRandomly()
HashSet<int> exclude = new HashSet<int>();
int choice = rand.Next(1, 4);

while (browser.FindElements(By.CssSelector("button[value='" + choice.ToString() + "']")).Count == 0)
while (browser.FindElements(By.CssSelector("button[name=chooseMove][value='" + choice.ToString() + "']")).Count == 0)
{
c.writef("Bad move choice: " + choice.ToString() + "Picking another", "[DEBUG]", Global.okColor);
exclude.Add(choice);
Expand Down
Binary file not shown.
Binary file modified ShowdownBot/obj/x86/Debug/ShowdownBot.exe
Binary file not shown.
Binary file modified ShowdownBot/obj/x86/Debug/ShowdownBot.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified ShowdownBot/obj/x86/Release/ShowdownBot.exe
Binary file not shown.
Binary file modified ShowdownBot/obj/x86/Release/ShowdownBot.pdb
Binary file not shown.

0 comments on commit e7d2d2d

Please sign in to comment.