Skip to content

Commit

Permalink
Fixing .NET tests to work with Marionette implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Oct 14, 2015
1 parent b0e2f0d commit 4c41e06
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 86 deletions.
146 changes: 60 additions & 86 deletions dotnet/test/common/ExecutingJavascriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public void ShouldBeAbleToExecuteSimpleJavascriptAndReturnABoolean()
object result = ExecuteScript("return true;");

Assert.IsNotNull(result);
Assert.IsTrue(result is Boolean);
Assert.IsTrue((Boolean)result);
Assert.IsTrue(result is bool);
Assert.IsTrue((bool)result);
}

[Test]
Expand Down Expand Up @@ -247,8 +247,7 @@ public void ShouldBeAbleToPassAStringAsAnArgument()

driver.Url = javascriptPage;

ExecuteScript("displayMessage(arguments[0]);", "Hello!");
string text = driver.FindElement(By.Id("result")).Text;
string text = (string)ExecuteScript("return arguments[0] == 'Hello!' ? 'Hello!' : 'Goodbye!';", "Hello!");
Assert.AreEqual("Hello!", text);
}

Expand All @@ -257,49 +256,46 @@ public void ShouldBeAbleToPassAStringAsAnArgument()
public void ShouldBeAbleToPassABooleanAsAnArgument()
{

string function = "displayMessage(arguments[0] ? 'True' : 'False');";
string function = "return arguments[0] == true ? true : false;";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, true);
string text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("True", text);
bool result = (bool)ExecuteScript(function, true);
Assert.IsTrue(result);

ExecuteScript(function, false);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("False", text);
result = (bool)ExecuteScript(function, false);
Assert.IsFalse(result);
}

[Test]
[Category("Javascript")]
public void ShouldBeAbleToPassANumberAsAnArgument()
{
string function = "displayMessage(arguments[0]);";
string functionTemplate = "return arguments[0] == {0} ? {0} : 0;";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, 3);
string text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("3", text);

ExecuteScript(function, -3);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-3", text);
string function = string.Format(functionTemplate, 3);
long result = (long)ExecuteScript(function, 3);
Assert.AreEqual(3, result);

ExecuteScript(function, 2147483647);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("2147483647", text);
function = string.Format(functionTemplate, -3);
result = (long)ExecuteScript(function, -3);
Assert.AreEqual(-3, result);

ExecuteScript(function, -2147483647);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-2147483647", text);
function = string.Format(functionTemplate, 2147483647);
result = (long)ExecuteScript(function, 2147483647);
Assert.AreEqual(2147483647, result);

function = string.Format(functionTemplate, -2147483647);
result = (long)ExecuteScript(function, -2147483647);
Assert.AreEqual(-2147483647, result);
}

[Test]
Expand Down Expand Up @@ -333,8 +329,6 @@ public void PassingArrayAsOnlyArgumentShouldFlattenArray()

[Test]
[Category("Javascript")]
[IgnoreBrowser(Browser.Firefox)]
[IgnoreBrowser(Browser.Remote)]
public void ShouldBeAbleToPassAnArrayAsAdditionalArgument()
{
if (!(driver is IJavaScriptExecutor))
Expand All @@ -350,7 +344,6 @@ public void ShouldBeAbleToPassAnArrayAsAdditionalArgument()

[Test]
[Category("Javascript")]
[IgnoreBrowser(Browser.Remote)]
public void ShouldBeAbleToPassACollectionAsArgument()
{
if (!(driver is IJavaScriptExecutor))
Expand Down Expand Up @@ -572,9 +565,8 @@ public void ShouldBeAbleToPassMoreThanOneStringAsArguments()
return;

driver.Url = javascriptPage;
ExecuteScript("displayMessage(arguments[0] + arguments[1] + arguments[2] + arguments[3]);", "Hello,", " ", "world", "!");
string text = (string)ExecuteScript("return arguments[0] + arguments[1] + arguments[2] + arguments[3];", "Hello,", " ", "world", "!");

string text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("Hello, world!", text);
}

Expand All @@ -583,122 +575,103 @@ public void ShouldBeAbleToPassMoreThanOneStringAsArguments()
public void ShouldBeAbleToPassMoreThanOneBooleanAsArguments()
{

string function = "displayMessage((arguments[0] ? 'True' : 'False') + (arguments[1] ? 'True' : 'False'));";
string function = "return (arguments[0] ? 'True' : 'False') + (arguments[1] ? 'True' : 'False');";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, true, true);
string text = driver.FindElement(By.Id("result")).Text;
string text = (string)ExecuteScript(function, true, true);
Assert.AreEqual("TrueTrue", text);

ExecuteScript(function, false, true);
text = driver.FindElement(By.Id("result")).Text;
text = (string)ExecuteScript(function, false, true);
Assert.AreEqual("FalseTrue", text);

ExecuteScript(function, true, false);
text = driver.FindElement(By.Id("result")).Text;
text = (string)ExecuteScript(function, true, false);
Assert.AreEqual("TrueFalse", text);

ExecuteScript(function, false, false);
text = driver.FindElement(By.Id("result")).Text;
text = (string)ExecuteScript(function, false, false);
Assert.AreEqual("FalseFalse", text);
}

