Skip to content

Commit

Permalink
Merge pull request #80 from ObjectivityLtd/3.1.6
Browse files Browse the repository at this point in the history
3.1.6
  • Loading branch information
raczeja committed Jul 11, 2018
2 parents 44cb691 + 62e8283 commit 287f5f7
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .nuspec/Objectivity.Test.Automation.Nunit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
<dependency id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" />
<dependency id="NUnit.Extension.VSProjectLoader" version="3.7.0" />
<dependency id="NUnit.Extension.TeamCityEventListener" version="1.0.3" />
<dependency id="NPOI" version="2.3.0" />
<dependency id="SharpZipLib" version="0.86.0" />
</dependencies>
</metadata>
<files>
<file src="..\Objectivity.Test.Automation.Tests.NUnit\ProjectTestBase.cs" target="content" />
<file src="..\Objectivity.Test.Automation.Tests.NUnit\App.config" target="content" />
<file src="..\Objectivity.Test.Automation.Tests.PageObjects\ProjectPageBase.cs" target="content" />
<file src="..\Objectivity.Test.Automation.Tests.NUnit\DataDriven\DataDrivenHelper.cs" target="content\DataDriven" />
<file src="..\Objectivity.Test.Automation.Tests.NUnit\DataDriven\TestData.cs" target="content\DataDriven" />
<file src="..\Objectivity.Test.Automation.Tests.NUnit\ProjectBaseConfiguration.cs" target="content" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,53 @@ public static void SynchronizeWithAngular(this IWebDriver webDriver, bool enable
DriversCustomSettings.SetAngularSynchronizationForDriver(webDriver, enable);
}

/// <summary>
/// Javascript drag and drop function.
/// </summary>
/// <param name="webDriver">The WebDriver</param>
/// <param name="source">Source element</param>
/// <param name="destination">Destination element</param>
public static void DragAndDropJs(this IWebDriver webDriver, IWebElement source, IWebElement destination)
{
var script =
"function createEvent(typeOfEvent) { " +
"var event = document.createEvent(\"CustomEvent\"); " +
"event.initCustomEvent(typeOfEvent, true, true, null); " +
"event.dataTransfer = { " +
"data: { }, " +
"setData: function(key, value) { " +
"this.data[key] = value; " +
"}, " +
"getData: function(key) { " +
"return this.data[key]; " +
"} " +
"}; " +
"return event; " +
"} " +
"function dispatchEvent(element, event, transferData) { " +
"if (transferData !== undefined)" +
"{" +
"event.dataTransfer = transferData;" +
"}" +
"if (element.dispatchEvent) {" +
"element.dispatchEvent(event);" +
"} else if (element.fireEvent) {" +
"element.fireEvent(\"on\" + event.type, event);" +
"}" +
"}" +
"function simulateHTML5DragAndDrop(element, target)" +
"{" +
"var dragStartEvent = createEvent('dragstart');" +
"dispatchEvent(element, dragStartEvent);" +
"var dropEvent = createEvent('drop');" +
"dispatchEvent(target, dropEvent, dragStartEvent.dataTransfer);" +
"var dragEndEvent = createEvent('dragend');" +
"dispatchEvent(element, dragEndEvent, dropEvent.dataTransfer);" +
"} simulateHTML5DragAndDrop(arguments[0], arguments[1])";

((IJavaScriptExecutor)webDriver).ExecuteScript(script, source, destination);
}

/// <summary>
/// Approves the trust certificate for internet explorer.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions Objectivity.Test.Automation.Common/Helpers/NameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,23 @@ public static string ShortenFileName(string folder, string fileName, string patt

return fileName;
}

/// <summary>
/// Remove all special characters except digit and letters.
/// </summary>
/// <param name="name">The string to remove special chracters.</param>
/// <returns>String with removed all special chracters</returns>
/// <example>How to use it: <code>
/// var name = NameHelper.RemoveSpecialCharacters("country/region");
/// </code></example>
public static string RemoveSpecialCharacters(string name)
{
Logger.Debug(CultureInfo.CurrentCulture, "Removing all special characters except digit and letters from '{0}'", name);
Regex rgx = new Regex("[^a-zA-Z0-9]");
name = rgx.Replace(name, string.Empty);
Logger.Debug(CultureInfo.CurrentCulture, "name without special characters: '{0}'", name);

return name;
}
}
}
87 changes: 86 additions & 1 deletion Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ namespace Objectivity.Test.Automation.Common.Helpers
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;

