From 87cd2159362e2d63e1b2e5d3e36600280d22f60d Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Mon, 11 Sep 2017 07:24:03 +0200 Subject: [PATCH 01/17] Added the ability to add the screenshots to the test results of NUnit, added waits for screenshots to be saved --- .../DriverContext.cs | 10 ++++++---- .../Helpers/TakeScreenShot.cs | 3 ++- .../ProjectTestBase.cs | 15 ++++++++++++++- .../App.config | 2 +- .../ProjectTestBase.cs | 15 ++++++++++++++- .../Tests/SaveScreenShotsPageSourceTestsNUnit.cs | 2 ++ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Objectivity.Test.Automation.Common/DriverContext.cs b/Objectivity.Test.Automation.Common/DriverContext.cs index 9954e3c06..2bbf134a9 100644 --- a/Objectivity.Test.Automation.Common/DriverContext.cs +++ b/Objectivity.Test.Automation.Common/DriverContext.cs @@ -509,8 +509,9 @@ public string SaveScreenshot(ErrorDetail errorDetail, string folder, string titl try { errorDetail.Screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png); + FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, correctFileName, folder); Logger.Error(CultureInfo.CurrentCulture, "Test failed: screenshot saved to {0}.", filePath); - Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath); + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath)); return filePath; } catch (NullReferenceException) @@ -532,7 +533,8 @@ public string SavePageSource(string fileName) { var fileNameShort = Regex.Replace(fileName, "[^0-9a-zA-Z._]+", "_"); fileNameShort = NameHelper.ShortenFileName(this.PageSourceFolder, fileNameShort, "_", 255); - var path = Path.Combine(this.PageSourceFolder, string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html")); + var fileNameWithExtension = string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html"); + var path = Path.Combine(this.PageSourceFolder, fileNameWithExtension); if (File.Exists(path)) { File.Delete(path); @@ -541,9 +543,9 @@ public string SavePageSource(string fileName) var pageSource = this.driver.PageSource; pageSource = pageSource.Replace("", string.Format(CultureInfo.CurrentCulture, "", BaseConfiguration.Host)); File.WriteAllText(path, pageSource); - + FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, fileNameWithExtension, this.PageSourceFolder); Logger.Error(CultureInfo.CurrentCulture, "Test failed: page Source saved to {0}.", path); - Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path); + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path)); return path; } diff --git a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs index 3c06146be..4472c2563 100644 --- a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs +++ b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs @@ -92,7 +92,8 @@ public static string Save(Bitmap bitmap, ImageFormat format, string folder, stri bitmap.Save(filePath, format); bitmap.Dispose(); Logger.Error(CultureInfo.CurrentCulture, "Test failed: full screenshot saved to {0}.", filePath); - Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath); + FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, fileName, folder); + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath)); return filePath; } diff --git a/Objectivity.Test.Automation.Tests.Features/ProjectTestBase.cs b/Objectivity.Test.Automation.Tests.Features/ProjectTestBase.cs index 8a2fc2016..11abc819a 100644 --- a/Objectivity.Test.Automation.Tests.Features/ProjectTestBase.cs +++ b/Objectivity.Test.Automation.Tests.Features/ProjectTestBase.cs @@ -118,13 +118,26 @@ public void BeforeTest() public void AfterTest() { this.DriverContext.IsTestFailed = this.scenarioContext.TestError != null || !this.driverContext.VerifyMessages.Count.Equals(0); - this.SaveTestDetailsIfTestFailed(this.driverContext); + var filePaths = this.SaveTestDetailsIfTestFailed(this.driverContext); + this.SaveAttachmentsToTestContext(filePaths); this.DriverContext.Stop(); this.LogTest.LogTestEnding(this.driverContext); if (this.IsVerifyFailedAndClearMessages(this.driverContext) && this.scenarioContext.TestError == null) { Assert.Fail(); } + } + + private void SaveAttachmentsToTestContext(string[] filePaths) + { + if (filePaths != null) + { + foreach (var filePath in filePaths) + { + this.LogTest.Info("Uploading file [{0}] to test context", filePath); + TestContext.AddTestAttachment(filePath); + } + } } } } diff --git a/Objectivity.Test.Automation.Tests.NUnit/App.config b/Objectivity.Test.Automation.Tests.NUnit/App.config index 7aeff5e46..f52925e0e 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/App.config +++ b/Objectivity.Test.Automation.Tests.NUnit/App.config @@ -19,7 +19,7 @@ - + diff --git a/Objectivity.Test.Automation.Tests.NUnit/ProjectTestBase.cs b/Objectivity.Test.Automation.Tests.NUnit/ProjectTestBase.cs index 8daee2b10..88b7f94ec 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/ProjectTestBase.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/ProjectTestBase.cs @@ -99,12 +99,25 @@ public void BeforeTest() public void AfterTest() { this.DriverContext.IsTestFailed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed || !this.driverContext.VerifyMessages.Count.Equals(0); - this.SaveTestDetailsIfTestFailed(this.driverContext); + var filePaths = this.SaveTestDetailsIfTestFailed(this.driverContext); + this.SaveAttachmentsToTestContext(filePaths); this.LogTest.LogTestEnding(this.driverContext); if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed) { Assert.Fail(); } } + + private void SaveAttachmentsToTestContext(string[] filePaths) + { + if (filePaths != null) + { + foreach (var filePath in filePaths) + { + this.LogTest.Info("Uploading file [{0}] to test context", filePath); + TestContext.AddTestAttachment(filePath); + } + } + } } } diff --git a/Objectivity.Test.Automation.Tests.NUnit/Tests/SaveScreenShotsPageSourceTestsNUnit.cs b/Objectivity.Test.Automation.Tests.NUnit/Tests/SaveScreenShotsPageSourceTestsNUnit.cs index a042b5c9a..a14ceb21b 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/Tests/SaveScreenShotsPageSourceTestsNUnit.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/Tests/SaveScreenShotsPageSourceTestsNUnit.cs @@ -38,6 +38,7 @@ public void SaveFullScreenShotTest() var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png); Assert.IsNotNull(TakeScreenShot.Save(TakeScreenShot.DoIt(), ImageFormat.Png, this.DriverContext.ScreenShotFolder, string.Format(CultureInfo.CurrentCulture, this.DriverContext.TestTitle + "_first"))); var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber); + TestContext.AddTestAttachment(nameOfScreenShot); Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title"); Assert.IsNotNull(this.DriverContext.TakeAndSaveScreenshot()); } @@ -49,6 +50,7 @@ public void SaveWebDriverScreenShotTest() var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png); Assert.IsNotNull(downloadPage.SaveWebDriverScreenShot()); var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber); + TestContext.AddTestAttachment(nameOfScreenShot); Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title"); } From 9ed6eb87282f722ddc08bc54c89462777badfd58 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Mon, 11 Sep 2017 07:55:51 +0200 Subject: [PATCH 02/17] Fixed return page in DownloadPage test --- .../PageObjects/TheInternet/DownloadPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs b/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs index 5da49eb47..7ede29a26 100644 --- a/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs +++ b/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs @@ -114,7 +114,7 @@ public string CheckIfScreenShotIsSaved(int screenShotNumber) FilesHelper.WaitForFileOfGivenType(FileType.Png, 5, screenShotNumber, this.DriverContext.ScreenShotFolder); var nameOfFile = FilesHelper.GetLastFile(this.DriverContext.ScreenShotFolder, FileType.Png); - return nameOfFile.Name; + return Path.Combine(this.DriverContext.ScreenShotFolder, nameOfFile.Name); } public string SaveWebDriverScreenShot() From 8cf46310f4399c072eeced7045e3c523f0721217 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Mon, 11 Sep 2017 09:40:59 +0200 Subject: [PATCH 03/17] Fixed return file name in DownloadPage test --- .../PageObjects/TheInternet/DownloadPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs b/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs index 7ede29a26..a7f1695e5 100644 --- a/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs +++ b/Objectivity.Test.Automation.Tests.PageObjects/PageObjects/TheInternet/DownloadPage.cs @@ -114,7 +114,7 @@ public string CheckIfScreenShotIsSaved(int screenShotNumber) FilesHelper.WaitForFileOfGivenType(FileType.Png, 5, screenShotNumber, this.DriverContext.ScreenShotFolder); var nameOfFile = FilesHelper.GetLastFile(this.DriverContext.ScreenShotFolder, FileType.Png); - return Path.Combine(this.DriverContext.ScreenShotFolder, nameOfFile.Name); + return nameOfFile.FullName; } public string SaveWebDriverScreenShot() From e056ac1eb588d2f23ab11b6ba2b400ed1929aa7b Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 12 Sep 2017 12:10:20 +0200 Subject: [PATCH 04/17] Replaced Selenium.Firefox.WebDriver by Selenium.WebDriver.GeckoDriver v.0.18.0 --- .../Objectivity.Test.Automation.Common.csproj | 4 ++-- Objectivity.Test.Automation.Common/packages.config | 2 +- .../Objectivity.Test.Automation.Tests.Angular.csproj | 4 ++-- Objectivity.Test.Automation.Tests.Angular/packages.config | 2 +- .../Objectivity.Test.Automation.Tests.PageObjects.csproj | 6 +++--- .../packages.config | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj b/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj index 927ebdfc3..d078a00ff 100644 --- a/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj +++ b/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj @@ -176,11 +176,11 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + - + - + @@ -32,8 +32,6 @@ - - diff --git a/Objectivity.Test.Automation.Tests.Angular/PageObjects/ProtractorHomePage.cs b/Objectivity.Test.Automation.Tests.Angular/PageObjects/ProtractorHomePage.cs index de3966154..4c5fc8dd0 100644 --- a/Objectivity.Test.Automation.Tests.Angular/PageObjects/ProtractorHomePage.cs +++ b/Objectivity.Test.Automation.Tests.Angular/PageObjects/ProtractorHomePage.cs @@ -23,6 +23,7 @@ private readonly ElementLocator public ProtractorHomePage OpenProtractorHomePage() { var url = BaseConfiguration.GetUrlValue; + this.Driver.SynchronizeWithAngular(true); this.Driver.NavigateTo(new Uri(url)); Logger.Info(CultureInfo.CurrentCulture, "Opening page {0}", url); return this; diff --git a/Objectivity.Test.Automation.Tests.Angular/Tests/AngularTestNunit.cs b/Objectivity.Test.Automation.Tests.Angular/Tests/AngularTestNunit.cs index 9f50ebfc4..c3381ea95 100644 --- a/Objectivity.Test.Automation.Tests.Angular/Tests/AngularTestNunit.cs +++ b/Objectivity.Test.Automation.Tests.Angular/Tests/AngularTestNunit.cs @@ -1,4 +1,26 @@ -using NUnit.Framework; +// +// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved. +// +// +// 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. +// + +using NUnit.Framework; namespace Objectivity.Test.Automation.Tests.Angular.Tests { using Objectivity.Test.Automation.Tests.Angular.PageObjects; diff --git a/Objectivity.Test.Automation.Tests.NUnit/App.config b/Objectivity.Test.Automation.Tests.NUnit/App.config index f52925e0e..4e5445dd8 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/App.config +++ b/Objectivity.Test.Automation.Tests.NUnit/App.config @@ -32,8 +32,6 @@ - - diff --git a/Objectivity.Test.Automation.Tests.Xunit/App.config b/Objectivity.Test.Automation.Tests.Xunit/App.config index 8e262d52d..dcf1ef298 100644 --- a/Objectivity.Test.Automation.Tests.Xunit/App.config +++ b/Objectivity.Test.Automation.Tests.Xunit/App.config @@ -33,8 +33,6 @@ - - From 3be54af18e3f1f63985e2e75e31d5ad7fae20fb3 Mon Sep 17 00:00:00 2001 From: pstryczek Date: Thu, 14 Sep 2017 10:07:54 +0200 Subject: [PATCH 07/17] Added class DriversCustomSettings --- .../DriversCustomSettings.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Objectivity.Test.Automation.Common/DriversCustomSettings.cs diff --git a/Objectivity.Test.Automation.Common/DriversCustomSettings.cs b/Objectivity.Test.Automation.Common/DriversCustomSettings.cs new file mode 100644 index 000000000..992f27f1e --- /dev/null +++ b/Objectivity.Test.Automation.Common/DriversCustomSettings.cs @@ -0,0 +1,69 @@ +// +// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved. +// +// +// 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. +// + +namespace Objectivity.Test.Automation.Common +{ + using System.Collections.Generic; + using OpenQA.Selenium; + + /// + /// To keep drivers custom setting + /// + public static class DriversCustomSettings + { + private static Dictionary driversAngularSynchronizationEnable = + new Dictionary(); + + /// + /// Method return true or false is driver is synchronized with angular. + /// + /// Provide driver. + /// If driver is synchornized with angular return true if not return false. + public static bool IsDriverSynchronizationWithAngular(IWebDriver driver) + { + return driversAngularSynchronizationEnable.ContainsKey(driver) && driversAngularSynchronizationEnable[driver]; + } + + /// + /// Set angular synchronization for driver. + /// + /// Provide driver. + /// Set true to enable. + public static void SetAngularSynchronizationForDriver(IWebDriver driver, bool enable) + { + if (enable == false && driversAngularSynchronizationEnable.ContainsKey(driver)) + { + driversAngularSynchronizationEnable.Remove(driver); + } + + if (enable && !driversAngularSynchronizationEnable.ContainsKey(driver)) + { + driversAngularSynchronizationEnable.Add(driver, true); + } + + if (enable && driversAngularSynchronizationEnable.ContainsKey(driver)) + { + driversAngularSynchronizationEnable[driver] = true; + } + } + } +} From 00975f6e7cb19e609698a412fbe07577c7f99644 Mon Sep 17 00:00:00 2001 From: pstryczek Date: Fri, 15 Sep 2017 13:44:31 +0200 Subject: [PATCH 08/17] Added unit test to framework --- .../App.config | 83 +++++++++++++ ...jectivity.Test.Automation.UnitTests.csproj | 109 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 38 ++++++ .../Tests/DriversCustomSettingsUnitTests.cs | 48 ++++++++ .../packages.config | 4 + TestFramework.sln | 6 + 6 files changed, 288 insertions(+) create mode 100644 Objectivity.Test.Automation.UnitTests/App.config create mode 100644 Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj create mode 100644 Objectivity.Test.Automation.UnitTests/Properties/AssemblyInfo.cs create mode 100644 Objectivity.Test.Automation.UnitTests/Tests/DriversCustomSettingsUnitTests.cs create mode 100644 Objectivity.Test.Automation.UnitTests/packages.config diff --git a/Objectivity.Test.Automation.UnitTests/App.config b/Objectivity.Test.Automation.UnitTests/App.config new file mode 100644 index 000000000..82bcd554d --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/App.config @@ -0,0 +1,83 @@ + + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + add key="FirefoxPluginName.xpi" value=""/--> + + + + + + add key="ChromePluginName.crx" value=""/--> + + + add key="CapabilityName" value=""/--> + + + + + diff --git a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj new file mode 100644 index 000000000..371ec5cee --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj @@ -0,0 +1,109 @@ + + + + Debug + AnyCPU + {4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9} + Library + Properties + Objectivity.Test.Automation.UnitTests + Objectivity.Test.Automation.UnitTests + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll + True + + + + ..\packages\Selenium.WebDriver.3.4.0\lib\net40\WebDriver.dll + + + + + + + + + + + + + + + + + Designer + + + + + + {46fa4edc-a114-4e8f-a545-996f99e31ea8} + Objectivity.Test.Automation.Common + + + + + + + False + + + False + + + False + + + False + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/Objectivity.Test.Automation.UnitTests/Properties/AssemblyInfo.cs b/Objectivity.Test.Automation.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..35cb405a4 --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using NUnit.Framework; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Objectivity.Test.Automation.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Objectivity.Test.Automation.UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: Parallelizable(ParallelScope.Fixtures)] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4f7a9d54-779a-4f45-91dc-4c8b81b4a9c9")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Objectivity.Test.Automation.UnitTests/Tests/DriversCustomSettingsUnitTests.cs b/Objectivity.Test.Automation.UnitTests/Tests/DriversCustomSettingsUnitTests.cs new file mode 100644 index 000000000..54ef728ca --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/Tests/DriversCustomSettingsUnitTests.cs @@ -0,0 +1,48 @@ +// +// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved. +// +// +// 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. +// + +namespace Objectivity.Test.Automation.UnitTests.Tests +{ + using NUnit.Framework; + using Common; + using Common.Extensions; + + [TestFixture, Parallelizable(ParallelScope.Fixtures)] + public class DriversCustomSettingsUnitTests + { + [Test] + public void CheckSynchronizationWithAngularFuctionality() + { + var driverContext = new DriverContext {CurrentDirectory = TestContext.CurrentContext.TestDirectory}; + driverContext.Start(); + var Default_false = DriversCustomSettings.IsDriverSynchronizationWithAngular(driverContext.Driver); + driverContext.Driver.SynchronizeWithAngular(true); + var TurnOn_true = DriversCustomSettings.IsDriverSynchronizationWithAngular(driverContext.Driver); + driverContext.Driver.SynchronizeWithAngular(false); + var TurnOn_false = DriversCustomSettings.IsDriverSynchronizationWithAngular(driverContext.Driver); + driverContext.Stop(); + Assert.False(Default_false, "Default setting is not false"); + Assert.True(TurnOn_true, "Setting is not true"); + Assert.False(TurnOn_false, "Setting is not false"); + } + } +} diff --git a/Objectivity.Test.Automation.UnitTests/packages.config b/Objectivity.Test.Automation.UnitTests/packages.config new file mode 100644 index 000000000..01feaf467 --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TestFramework.sln b/TestFramework.sln index 503cbc2f3..4b153ba67 100644 --- a/TestFramework.sln +++ b/TestFramework.sln @@ -24,6 +24,8 @@ Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "Objectivity.Test.Automation EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Objectivity.Test.Automation.Tests.Angular", "Objectivity.Test.Automation.Tests.Angular\Objectivity.Test.Automation.Tests.Angular.csproj", "{EE625CF5-B283-44A9-A35F-0BFBBF4D409E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Objectivity.Test.Automation.UnitTests", "Objectivity.Test.Automation.UnitTests\Objectivity.Test.Automation.UnitTests.csproj", "{4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,10 @@ Global {EE625CF5-B283-44A9-A35F-0BFBBF4D409E}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE625CF5-B283-44A9-A35F-0BFBBF4D409E}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE625CF5-B283-44A9-A35F-0BFBBF4D409E}.Release|Any CPU.Build.0 = Release|Any CPU + {4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F7A9D54-779A-4F45-91DC-4C8B81B4A9C9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 88a2f5ed3a630dbadb9e05afff6133d25fed7b31 Mon Sep 17 00:00:00 2001 From: pstryczek Date: Fri, 15 Sep 2017 15:05:56 +0200 Subject: [PATCH 09/17] Fix error in csproj --- ...jectivity.Test.Automation.UnitTests.csproj | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj index 371ec5cee..04ffa7485 100644 --- a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj +++ b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj @@ -62,7 +62,9 @@ Designer - + + Designer + @@ -90,20 +92,4 @@ - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file From 35f22aedf61884819544e6441ecab2b705430efb Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Fri, 15 Sep 2017 16:43:57 +0200 Subject: [PATCH 10/17] Update README.md file --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 031b4c800..e89eb79ac 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Projects examples of using Test Framework : - Objectivity.Test.Automation.Tests.xUnit for xUnit - Objectivity.Test.Automation.Tests.PageObjects for Page Object Pattern - Objectivity.Test.Automation.Common.Documentation.shfbproj for building API documentation +- Objectivity.Test.Automation.UnitTests for unit test of framework NUnit Example Test: From 1282e559fa7a0fddfc4554d69913e9ed34d9eea1 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 08:38:43 +0200 Subject: [PATCH 11/17] fixed bug in WaitHelper, added WaitHelperTests unit tests, updated NUnit to version 3.8.1 --- Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs | 4 +++- .../Objectivity.Test.Automation.Tests.NUnit.csproj | 4 ++-- .../Tests/PerformanceTestsNUnit.cs | 1 + Objectivity.Test.Automation.Tests.NUnit/packages.config | 8 ++++---- Objectivity.Test.Automation.UnitTests/App.config | 4 ++-- .../Objectivity.Test.Automation.UnitTests.csproj | 6 ++++++ README.md | 8 ++++---- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs b/Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs index cc28d0d71..45492d2ef 100644 --- a/Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs +++ b/Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs @@ -114,6 +114,7 @@ public static void Wait(Func condition, TimeSpan timeout, TimeSpan sleepIn /// public static bool Wait(Func condition, TimeSpan timeout, TimeSpan sleepInterval) { + var result = false; var start = DateTime.Now; var canceller = new CancellationTokenSource(); var task = Task.Factory.StartNew(condition, canceller.Token); @@ -124,6 +125,7 @@ public static bool Wait(Func condition, TimeSpan timeout, TimeSpan sleepIn { if (task.Result) { + result = true; canceller.Cancel(); break; } @@ -143,7 +145,7 @@ public static bool Wait(Func condition, TimeSpan timeout, TimeSpan sleepIn } canceller.Cancel(); - return false; + return result; } } } diff --git a/Objectivity.Test.Automation.Tests.NUnit/Objectivity.Test.Automation.Tests.NUnit.csproj b/Objectivity.Test.Automation.Tests.NUnit/Objectivity.Test.Automation.Tests.NUnit.csproj index 9c626cbbc..78e29c8b6 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/Objectivity.Test.Automation.Tests.NUnit.csproj +++ b/Objectivity.Test.Automation.Tests.NUnit/Objectivity.Test.Automation.Tests.NUnit.csproj @@ -58,8 +58,8 @@ ..\packages\NLog.4.3.5\lib\net45\NLog.dll True - - ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll + + ..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll True diff --git a/Objectivity.Test.Automation.Tests.NUnit/Tests/PerformanceTestsNUnit.cs b/Objectivity.Test.Automation.Tests.NUnit/Tests/PerformanceTestsNUnit.cs index 55c893494..47eb19586 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/Tests/PerformanceTestsNUnit.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/Tests/PerformanceTestsNUnit.cs @@ -29,6 +29,7 @@ namespace Objectivity.Test.Automation.Tests.NUnit.Tests /// Tests to test framework /// [TestFixture] + [Parallelizable(ParallelScope.None)] public class PerformanceTestsNUnit : ProjectTestBase { [Test] diff --git a/Objectivity.Test.Automation.Tests.NUnit/packages.config b/Objectivity.Test.Automation.Tests.NUnit/packages.config index a006168d2..b37062ef6 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/packages.config +++ b/Objectivity.Test.Automation.Tests.NUnit/packages.config @@ -2,13 +2,13 @@ - + - - + + - + \ No newline at end of file diff --git a/Objectivity.Test.Automation.UnitTests/App.config b/Objectivity.Test.Automation.UnitTests/App.config index 82bcd554d..a9047e259 100644 --- a/Objectivity.Test.Automation.UnitTests/App.config +++ b/Objectivity.Test.Automation.UnitTests/App.config @@ -33,7 +33,7 @@ - + @@ -59,7 +59,7 @@ - + diff --git a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj index 04ffa7485..a511f0d43 100644 --- a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj +++ b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj @@ -55,6 +55,8 @@ + + @@ -71,6 +73,10 @@ {46fa4edc-a114-4e8f-a545-996f99e31ea8} Objectivity.Test.Automation.Common + + {74F9B9A8-0055-4C13-B3C9-FACED546CB43} + Objectivity.Test.Automation.Tests.NUnit + diff --git a/README.md b/README.md index e89eb79ac..4e5ec40f8 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ namespace Objectivity.Test.Automation.Tests.PageObjects.PageObjects.TheInternet - See [Getting started](https://github.com/ObjectivityLtd/Test.Automation/wiki/Getting%20started). Checkout the code or get it from [nuget.org](https://www.nuget.org/packages?q=Objectivity.Test.Automation.Common) -- Objectivity.Test.Automation.Common.NUnit [nuget](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.NUnit/) -- Objectivity.Test.Automation.Common.Features [nuget](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.Features/) -- Objectivity.Test.Automation.Common.MsTest [nuget](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.MsTest/) -- Objectivity.Test.Automation.Common.xUnit [nuget](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.xUnit/) +- Objectivity.Test.Automation.Common.NUnit [![NuGet Package](https://img.shields.io/nuget/v/Objectivity.Test.Automation.Common.NUnit.svg)](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.NUnit/) +- Objectivity.Test.Automation.Common.Features [![NuGet Package](https://img.shields.io/nuget/v/Objectivity.Test.Automation.Common.Features.svg)](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.Features/) +- Objectivity.Test.Automation.Common.MsTest [![NuGet Package](https://img.shields.io/nuget/v/Objectivity.Test.Automation.Common.MsTest.svg)](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.MsTest/) +- Objectivity.Test.Automation.Common.xUnit [![NuGet Package](https://img.shields.io/nuget/v/Objectivity.Test.Automation.Common.xUnit.svg)](https://www.nuget.org/packages/Objectivity.Test.Automation.Common.xUnit/) From 5722ad437ea7b2da439f821346ba2913b604ce47 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 08:48:59 +0200 Subject: [PATCH 12/17] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4e5ec40f8..4fb4fc54c 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,11 @@ Test Framework was designed in Objectivity to propose common way how people should create Selenium WebDriver tests. + + Project API documentation can be found here: http://objectivityltd.github.io/Test.Automation + It provides following features: - Ready for parallel tests execution, more details [here](https://github.com/ObjectivityLtd/Test.Automation/wiki/Selenium%20Parallel%20tests%20execution) - Possibility to use MSTest, NUnit or xUNIT framework From e5252bd4c84f27e72da1d0210ecbd91033c0674a Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 08:50:22 +0200 Subject: [PATCH 13/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fb4fc54c..aeac3a4f5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Test Framework was designed in Objectivity to propose common way how people shou Project API documentation can be found here: http://objectivityltd.github.io/Test.Automation -It provides following features: +**It provides following features:** - Ready for parallel tests execution, more details [here](https://github.com/ObjectivityLtd/Test.Automation/wiki/Selenium%20Parallel%20tests%20execution) - Possibility to use MSTest, NUnit or xUNIT framework - Specflow ready From 5921a373ef4b3107b858c0c65d1c83d7c84d2fcc Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 08:52:05 +0200 Subject: [PATCH 14/17] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index aeac3a4f5..ce16787ea 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ Test Framework was designed in Objectivity to propose common way how people should create Selenium WebDriver tests. - -Project API documentation can be found here: http://objectivityltd.github.io/Test.Automation - +Project API documentation can be found here: http://objectivityltd.github.io/Test.Automation

**It provides following features:** - Ready for parallel tests execution, more details [here](https://github.com/ObjectivityLtd/Test.Automation/wiki/Selenium%20Parallel%20tests%20execution) From f723c3f0fea35cc6359185b3485afd8b3dce9afb Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 08:57:27 +0200 Subject: [PATCH 15/17] Added WaitHelperTests --- ...jectivity.Test.Automation.UnitTests.csproj | 1 - .../Tests/WaitHelperTests.cs | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Objectivity.Test.Automation.UnitTests/Tests/WaitHelperTests.cs diff --git a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj index a511f0d43..29429f29a 100644 --- a/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj +++ b/Objectivity.Test.Automation.UnitTests/Objectivity.Test.Automation.UnitTests.csproj @@ -55,7 +55,6 @@
- diff --git a/Objectivity.Test.Automation.UnitTests/Tests/WaitHelperTests.cs b/Objectivity.Test.Automation.UnitTests/Tests/WaitHelperTests.cs new file mode 100644 index 000000000..c95d2bb19 --- /dev/null +++ b/Objectivity.Test.Automation.UnitTests/Tests/WaitHelperTests.cs @@ -0,0 +1,42 @@ +using System; +using NUnit.Framework; +using Objectivity.Test.Automation.Common.Exceptions; +using Objectivity.Test.Automation.Common.Helpers; + +namespace Objectivity.Test.Automation.UnitTests.Tests +{ + [TestFixture()] + [TestFixture, Parallelizable(ParallelScope.Self)] + public class WaitHelperTests + { + [Test()] + public void WaitTimeoutExceptionTest() + { + var start = DateTime.Now; + int wait = 3; + Assert.Throws(() => WaitHelper.Wait(() => SumNumber(1,1) > 3, TimeSpan.FromSeconds(wait), TimeSpan.FromSeconds(1), "Timeout")); + var stop = DateTime.Now; + Assert.True(stop - start >= TimeSpan.FromSeconds(wait)); + Assert.False(stop - start < TimeSpan.FromSeconds(wait)); + } + + [Test()] + public void WaitReturnFalseTest() + { + bool result = WaitHelper.Wait(() => SumNumber(1, 1) > 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1)); + Assert.False(result); + } + + [Test()] + public void WaitReturnTrueTest() + { + bool result = WaitHelper.Wait(() => SumNumber(1, 1) > 1, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1)); + Assert.True(result); + } + + int SumNumber(int a, int b) + { + return a + b; + } + } +} \ No newline at end of file From 2d677050c28d400fd5419e270e12a4db7f0b00db Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 09:44:02 +0200 Subject: [PATCH 16/17] Added DeleteAllCookies(), Fixes #57 --- Objectivity.Test.Automation.Common/DriverContext.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Objectivity.Test.Automation.Common/DriverContext.cs b/Objectivity.Test.Automation.Common/DriverContext.cs index 2bbf134a9..f7e71f15e 100644 --- a/Objectivity.Test.Automation.Common/DriverContext.cs +++ b/Objectivity.Test.Automation.Common/DriverContext.cs @@ -479,6 +479,14 @@ public void WindowMaximize() this.driver.Manage().Window.Maximize(); } + /// + /// Deletes all cookies from the page. + /// + public void DeleteAllCookies() + { + this.driver.Manage().Cookies.DeleteAllCookies(); + } + /// /// Stop browser instance. /// From f94b1ddab23cffb5ec8bee6b2044438b45c0f1f0 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 19 Sep 2017 09:57:17 +0200 Subject: [PATCH 17/17] Updated NUnit --- .nuspec/Objectivity.Test.Automation.Features.nuspec | 2 +- .nuspec/Objectivity.Test.Automation.Nunit.nuspec | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.nuspec/Objectivity.Test.Automation.Features.nuspec b/.nuspec/Objectivity.Test.Automation.Features.nuspec index 995fb3af6..e5548fdd6 100644 --- a/.nuspec/Objectivity.Test.Automation.Features.nuspec +++ b/.nuspec/Objectivity.Test.Automation.Features.nuspec @@ -16,7 +16,7 @@ selenium webdriver testautomation tests specflow Objectivity.Test.Automation.Common template - + diff --git a/.nuspec/Objectivity.Test.Automation.Nunit.nuspec b/.nuspec/Objectivity.Test.Automation.Nunit.nuspec index aebba2366..6d73d856b 100644 --- a/.nuspec/Objectivity.Test.Automation.Nunit.nuspec +++ b/.nuspec/Objectivity.Test.Automation.Nunit.nuspec @@ -15,13 +15,13 @@ Copyright 2015 selenium webdriver testautomation tests nunit Objectivity.Test.Automation.Common - + - - + +