Skip to content

Commit

Permalink
Merge commit 'ff32143760ccc4bbf6ff2e4accf668018de50a04'
Browse files Browse the repository at this point in the history
Existing tests pass. Need to add the Selenium tests to the solution too.
# Conflicts:
#	TestAutomationEssentials.Common/TestAutomationEssentials.Common.csproj
#	TestAutomationEssentials.Common/packages.config
#	TestAutomationEssentials.MSTest/TestAutomationEssentials.MSTest.csproj
#	TestAutomationEssentials.Selenium/Browser.cs
#	TestAutomationEssentials.Selenium/BrowserElement.cs
#	TestAutomationEssentials.Selenium/BrowserWindow.cs
#	TestAutomationEssentials.Selenium/ElementsContainer.cs
#	TestAutomationEssentials.Selenium/TestAutomationEssentials.Selenium.csproj
#	TestAutomationEssentials.Selenium/packages.config
  • Loading branch information
arnonax committed Jan 13, 2019
2 parents 08affda + ff32143 commit 743c039
Show file tree
Hide file tree
Showing 14 changed files with 945 additions and 62 deletions.
5 changes: 3 additions & 2 deletions TestAutomationEssentials.Common/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void While(Func<bool> condition, TimeSpan timeout, string timeoutM
ValidateNullArgument(args, "args");
ValidateTimeout(timeout);

Until(() => !condition(), timeout, timeoutMessage);
Until(() => !condition(), timeout, timeoutMessage, args);
}

/// <summary>
Expand All @@ -102,10 +102,11 @@ public static void Until(Func<bool> condition, TimeSpan timeout, string timeoutM
ValidateNullArgument(timeoutMessage, "timeoutMessage");
ValidateNullArgument(args, "args");
ValidateTimeout(timeout);
var formattedMessage = string.Format(timeoutMessage, args);

var conditionMet = IfNot(condition, timeout);
if (!conditionMet)
throw new TimeoutException(string.Format(timeoutMessage, args));
throw new TimeoutException(formattedMessage);
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion TestAutomationEssentials.MSTest/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestAutomationEssentials.MSTest
Expand All @@ -18,7 +19,7 @@ public class TestUtils
/// <exception cref="ArgumentNullException"><paramref name="action"/> is null</exception>
/// <exception cref="AssertFailedException">No exception of type <typeparamref name="TException"/> was
/// thrown by <paramref name="action"/></exception>
public static TException ExpectException<TException>(Action action)
public static TException ExpectException<TException>([InstantHandle]Action action)
where TException : Exception
{
const string message = "Expected an exception of type {0} but it wasn't thrown";
Expand Down
4 changes: 4 additions & 0 deletions TestAutomationEssentials.MSTest/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="JetBrains.Annotations" version="2018.2.1" targetFramework="net45" />
</packages>
69 changes: 46 additions & 23 deletions TestAutomationEssentials.Selenium/Browser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Linq;
using JetBrains.Annotations;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using TestAutomationEssentials.Common;
using TestAutomationEssentials.Common.ExecutionContext;
using TestAutomationEssentials.MSTest;

namespace TestAutomationEssentials.Selenium
{
Expand Down Expand Up @@ -119,32 +119,55 @@ public void Dispose()
_isDisposed = true;
}

/// <summary>
/// Invokes a delegate that causes a new window to open, and return an object representing the new window
/// </summary>
/// <param name="action">The delegate that should cause a new window to open</param>
/// <param name="windowDescription">A description that will identify the window in the log</param>
/// <returns>The <see cref="BrowserWindow"/> object that represent the newly opened window</returns>
/// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="windowDescription"/> are null</exception>
/// <exception cref="TimeoutException">A new window wasn't opened for 60 seconds after the delegate completed</exception>
/// <remarks>
/// When the current <see cref="IIsolationScope"/> ends, the window is automatically closed
/// </remarks>
/// <example>
/// <code>
/// var openNewWindowButton = myBrowser.WaitForElement(By.Id("openNewWindowButtonId"), "Open new window button");
/// var newWindow = myBrowser.OpenWindow(() => openNewButton.Click(), "New window");
/// Assert.AreEqual("New window Title", newWindow.Title);
/// </code>
/// </example>
public BrowserWindow OpenWindow(Action action, string windowDescription)
/// <summary>
/// Invokes a delegate that causes a new window to open, and return an object representing the new window
/// </summary>
/// <param name="action">The delegate that should cause a new window to open</param>
/// <param name="windowDescription">A description that will identify the window in the log</param>
/// <returns>The <see cref="BrowserWindow"/> object that represent the newly opened window</returns>
/// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="windowDescription"/> are null</exception>
/// <exception cref="TimeoutException">A new window wasn't opened for 60 seconds after the delegate completed</exception>
/// <remarks>
/// When the current <see cref="IIsolationScope"/> ends, the window is automatically closed
/// </remarks>
/// <example>
/// <code>
/// var openNewWindowButton = myBrowser.WaitForElement(By.Id("openNewWindowButtonId"), "Open new window button");
/// var newWindow = myBrowser.OpenWindow(() => openNewButton.Click(), "New window");
/// Assert.AreEqual("New window Title", newWindow.Title);
/// </code>
/// </example>
public BrowserWindow OpenWindow(Action action, string windowDescription)
{
return OpenWindow(action, windowDescription, 1.Minutes());
}

/// <summary>
/// Invokes a delegate that causes a new window to open, and return an object representing the new window
/// </summary>
/// <param name="action">The delegate that should cause a new window to open</param>
/// <param name="windowDescription">A description that will identify the window in the log</param>
/// <param name="timeout">The maximal time to wait for the window to open</param>
/// <returns>The <see cref="BrowserWindow"/> object that represent the newly opened window</returns>
/// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="windowDescription"/> are null</exception>
/// <exception cref="TimeoutException">A new window wasn't opened for the specified timeout after the delegate completed</exception>
/// <remarks>
/// When the current <see cref="IIsolationScope"/> ends, the window is automatically closed
/// </remarks>
/// <example>
/// <code>
/// var openNewWindowButton = myBrowser.WaitForElement(By.Id("openNewWindowButtonId"), "Open new window button");
/// var newWindow = myBrowser.OpenWindow(() => openNewButton.Click(), "New window");
/// Assert.AreEqual("New window Title", newWindow.Title);
/// </code>
/// </example>
public BrowserWindow OpenWindow([InstantHandle]Action action, string windowDescription, TimeSpan timeout)
{
CheckDisposed();
if (action == null)
throw new ArgumentNullException("action");
if (windowDescription == null)
throw new ArgumentNullException("windowDescription");

Activate();
var webDriver = GetWebDriver();
var existingHandles = webDriver.WindowHandles;
Expand Down Expand Up @@ -179,5 +202,5 @@ void IDOMRoot.Activate()
CheckDisposed();
Activate();
}
}
}
}
19 changes: 13 additions & 6 deletions TestAutomationEssentials.Selenium/BrowserElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ void IWebElement.Submit()
public void Click()
{
Logger.WriteLine("Click on '{0}'", Description);
//Actions action = new Actions(_domRoot.Browser.GetWebDriver());
//action.MoveToElement(WebElement, 0, 0).Perform();
//action.Click(WebElement).Perform();
WebElement.Click();
}