[Test]
[Category("Javascript")]
public void ShouldBeAbleToPassMoreThanOneNumberAsArguments()
{
string function = "displayMessage(arguments[0]+arguments[1]);";
string function = "return arguments[0]+arguments[1];";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, 30, 12);
string text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("42", text);
long result = (long)ExecuteScript(function, 30, 12);
Assert.AreEqual(42, result);

ExecuteScript(function, -30, -12);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-42", text);
result = (long)ExecuteScript(function, -30, -12);
Assert.AreEqual(-42, result);

ExecuteScript(function, 2147483646, 1);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("2147483647", text);
result = (long)ExecuteScript(function, 2147483646, 1);
Assert.AreEqual(2147483647, result);

ExecuteScript(function, -2147483646, -1);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-2147483647", text);
result = (long)ExecuteScript(function, -2147483646, -1);
Assert.AreEqual(-2147483647, result);

}

[Test]
[Category("Javascript")]
public void ShouldBeAbleToPassADoubleAsAnArgument()
{
string function = "displayMessage(arguments[0]);";
string function = "return arguments[0];";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, (double)4.2);
string text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("4.2", text);

ExecuteScript(function, (double)-4.2);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-4.2", text);
double result = (double)ExecuteScript(function, (double)4.2);
Assert.AreEqual(4.2, result);

ExecuteScript(function, (float)4.2);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("4.2", text);
result = (double)ExecuteScript(function, (double)-4.2);
Assert.AreEqual(-4.2, result);

ExecuteScript(function, (float)-4.2);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-4.2", text);
result = (double)ExecuteScript(function, (float)4.2);
Assert.AreEqual(4.2, result);

ExecuteScript(function, (double)4.0);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("4", text);
result = (double)ExecuteScript(function, (float)-4.2);
Assert.AreEqual(-4.2, result);

ExecuteScript(function, (double)-4.0);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-4", text);
result = (long)ExecuteScript(function, (double)4.0);
Assert.AreEqual(4, result);

result = (long)ExecuteScript(function, (double)-4.0);
Assert.AreEqual(-4, result);
}

[Test]
[Category("Javascript")]
public void ShouldBeAbleToPassMoreThanOneDoubleAsArguments()
{
String function = "displayMessage(arguments[0]+arguments[1]);";
String function = "return arguments[0]+arguments[1];";

if (!(driver is IJavaScriptExecutor))
return;

driver.Url = javascriptPage;

ExecuteScript(function, 30, 12);
String text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("42", text);
double result = (double)ExecuteScript(function, 30.1, 12.1);
Assert.AreEqual(42.2, result);

ExecuteScript(function, -30, -12);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-42", text);
result = (double)ExecuteScript(function, -30.1, -12.1);
Assert.AreEqual(-42.2, result);

ExecuteScript(function, 2147483646, 1);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("2147483647", text);
result = (double)ExecuteScript(function, 2147483646.1, 1.0);
Assert.AreEqual(2147483647.1, result);

ExecuteScript(function, -2147483646, -1);
text = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual("-2147483647", text);
result = (double)ExecuteScript(function, -2147483646.1, -1.0);
Assert.AreEqual(-2147483647.1, result);

}

Expand Down Expand Up @@ -791,7 +764,8 @@ private bool CompareLists(ReadOnlyCollection<object> first, ReadOnlyCollection<o

private object ExecuteScript(String script, params Object[] args)
{
return ((IJavaScriptExecutor)driver).ExecuteScript(script, args);
object toReturn = ((IJavaScriptExecutor)driver).ExecuteScript(script, args);
return toReturn;
}
}
}
5 changes: 5 additions & 0 deletions dotnet/test/common/JavascriptEnabledBrowserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public void ShouldBeAbleToGetTheLocationOfAnElement()
[IgnoreBrowser(Browser.WindowsPhone, "Windows Phone driver does not support multiple windows")]
public void ShouldBeAbleToClickALinkThatClosesAWindow()
{
if (TestUtilities.IsMarionette(driver))
{
Assert.Ignore("Marionette hangs the browser in this case");
}

driver.Url = javascriptPage;

String handle = driver.CurrentWindowHandle;
Expand Down
5 changes: 5 additions & 0 deletions dotnet/test/common/NavigationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public void ShouldGoBackAndForward()
[IgnoreBrowser(Browser.Remote, "Remote server does not handle encoded characters properly")]
public void ShouldAcceptInvalidUrlsUsingStrings()
{
if (TestUtilities.IsMarionette(driver))
{
Assert.Ignore("Invalid URLs hang Marionette");

}
INavigation navigation;
navigation = driver.Navigate();

Expand Down

0 comments on commit 4c41e06

Please sign in to comment.