using NLog;
using Objectivity.Test.Automation.Common.Extensions;
using OpenQA.Selenium;

/// <summary>
/// Custom screenshot solution
Expand Down Expand Up @@ -99,5 +100,89 @@ public static string Save(Bitmap bitmap, ImageFormat format, string folder, stri

return null;
}

/// <summary>
/// Takes screen shot of specific element.
/// </summary>
/// <param name="element">Element to take screenshot</param>
/// <param name="folder">Folder to save screenshot</param>
/// <param name="screenshotName">Name of screenshot</param>
/// <returns>Full path to taken screenshot</returns>
/// <example>How to use it: <code>
/// var el = this.Driver.GetElement(this.menu);
/// TakeScreenShot.TakeScreenShotOfElement(el, TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");
/// </code></example>
public static string TakeScreenShotOfElement(IWebElement element, string folder, string screenshotName)
{
Logger.Debug("Taking screenhot of element not within iframe");
return TakeScreenShotOfElement(0, 0, element, folder, screenshotName);
}

/// <summary>
/// Takes screen shot of specific element within iframe.
/// </summary>
/// <param name="iframeLocationX">X coordinate of iframe</param>
/// <param name="iframeLocationY">Y coordinate of iframe</param>
/// <param name="element">Element to take screenshot</param>
/// <param name="folder">Folder to save screenshot</param>
/// <param name="screenshotName">Name of screenshot</param>
/// <returns>Full path to taken screenshot</returns>
/// <example>How to use it: <code>
/// var iFrame = this.Driver.GetElement(this.iframe);
/// int x = iFrame.Location.X;
/// int y = iFrame.Location.Y;
/// this.Driver.SwitchTo().Frame(0);
/// var el = this.Driver.GetElement(this.elelemtInIFrame);
/// TakeScreenShot.TakeScreenShotOfElement(el, TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");
/// </code></example>
public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLocationY, IWebElement element, string folder, string screenshotName)
{
Logger.Debug("Taking screenhot of iframe LocationX:{0} LocationY:{1}", iframeLocationX, iframeLocationY);
var locationX = iframeLocationX;
var locationY = iframeLocationY;

var driver = element.ToDriver();

var screenshotDriver = (ITakesScreenshot)driver;
var screenshot = screenshotDriver.GetScreenshot();
var filePath = Path.Combine(folder, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture) + "temporary_fullscreen.png");
Logger.Debug(CultureInfo.CurrentCulture, "Taking full screenshot {0}", filePath);
screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);

if (BaseConfiguration.TestBrowser == BrowserType.Chrome)
{
locationX = element.Location.X + locationX;
locationY = element.Location.Y + locationY;
}
else
{
locationX = element.Location.X;
locationY = element.Location.Y;
}

var elementWidth = element.Size.Width;
var elementHeight = element.Size.Height;

Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot of element locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);

var image = new Rectangle(locationX, locationY, elementWidth, elementHeight);
var importFile = new Bitmap(filePath);
string newFilePath;
Bitmap cloneFile;
try
{
newFilePath = Path.Combine(folder, screenshotName + ".png");
cloneFile = (Bitmap)importFile.Clone(image, importFile.PixelFormat);
}
finally
{
importFile.Dispose();
}