Expand Down Expand Up @@ -339,10 +336,10 @@ internal IWebElement GetWebElement()
/// </summary>
/// <param name="target">The target element to drop the current element onto</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
[Obsolete("This method doesn't work with GeckoDriver right now. If this will be implemented by that driver" +
"in the future, this Obsolete warning should be removed")]
public void DragAndDrop(BrowserElement target)
{
if (target == null)
throw new ArgumentNullException("target");

Logger.WriteLine("Drag element '{0}' to '{1}'", Description, target.Description);
var targetWebElement = target.WebElement;
Expand All @@ -358,7 +355,17 @@ public void DragAndDrop(BrowserElement target)
/// <exception cref="TimeoutException">The current element hasn't been disappeared for the specified period</exception>
public void WaitToDisappear(int seconds = DefaultWaitTimeout)
{
Wait.While(() => Displayed, seconds.Seconds(), "Element '{0}' still appears after '{1}' seconds", Description, seconds);
WaitToDisappear(seconds.Seconds());
}

/// <summary>
/// Waits for the current element to disappear. That is, either become invisible or completely removed from the DOM
/// </summary>
/// <param name="timeout">Timeout to wait for the element to disappear</param>
/// <exception cref="TimeoutException">The current element hasn't been disappeared for the specified period</exception>
public void WaitToDisappear(TimeSpan timeout)
{
Wait.While(() => Displayed, timeout, "Element '{0}' still appears after '{1}'", Description, timeout.ToSpokenString());
}

#region IWrapsElement Members
Expand Down
7 changes: 5 additions & 2 deletions TestAutomationEssentials.Selenium/BrowserWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using OpenQA.Selenium;
using TestAutomationEssentials.Common;

Expand All @@ -9,7 +10,7 @@ namespace TestAutomationEssentials.Selenium
public class BrowserWindow : ElementsContainer, IDOMRoot
{
private readonly Browser _browser;
private readonly string _windowHandle;
private string _windowHandle;

/// <summary>
/// Initializes the <see cref="BrowserWindow"/> given the specified browser, window handle, and a description
Expand Down Expand Up @@ -119,7 +120,9 @@ public void NavigateToUrl(string url)
{
Logger.WriteLine("Navigating to '{0}' on '{1}' window", url, Description);
Activate();
_browser.GetWebDriver().Navigate().GoToUrl(url);
var driver = _browser.GetWebDriver();
driver.Url = url;
_windowHandle = driver.CurrentWindowHandle; // Workaround for GeckoDriver. See test: GeckoDriverChangesWindowHandleAfterSettingUrlForTheFirstTime
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<NoWarn>7035</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="JetBrains.Annotations, Version=2018.2.1.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<HintPath>..\packages\JetBrains.Annotations.2018.2.1\lib\net20\JetBrains.Annotations.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand All @@ -49,12 +53,12 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver, Version=3.11.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.11.1\lib\net45\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=3.14.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.14.0\lib\net45\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WebDriver.Support, Version=3.11.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.Support.3.11.1\lib\net45\WebDriver.Support.dll</HintPath>
<Reference Include="WebDriver.Support, Version=3.14.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.Support.3.14.0\lib\net45\WebDriver.Support.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand All @@ -78,7 +82,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
5 changes: 3 additions & 2 deletions TestAutomationEssentials.Selenium/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Selenium.Support" version="3.11.1" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.11.1" targetFramework="net45" />
<package id="JetBrains.Annotations" version="2018.2.1" targetFramework="net45" />
<package id="Selenium.Support" version="3.14.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.14.0" targetFramework="net45" />
</packages>
Loading

0 comments on commit 743c039

Please sign in to comment.