From ae935e254bd0e2ebd62dc48f0eff171807acd67e Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Mon, 12 Feb 2018 09:45:55 +0100 Subject: [PATCH] Added NUnit DataDrive from Excel (xlsx) files, reviewer pstryczek --- .../App.config | 1 + .../DataDriven/DataDriven.xlsx | Bin 0 -> 10351 bytes .../DataDriven/DataDrivenHelper.cs | 102 +++++++++++++++++- .../DataDriven/TestData.cs | 10 ++ ...ctivity.Test.Automation.Tests.NUnit.csproj | 24 +++++ .../ProjectBaseConfiguration.cs | 19 ++++ .../Tests/HerokuappTestsDataDrivenNUnit.cs | 96 +++++++++++++++++ .../Tests/HerokuappTestsNUnit.cs | 36 ------- .../packages.config | 2 + 9 files changed, 253 insertions(+), 37 deletions(-) create mode 100644 Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDriven.xlsx create mode 100644 Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsDataDrivenNUnit.cs diff --git a/Objectivity.Test.Automation.Tests.NUnit/App.config b/Objectivity.Test.Automation.Tests.NUnit/App.config index c86cd8a52..f316e9585 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/App.config +++ b/Objectivity.Test.Automation.Tests.NUnit/App.config @@ -55,6 +55,7 @@ + diff --git a/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDriven.xlsx b/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDriven.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5cafebe82759168f2f0295d704bdba475e7f28e1 GIT binary patch literal 10351 zcmeHN^;;a7A&|Y1PJa9$ z-al|}|Iq#Q*HdeD@2*u$7UZDK;A&+_ob%#2RTji^@bCY7{0GlKr&6DFI}oK=b&p@TMJ3cvNLl#> zvUU_b+8Lx24+&PNl^Zm?&vK}`k}{nj@p&v&`L@-Cluw=co)O%$$jbU1W5O6;`ZRXu z58Gi zxwl7|jws7c?~mQQFi^K5>^?dnxqe@d&e~3*#e5ST+Gy(R@T|35c6a65E2!<5&u@J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;8*lvu{UBoP1T{a84ONvH;@k$tD`m^B!}a~OhLgI~i~ z=Ti7U=I`041s~Qps6#RKaU*z8uvq05m1%c>PAJVigu4$H2WsTeCLEWC`lOD1)l`V~ zd&>no3xKgm75#YlE9S7PJ$9etGfG489d?D89;}Mq;Nhp7gI{LP@{|!3e zDf{C{i*2)>|Ji_ryg&{*j9e(93VNd=|B>EZtsFwUk%e-iTuu{>?3>ulS+3Qj-M0?k zMX`so(h;($p=_%PWW$Oj%r*O%aK!ZEPfoXjJV&n>TEgj2>(KCy%23`)t%>^F=dh2# zL>MuFELRms%yY_OnUnD}#SlIa(k4XHqkOhw^ioz2a9L`q-VtLsz0+9p8%DY4J{?9T9H#MdP1j?4IX7p zNTiZkHPulvr4uE&XxRHvc0I%K!d&IxAkV>AukCVrkqdmZi`RiW#2U7pYF_h6h<4~; z6?dR#S_z<_5R2cvhBEB2UEVxCknI<6+P$RrLVuOO&ZMC2ta9$nM<3Leh=8LIL(&gT zf(Se<=<674-i(QGcO46*Qj$JY9tS2JpoF$6@?hl08LvTD|^82_^W2^0!*{DZ*dNy5IH?5EXR!oLB8h<^>>NeceQl>8L*uR;GeBm@K%>7T~*M+%UWgaUi=&t4=Fge8~^ J2V_6*{s*Eq$aVk# literal 0 HcmV?d00001 diff --git a/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDrivenHelper.cs b/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDrivenHelper.cs index 05d60886a..85f82bc9d 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDrivenHelper.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/DataDriven/DataDrivenHelper.cs @@ -25,18 +25,24 @@ namespace Objectivity.Test.Automation.Tests.NUnit.DataDriven using System; using System.Collections.Generic; using System.Globalization; + using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Xml.Linq; using Common.Exceptions; using global::NUnit.Framework; + using NLog; + using NPOI.SS.UserModel; + using NPOI.XSSF.UserModel; /// /// XML DataDriven methods for NUnit test framework More details on wiki /// public static class DataDrivenHelper { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + /// /// Reads the data drive file and set test name. /// @@ -117,6 +123,100 @@ public static IEnumerable ReadDataDriveFile(string folder, string return doc.Descendants(testData).Select(element => element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value)).Select(testParams => new TestCaseData(testParams)); } + /// + /// Reads the Excel data drive file and optionaly set test name. + /// + /// Full path to Excel DataDriveFile file + /// Name of the sheet at xlsx file. + /// Optional values of listed parameters will be used in test case name. + /// Optional name of the test, use as prefix for test case name. + /// + /// IEnumerable TestCaseData + /// + /// Exception when wrong cell type in file + /// Exception when parameter not found in row + /// How to use it: + /// public static IEnumerable CredentialsFromExcel + /// { + /// get { return DataDrivenHelper.ReadXlsxDataDriveFile(ProjectBaseConfiguration.DataDrivenFileXlsx, "credential", new[] { "user", "password" }, "credentialExcel"); } + /// } + /// + public static IEnumerable ReadXlsxDataDriveFile(string path, string sheetName, [Optional] string[] diffParam, [Optional] string testName) + { + Logger.Debug("Sheet {0} in file: {1}", sheetName, path); + XSSFWorkbook wb; + + using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) + { + wb = new XSSFWorkbook(fs); + } + + // get sheet + var sh = (XSSFSheet)wb.GetSheet(sheetName); + + int startRow = 1; + int startCol = 0; + int totalRows = sh.LastRowNum; + int totalCols = sh.GetRow(0).LastCellNum; + + var row = 1; + for (int i = startRow; i <= totalRows; i++, row++) + { + var column = 0; + var testParams = new Dictionary(); + for (int j = startCol; j < totalCols; j++, column++) + { + if (sh.GetRow(0).GetCell(column).CellType != CellType.String) + { + throw new InvalidOperationException(string.Format("Cell with name of parameter must be string only, file {0} at sheet {1} row {2} column {3}", path, sheetName, 0, column)); + } + + var cellType = sh.GetRow(row).GetCell(column).CellType; + switch (cellType) + { + case CellType.String: + testParams.Add(sh.GetRow(0).GetCell(column).StringCellValue, sh.GetRow(row).GetCell(column).StringCellValue); + break; + case CellType.Numeric: + testParams.Add(sh.GetRow(0).GetCell(column).StringCellValue, sh.GetRow(row).GetCell(column).NumericCellValue.ToString(CultureInfo.CurrentCulture)); + break; + default: + throw new InvalidOperationException(string.Format("Not supported cell type {0} in file {1} at sheet {2} row {3} column {4}", cellType, path, sheetName, row, column)); + } + } + + // set test name + var testCaseName = string.IsNullOrEmpty(testName) ? sheetName : testName; + + if (diffParam != null && diffParam.Any()) + { + try + { + testCaseName = TestCaseName(diffParam, testParams, testCaseName); + } + catch (DataDrivenReadException e) + { + throw new DataDrivenReadException( + string.Format( + " Exception while reading Excel Data Driven file\n searched key '{0}' not found at sheet '{1}' \n for test {2} in file '{3}' at row {4}", + e.Message, + sheetName, + testName, + path, + row)); + } + } + else + { + testCaseName = testCaseName + "_row(" + row + ")"; + } + + var data = new TestCaseData(testParams); + data.SetName(testCaseName); + yield return data; + } + } + /// /// Get the name of test case from value of parameters. /// @@ -150,5 +250,5 @@ private static string TestCaseName(string[] diffParam, Dictionarytrue + + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + True + ..\packages\NLog.4.3.5\lib\net45\NLog.dll True + + ..\packages\NPOI.2.3.0\lib\net40\NPOI.dll + True + + + ..\packages\NPOI.2.3.0\lib\net40\NPOI.OOXML.dll + True + + + ..\packages\NPOI.2.3.0\lib\net40\NPOI.OpenXml4Net.dll + True + + + ..\packages\NPOI.2.3.0\lib\net40\NPOI.OpenXmlFormats.dll + True + ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll True @@ -84,6 +104,7 @@ Code + @@ -94,6 +115,9 @@ Designer + + Always + Designer diff --git a/Objectivity.Test.Automation.Tests.NUnit/ProjectBaseConfiguration.cs b/Objectivity.Test.Automation.Tests.NUnit/ProjectBaseConfiguration.cs index 4f97c2f3b..8f532792a 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/ProjectBaseConfiguration.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/ProjectBaseConfiguration.cs @@ -54,6 +54,25 @@ public static string DataDrivenFile } } + /// + /// Gets the Excel data driven file. + /// + /// + /// The Excel data driven file. + /// + public static string DataDrivenFileXlsx + { + get + { + if (BaseConfiguration.UseCurrentDirectory) + { + return Path.Combine(CurrentDirectory + ConfigurationManager.AppSettings["DataDrivenFileXlsx"]); + } + + return ConfigurationManager.AppSettings["DataDrivenFileXlsx"]; + } + } + /// /// Gets the Download Folder path /// diff --git a/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsDataDrivenNUnit.cs b/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsDataDrivenNUnit.cs new file mode 100644 index 000000000..d022992e2 --- /dev/null +++ b/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsDataDrivenNUnit.cs @@ -0,0 +1,96 @@ +// +// 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.Tests.NUnit.Tests +{ + using System.Collections.Generic; + using Automation.Tests.PageObjects.PageObjects.TheInternet; + using Common; + using DataDriven; + using global::NUnit.Framework; + + [TestFixture] + [Parallelizable(ParallelScope.Fixtures)] + public class HerokuappTestsDataDrivenNUnit : ProjectTestBase + { + [Test] + [TestCaseSource(typeof(TestData), "Credentials")] + public void FormAuthenticationPageTest(IDictionary parameters) + { + new InternetPage(this.DriverContext).OpenHomePage().GoToFormAuthenticationPage(); + + var formFormAuthentication = new FormAuthenticationPage(this.DriverContext); + formFormAuthentication.EnterUserName(parameters["user"]); + formFormAuthentication.EnterPassword(parameters["password"]); + formFormAuthentication.LogOn(); + Verify.That( + this.DriverContext, + () => Assert.AreEqual(parameters["message"], formFormAuthentication.GetMessage)); + } + + [Test] + [TestCaseSource(typeof(TestData), "CredentialsExcel")] + public void FormAuthenticationPageExcelTest(IDictionary parameters) + { + new InternetPage(this.DriverContext).OpenHomePage().GoToFormAuthenticationPage(); + + var formFormAuthentication = new FormAuthenticationPage(this.DriverContext); + formFormAuthentication.EnterUserName(parameters["user"]); + formFormAuthentication.EnterPassword(parameters["password"]); + formFormAuthentication.LogOn(); + Verify.That( + this.DriverContext, + () => Assert.AreEqual(parameters["message"], formFormAuthentication.GetMessage)); + } + + [Test] + [Category("PhantomJs")] + [TestCaseSource(typeof(TestData), "LinksSetTestName")] + public void CountLinksAndSetTestNameAtShiftingContentTest(IDictionary parameters) + { + new InternetPage(this.DriverContext).OpenHomePage().GoToShiftingContentPage(); + + var links = new ShiftingContentPage(this.DriverContext); + Verify.That(this.DriverContext, () => Assert.AreEqual(parameters["number"], links.CountLinks())); + } + + [Test] + [TestCaseSource(typeof(TestData), "LinksExcel")] + public void CountLinksAndSetTestNameAtShiftingContentExcelTest(IDictionary parameters) + { + new InternetPage(this.DriverContext).OpenHomePage().GoToShiftingContentPage(); + + var links = new ShiftingContentPage(this.DriverContext); + Verify.That(this.DriverContext, () => Assert.AreEqual(parameters["number"], links.CountLinks())); + } + + [Test] + [TestCaseSource(typeof(TestData), "Links")] + public void CountLinksAtShiftingContentTest(IDictionary parameters) + { + new InternetPage(this.DriverContext).OpenHomePage().GoToShiftingContentPage(); + + var links = new ShiftingContentPage(this.DriverContext); + Verify.That(this.DriverContext, () => Assert.AreEqual(parameters["number"], links.CountLinks())); + } + } +} diff --git a/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsNUnit.cs b/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsNUnit.cs index d6cf9b6b0..f0e0bc415 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsNUnit.cs +++ b/Objectivity.Test.Automation.Tests.NUnit/Tests/HerokuappTestsNUnit.cs @@ -46,21 +46,6 @@ public void BasicAuthTest() basicAuthPage.GetCongratulationsInfo)); } - [Test] - [TestCaseSource(typeof(TestData), "Credentials")] - public void FormAuthenticationPageTest(IDictionary parameters) - { - new InternetPage(this.DriverContext).OpenHomePage().GoToFormAuthenticationPage(); - - var formFormAuthentication = new FormAuthenticationPage(this.DriverContext); - formFormAuthentication.EnterUserName(parameters["user"]); - formFormAuthentication.EnterPassword(parameters["password"]); - formFormAuthentication.LogOn(); - Verify.That( - this.DriverContext, - () => Assert.AreEqual(parameters["message"], formFormAuthentication.GetMessage)); - } - [Test] public void ForgotPasswordTest() { @@ -74,27 +59,6 @@ public void ForgotPasswordTest() () => Assert.AreEqual("Your e-mail's been sent!", forgotPassword.ClickRetrievePassword)); } - [Test] - [Category("PhantomJs")] - [TestCaseSource(typeof(TestData), "LinksSetTestName")] - public void CountLinksAndSetTestNameAtShiftingContentTest(IDictionary parameters) - { - new InternetPage(this.DriverContext).OpenHomePage().GoToShiftingContentPage(); - - var links = new ShiftingContentPage(this.DriverContext); - Verify.That(this.DriverContext, () => Assert.AreEqual(parameters["number"], links.CountLinks())); - } - - [Test] - [TestCaseSource(typeof(TestData), "Links")] - public void CountLinksAtShiftingContentTest(IDictionary parameters) - { - new InternetPage(this.DriverContext).OpenHomePage().GoToShiftingContentPage(); - - var links = new ShiftingContentPage(this.DriverContext); - Verify.That(this.DriverContext, () => Assert.AreEqual(parameters["number"], links.CountLinks())); - } - [Test] [Category("PhantomJs")] public void MultipleWindowsTest() diff --git a/Objectivity.Test.Automation.Tests.NUnit/packages.config b/Objectivity.Test.Automation.Tests.NUnit/packages.config index a380bbba2..eebebab40 100644 --- a/Objectivity.Test.Automation.Tests.NUnit/packages.config +++ b/Objectivity.Test.Automation.Tests.NUnit/packages.config @@ -2,6 +2,7 @@ + @@ -14,5 +15,6 @@ + \ No newline at end of file