Logger.Debug(CultureInfo.CurrentCulture, "Saving screenshot of element {0}", newFilePath);
cloneFile.Save(newFilePath);
File.Delete(filePath);
return newFilePath;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>bin\Debug\Objectivity.Test.Automation.Common.XML</DocumentationFile>
<CodeAnalysisRuleSet>..\fxcop-sonarqube.tests.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
Expand Down
3 changes: 0 additions & 3 deletions Objectivity.Test.Automation.Common/packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="coveralls.net" version="0.7.0" targetFramework="net45" developmentDependency="true" />
<package id="EWSoftware.SHFB" version="2017.12.30.2" targetFramework="net45" />
<package id="Microsoft.AnalysisServices.AdomdClient" version="12.0.2000.8" targetFramework="net40" />
<package id="NLog" version="4.3.5" targetFramework="net45" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net40" />
<package id="OpenCover" version="4.6.519" targetFramework="net45" />
<package id="Selenium.Support" version="3.12.1" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.12.1" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.38.0.1" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<StyleCopEnabled>True</StyleCopEnabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static IEnumerable<TestCaseData> ReadDataDriveFileCsv(string file, string

while (line != null)
{
string testCaseName;
line = sr.ReadLine();
if (line != null)
{
Expand All @@ -145,32 +146,25 @@ public static IEnumerable<TestCaseData> ReadDataDriveFileCsv(string file, string
testParams.Add(columns[i], split[i]);
}

if (diffParam != null && diffParam.Any())
try
{
try
{
testName = TestCaseName(diffParam, testParams, testName);
}
catch (DataDrivenReadException e)
{
throw new DataDrivenReadException(
string.Format(
" Exception while reading Csv Data Driven file\n searched key '{0}' not found \n for test {1} in file '{2}' at row {3}",
testCaseName = TestCaseName(diffParam, testParams, testName);
}
catch (DataDrivenReadException e)
{
throw new DataDrivenReadException(
string.Format(
" Exception while reading Csv Data Driven file\n searched key '{0}' not found \n for test {1} in file '{2}' at row {3}",
e.Message,
testName,
file,
row));
}
}
else
{
testName = testName + "_row(" + row + ")";
}

row = row + 1;

var data = new TestCaseData(testParams);
data.SetName(testName);
data.SetName(testCaseName);
yield return data;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<StyleCopEnabled>True</StyleCopEnabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ namespace Objectivity.Test.Automation.Tests.NUnit
using System.Reflection;
using Common;
using Common.Helpers;
using global::NUnit.Framework;

/// <summary>
/// SeleniumConfiguration that consume app.config file
/// </summary>
public static class ProjectBaseConfiguration
{
private static readonly string CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private static readonly string CurrentDirectory = TestContext.CurrentContext.TestDirectory;

/// <summary>
/// Gets the data driven file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,16 @@ public void TablesTest()
Assert.AreEqual("Smith", table[0][0]);
Assert.AreEqual("edit delete", table[3][5]);
}

[Test]
public void DragAndDropTest()
{
var dragAndDrop = new InternetPage(this.DriverContext)
.OpenHomePage()
.GoToDragAndDropPage()
.MoveElementAtoElementB();

Assert.IsTrue(dragAndDrop.IsElementAMovedToB(), "Element is not moved.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
<ItemGroup>
<Compile Include="CustomGrid.cs" />
<Compile Include="PageObjects\TheInternet\BrokenImagesPage.cs" />
<Compile Include="PageObjects\TheInternet\DragAndDropPage.cs" />
<Compile Include="PageObjects\TheInternet\DynamicControlsPage.cs" />
<Compile Include="PageObjects\TheInternet\DynamicLoadingPage.cs" />
<Compile Include="PageObjects\TheInternet\IFramePage.cs" />
<Compile Include="PageObjects\TheInternet\TablesPage.cs" />
<Compile Include="PageObjects\TheInternet\HttpCode200Page.cs" />
<Compile Include="PageObjects\TheInternet\JavaScriptOnLoadPage.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// <copyright file="DragAndDropPage.cs" company="Objectivity Bespoke Software Specialists">
// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.
// </copyright>
// <license>
// The MIT License (MIT)
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </license>

namespace Objectivity.Test.Automation.Tests.PageObjects.PageObjects.TheInternet
{
using Common;
using Common.Extensions;
using Objectivity.Test.Automation.Common.Types;

public class DragAndDropPage : ProjectPageBase
{
private readonly ElementLocator boxA = new ElementLocator(Locator.Id, "column-a");
private readonly ElementLocator boxB = new ElementLocator(Locator.Id, "column-b");
private readonly ElementLocator boxBtext = new ElementLocator(Locator.XPath, "//div[@id='column-b']/header");

public DragAndDropPage(DriverContext driverContext)
: base(driverContext)
{
}

public DragAndDropPage MoveElementAtoElementB()
{
this.Driver.DragAndDropJs(this.Driver.GetElement(this.boxA), this.Driver.GetElement(this.boxB));
return this;
}

public bool IsElementAMovedToB()
{
return this.Driver.GetElement(this.boxBtext).Text.Equals("A");
}
}
}
Loading

0 comments on commit 287f5f7

Please sign in to comment.