├── Utils ├── Credentials.cs ├── DateHelper.cs ├── StringHelper.cs └── TableHelper.cs ├── Home.cs ├── PageOps.cs ├── PageObjects ├── Home.cs └── Login.cs ├── Automation.sln ├── Driver.cs ├── Automation.csproj ├── .gitattributes ├── Login.cs ├── .gitignore ├── PageAction.cs └── Check.cs /Utils/Credentials.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenQA.Selenium; 7 | 8 | namespace Automation.Utils 9 | { 10 | public class Credentials 11 | { 12 | public string UserName { get; set; } 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Home.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using OpenQA.Selenium; 3 | 4 | namespace Automation 5 | { 6 | 7 | public class Home 8 | { 9 | private IWebDriver _driver; 10 | private string _url; 11 | 12 | 13 | public Home(IWebDriver driver,string url) 14 | { 15 | _driver = driver; 16 | _url = url; 17 | 18 | } 19 | 20 | public void GoToHome() 21 | { 22 | 23 | 24 | _driver.Navigate().GoToUrl(_url); 25 | _driver.Manage().Window.Maximize(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /PageOps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Automation.PageObjects; 9 | 10 | using NUnit.Framework.Internal; 11 | using OpenQA.Selenium; 12 | 13 | namespace Automation 14 | { 15 | public class PageOps 16 | { 17 | 18 | private readonly PageAction _action; 19 | private readonly Login _login; 20 | private readonly IWebDriver _driver; 21 | private readonly Check _check; 22 | 23 | public PageOps(Login login, PageAction action, IWebDriver driver, Check check) 24 | { 25 | _check = check; 26 | _login = login; 27 | _action = action; 28 | _driver = driver; 29 | } 30 | 31 | 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /PageObjects/Home.cs: -------------------------------------------------------------------------------- 1 | 2 | using OpenQA.Selenium; 3 | 4 | namespace Automation.PageObjects 5 | { 6 | public class Home 7 | { 8 | private IWebDriver _driver; 9 | 10 | public Home(IWebDriver driver) 11 | { 12 | _driver = driver; 13 | } 14 | 15 | public class PageLabels 16 | { 17 | 18 | } 19 | public class PageLinks 20 | { 21 | 22 | } 23 | 24 | public class PageTextBox 25 | { 26 | } 27 | 28 | public class PageTitle 29 | { 30 | public static string SubmitMaritimeStatisticsTitle = "/html/head/title"; 31 | } 32 | public class PageButton 33 | { 34 | public static string StartNow = "//*[@id='start-btn']"; 35 | public static string Login = ""; 36 | 37 | } 38 | public class PageCheckBox 39 | { 40 | 41 | } 42 | 43 | public class PageImage 44 | { 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Automation.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29209.62 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Automation", "Automation.csproj", "{332176C7-1045-4BB5-A6D6-88983ADF4DB3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {332176C7-1045-4BB5-A6D6-88983ADF4DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {332176C7-1045-4BB5-A6D6-88983ADF4DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {332176C7-1045-4BB5-A6D6-88983ADF4DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {332176C7-1045-4BB5-A6D6-88983ADF4DB3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {778DD0E9-71C0-4C6C-808F-1BA05200167B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Driver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenQA.Selenium.Firefox; 3 | using OpenQA.Selenium.Chrome; 4 | using OpenQA.Selenium; 5 | 6 | namespace Automation 7 | { 8 | // 9 | public static class Driver 10 | { 11 | private static IWebDriver _webDriver; 12 | 13 | public static IWebDriver Instance 14 | { 15 | get 16 | { 17 | return _webDriver ?? Create(); 18 | } 19 | } 20 | 21 | private static IWebDriver Create() 22 | { 23 | _webDriver = new ChromeDriver(); 24 | return _webDriver; 25 | } 26 | 27 | public static void Initialise() 28 | { 29 | _webDriver = new ChromeDriver(); 30 | } 31 | 32 | public static void Initialise(ChromeOptions opt) 33 | { 34 | _webDriver = new ChromeDriver(".",opt); 35 | } 36 | public static void Close() 37 | { 38 | if (_webDriver == null) return; 39 | _webDriver.Close(); 40 | _webDriver.Quit(); 41 | } 42 | 43 | public static IJavaScriptExecutor Scripts(this IWebDriver driver) 44 | { 45 | return (IJavaScriptExecutor)driver; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Automation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Utils/DateHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Automation.Utils 8 | { 9 | public static class DateHelper 10 | { 11 | public static string GetLongDate(string input)//Date Helper Method 12 | { 13 | if (input is "Today") 14 | { 15 | DateTime dateNow = DateTime.Now; 16 | string date = dateNow.ToString("dd/MM/yyyy"); 17 | 18 | return date; 19 | } 20 | else if (input.Contains("Today+")) 21 | { 22 | string days = input.Substring(input.LastIndexOf("+")); 23 | int newInput = Convert.ToInt16(days); 24 | DateTime dateNow = DateTime.Now; 25 | DateTime newDate = dateNow.AddDays(newInput); 26 | string date = newDate.ToString("dd/MM/yyyy"); 27 | 28 | return date; 29 | } 30 | else if (input.Contains("Today-")) 31 | { 32 | string days = input.Substring(input.LastIndexOf("-")); 33 | int newInput = Convert.ToInt16(days); 34 | DateTime dateNow = DateTime.Now; 35 | int negDays = -System.Math.Abs(newInput); 36 | DateTime newDate = dateNow.AddDays(negDays); 37 | string date = newDate.ToString("dd/MM/yyyy"); 38 | 39 | return date; 40 | } 41 | else if (input == "NULL") 42 | { 43 | return "NULL"; 44 | } 45 | else 46 | { 47 | return input; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Utils/StringHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace Automation.Utils 9 | { 10 | public static class StringHelper 11 | { 12 | public static string UppercaseWords(string s) 13 | { 14 | char[] array = s.ToCharArray(); 15 | // Handle the first letter in the string. 16 | if (array.Length >= 1) 17 | { 18 | if (char.IsLower(array[0])) 19 | { 20 | array[0] = char.ToUpper(array[0]); 21 | } 22 | } 23 | 24 | // Scan through the letters, checking for spaces. 25 | // ... Uppercase the lowercase letters following spaces. 26 | for (int i = 1; i < array.Length; i++) 27 | { 28 | if (array[i - 1] == ' ') 29 | { 30 | if (char.IsLower(array[i])) 31 | { 32 | array[i] = char.ToUpper(array[i]); 33 | } 34 | } 35 | } 36 | return new string(array); 37 | 38 | } 39 | public static List ExtractFromString(string source, string start, string end) 40 | { 41 | var results = new List(); 42 | 43 | string pattern = string.Format( 44 | "{0}({1}){2}", 45 | Regex.Escape(start), 46 | ".+?", 47 | Regex.Escape(end)); 48 | 49 | foreach (Match m in Regex.Matches(source, pattern)) 50 | { 51 | results.Add(m.Groups[1].Value); 52 | } 53 | 54 | return results; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /PageObjects/Login.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | 3 | 4 | namespace Automation.PageObjects 5 | { 6 | 7 | public class Login 8 | { 9 | private IWebDriver _driver; 10 | 11 | 12 | public Login(IWebDriver driver) 13 | { 14 | _driver = driver; 15 | } 16 | 17 | IWebElement TxtUserName => _driver.FindElement(By.XPath(PageTextBox.User)); 18 | IWebElement TxtPassword => _driver.FindElement(By.XPath(PageTextBox.Password)); 19 | IWebElement BtnSignIn => _driver.FindElement(By.XPath(PageButton.SignIn)); 20 | 21 | public void EnterUserNameAndPassword(string userName, string password) 22 | { 23 | TxtUserName.SendKeys(userName); 24 | TxtPassword.SendKeys(password); 25 | } 26 | 27 | public void ClickLogin() 28 | { 29 | BtnSignIn.Click(); 30 | } 31 | 32 | 33 | public class PageLinks 34 | { 35 | 36 | public static string ForgotPassword = "//*[@id='lnkforgotpassword']"; 37 | } 38 | 39 | public class PageLabels 40 | { 41 | public static string Login = "//*[@id='hdrlogin']"; 42 | public static string Copyright = "//*[@id='lblcopyright']"; 43 | public static string RememberMe = "//*[@id='lblrememberme']"; 44 | 45 | } 46 | 47 | public class PageTextBox 48 | { 49 | public static string User = "//*[@id='username']"; 50 | public static string Password = "//*[@id='password']"; 51 | 52 | } 53 | 54 | public class PageButton 55 | { 56 | public static string SignIn = "//*[@id='btnsignin']"; 57 | } 58 | public class PageCheckBox 59 | { 60 | public static string RememberMe = "//*[@id='chkrememberme']"; 61 | } 62 | 63 | public class PageImage 64 | { 65 | public static string CubeLogo = "//*[@id='imgcubelogo']"; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Utils/TableHelper.cs: -------------------------------------------------------------------------------- 1 | using OpenQA.Selenium; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Automation.Utils 9 | { 10 | public static class TableHelper 11 | { 12 | private static List _tableDataCollections = new List(); 13 | 14 | 15 | public static List ReadTable(IWebElement table) 16 | { 17 | //Get all of the columns 18 | var columns = table.FindElements(By.TagName("th")); 19 | 20 | //Get all the rows 21 | var rows = table.FindElements(By.TagName("tr")); 22 | 23 | //Create row index 24 | int rowIndex = 0; 25 | 26 | foreach (var row in rows) 27 | { 28 | int colIndex = 0; 29 | 30 | var colDatas = row.FindElements(By.TagName(("td"))); 31 | 32 | foreach (var colValue in colDatas) 33 | { 34 | _tableDataCollections.Add(new TableDataCollection 35 | { 36 | RowNumber = rowIndex, 37 | ColumnName = columns[colIndex].Text, 38 | ColumnValue = colValue.Text 39 | }); 40 | //Move to next column 41 | colIndex++; 42 | 43 | } 44 | 45 | rowIndex++; 46 | } 47 | 48 | return _tableDataCollections; 49 | } 50 | 51 | public static string ReadCell(string columnName, int rowNumber) 52 | { 53 | var data = (from e in _tableDataCollections 54 | where e.ColumnName == columnName && e.RowNumber == rowNumber 55 | select e.ColumnValue).SingleOrDefault(); 56 | 57 | return data; 58 | } 59 | public class TableDataCollection 60 | { 61 | public int RowNumber { get; set; } 62 | public String ColumnName { get; set; } 63 | public string ColumnValue { get; set; } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Login.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing.Printing; 4 | using System.Drawing.Text; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | //using Automation.PageObjects; 10 | using OpenQA.Selenium; 11 | 12 | namespace Automation 13 | { 14 | public class Login 15 | { 16 | private IWebDriver _driver; 17 | private readonly string _loginpage; 18 | public Login(IWebDriver driver, string LoginPage) 19 | { 20 | _driver = driver; 21 | _loginpage = LoginPage; 22 | } 23 | public LoginCommand LoginAs(string username) 24 | { 25 | return new LoginCommand(username, _driver, _loginpage); 26 | // return LoginCommand; 27 | } 28 | 29 | public void GoToHome() 30 | { 31 | //var homePage = Driver.Instance; 32 | //homePage.Navigate().GoToUrl("https://localhost::44352/"); 33 | //Driver.Instance.Manage().Window.Maximize(); 34 | 35 | // var homePage = Driver.Instance; 36 | _driver.Navigate().GoToUrl("https://localhost::44352/"); 37 | _driver.Manage().Window.Maximize(); 38 | } 39 | 40 | 41 | public void LoginAsDeutscheBank1() 42 | { 43 | GoToHome(); 44 | LoginAs("DeutscheBank1@cube.global").WithPassword("C7FSy1p$gG").LoginToCube(); 45 | 46 | } 47 | 48 | public void LoginAsGbGAdmin() 49 | { 50 | GoToHome(); 51 | LoginAs("gbgadmin@cube.global").WithPassword("Xez4r^JC3_").LoginToCube(); 52 | 53 | } 54 | public class LoginCommand 55 | { 56 | private readonly IWebDriver _driver; 57 | private readonly string _userName; 58 | private string _password; 59 | private readonly string _loginpage; 60 | 61 | 62 | public LoginCommand(IWebDriver driver,string loginPage) 63 | { 64 | 65 | _driver = driver; 66 | _loginpage = loginPage; 67 | } 68 | 69 | 70 | public LoginCommand(string userName, IWebDriver driver, string loginPage) 71 | { 72 | _driver = driver; 73 | _userName = userName; 74 | _loginpage = loginPage; 75 | } 76 | 77 | public LoginCommand WithPassword(string password) 78 | { 79 | _password = password; 80 | return this; 81 | } 82 | 83 | public void LoginToCube() 84 | { 85 | 86 | 87 | Thread.Sleep(1000); 88 | _loginpage.EnterUserNameAndPassword(_userName, _password); 89 | Thread.Sleep(1000); 90 | _loginpage.ClickLogin(); 91 | 92 | } 93 | 94 | 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /PageAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing.Printing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | using OpenQA.Selenium; 10 | using OpenQA.Selenium.Interactions; 11 | using OpenQA.Selenium.Support.UI; 12 | using SeleniumExtras.WaitHelpers; 13 | namespace Automation 14 | { 15 | public class PageAction 16 | { 17 | 18 | private readonly IWebDriver _driver; 19 | private readonly Actions _action; 20 | private readonly Check _check; 21 | public PageAction(IWebDriver driver, Check check) 22 | { 23 | _driver = driver; 24 | _check = check; 25 | _action = new Actions(_driver); 26 | } 27 | 28 | public void ClickXpath(string El) 29 | { 30 | _driver.FindElement(By.XPath(El)).Click(); 31 | } 32 | 33 | public void MoveToXpath(string obj) 34 | { 35 | //WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10)); 36 | //////must first wait for the call to complete 37 | //wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath(obj))); 38 | 39 | //try 40 | //{ 41 | // IWebElement element = _driver.FindElement(By.XPath(obj)); 42 | // _action.MoveToElement(_driver.FindElement 43 | // (By.XPath(obj))).Build().Perform(); 44 | // Thread.Sleep(250); 45 | //} 46 | //catch (StaleElementReferenceException e) 47 | //{ 48 | // Console.WriteLine(e); 49 | 50 | //} 51 | Actions Obj = new Actions(Driver.Instance); 52 | Obj.MoveToElement(Driver.Instance.FindElement 53 | (By.XPath(obj))).Build().Perform(); 54 | Thread.Sleep(250); 55 | 56 | } 57 | 58 | public void ClickElementForXpathRowWithText(string textXPath, string text, string elemXPath) 59 | { 60 | var row = _driver.FindElements(By.XPath(textXPath)); 61 | var button = _driver.FindElements(By.XPath(elemXPath)); 62 | int rowCount = row.Count(); 63 | 64 | for (int i = 1; i <= rowCount; i++) 65 | { 66 | //Xpath must be wildcarded using * at Row Number for this method to function 67 | string newRow = textXPath; 68 | newRow = newRow.Replace("[*]", "[" + i.ToString() + "]"); 69 | Console.WriteLine(newRow); 70 | var rowToCheck = _driver.FindElement(By.XPath(newRow)).Text; 71 | Console.WriteLine(rowToCheck); 72 | 73 | if (rowToCheck.Contains(text)) 74 | { 75 | Console.WriteLine("Found"); 76 | Thread.Sleep(5000); 77 | var pathToClick = _driver.FindElements(By.XPath(elemXPath)).ElementAt(i - 1); 78 | pathToClick.Click(); 79 | break; 80 | } 81 | } 82 | } 83 | public void TypeToXPath(string obj, string keys) 84 | { 85 | _driver.FindElement 86 | (By.XPath(obj)).SendKeys(keys); 87 | } 88 | 89 | public void SendKeysToXpath(string obj, string keys) 90 | { 91 | _driver.FindElement 92 | (By.XPath(obj)).SendKeys(keys); 93 | } 94 | 95 | public void SendKeysWithAction(string obj, string keys) 96 | { 97 | // Actions Obj = new Actions(Driver.Instance); 98 | _action.Click(); 99 | _action.SendKeys(keys).Build().Perform(); 100 | Thread.Sleep(250); 101 | } 102 | 103 | public void SelectValueFromXPathDropdown(string XPath, string Value) 104 | { 105 | var dropDown = _driver.FindElement(By.XPath(XPath)); 106 | var selectValue = new SelectElement(dropDown); 107 | selectValue.SelectByText(Value); 108 | } 109 | 110 | public void ClickTableLink(string rowValueToFind, string table, string aHefTextToFind) 111 | { 112 | var foundTable = _driver.FindElement(By.XPath(table)); 113 | var rows = foundTable.FindElements(By.TagName("tr")); 114 | 115 | foreach (var row in rows) 116 | { 117 | if (row.Text.Contains(rowValueToFind)) 118 | { 119 | var tds = row.FindElements(By.TagName("a")); 120 | 121 | foreach (var entry in tds) 122 | { 123 | if (entry.Text.Trim().Contains(aHefTextToFind)) 124 | { 125 | Console.WriteLine(entry.Text); 126 | entry.Click(); 127 | return; 128 | } 129 | 130 | } 131 | } 132 | } 133 | } 134 | 135 | public void ClearInputBox(string XPath) 136 | { 137 | var inputBox = _driver.FindElement(By.XPath(XPath)); 138 | inputBox.Clear(); 139 | } 140 | 141 | //This method will look for the items in a in the Ul for a href 142 | //The xpath will require the path to a href 143 | public void ClickAnItemInaDropDownInputListBox(string xPathToInputBox, string xPathListItem, string valueToFind) 144 | { 145 | ClickXpath(xPathToInputBox); 146 | 147 | var xPath = string.Format(xPathListItem + "[text()[contains(., '{0}')]]", valueToFind); 148 | 149 | ClickXpath(xPath); 150 | 151 | } 152 | 153 | 154 | public void ScrollElementIntoView(string obj) 155 | { 156 | var elem = _driver.FindElement(By.XPath(obj)); 157 | IJavaScriptExecutor jsExec = (IJavaScriptExecutor)_driver; 158 | 159 | jsExec.ExecuteAsyncScript("arguments[0].scrollIntoView(true);", elem); 160 | } 161 | 162 | 163 | 164 | 165 | public void ClickButtonForXPathRowWithText(string TextXPath, string Text, string BtnXPath) 166 | { 167 | var row = Driver.Instance.FindElements(By.XPath(TextXPath)); 168 | var button = Driver.Instance.FindElements(By.XPath(BtnXPath)); 169 | int rowCount = row.Count(); 170 | if (rowCount is (1)) 171 | { 172 | //Xpath must have Row Number wildcarded using * at Row Number e.g. //*[@id=\"ListName\"]/tbody/tr[*]/td[3] where td is the Column to be used 173 | var pathToClick = Driver.Instance.FindElements(By.XPath(BtnXPath)).ElementAt(0); 174 | pathToClick.Click(); 175 | } 176 | 177 | else 178 | { 179 | for (int i = 1; i <= rowCount; i++) 180 | { 181 | //Xpath must be wildcarded using * at Row Number for this method to function 182 | string newRow = TextXPath; 183 | newRow = newRow.Replace("[*]", "[" + i.ToString() + "]"); 184 | var rowText = Driver.Instance.FindElement(By.XPath(newRow)).Text; 185 | if (rowText.Contains(Text)) 186 | { 187 | //this path must also have the Row Number wildcarded to allow elementAt to function 188 | var pathToClick = Driver.Instance.FindElements(By.XPath(BtnXPath)).ElementAt(i - 1); 189 | pathToClick.Click(); 190 | break; 191 | } 192 | 193 | Console.WriteLine(newRow); 194 | } 195 | } 196 | } 197 | 198 | 199 | public void ClickSpecificButtonForXPathRowWithText(string TextXPath, string Text, string BtnXPath, string BtnText) 200 | { 201 | var row = Driver.Instance.FindElements(By.XPath(TextXPath)); 202 | var button = Driver.Instance.FindElements(By.XPath(BtnXPath)); 203 | int rowCount = row.Count(); 204 | 205 | if (rowCount is (1)) 206 | { 207 | //Xpath must have Row Number wildcarded using * at Row Number e.g. //*[@id=\"ListName\"]/tbody/tr[*]/td[3] where td is the Column to be used 208 | var pathToClick = Driver.Instance.FindElements(By.XPath(BtnXPath)).ElementAt(0); 209 | pathToClick.Click(); 210 | } 211 | 212 | else 213 | { 214 | for (int i = 1; i <= rowCount; i++) 215 | { 216 | //Xpath must be wildcarded using * at Row Number for this method to function 217 | string newRow = TextXPath; 218 | string newRow2 = BtnXPath; 219 | newRow = newRow.Replace("[*]", "[" + i.ToString() + "]"); 220 | newRow2 = newRow2.Replace("[ROW]", "[" + i.ToString() + "]").Replace("OPTION", BtnText); 221 | var rowText = Driver.Instance.FindElement(By.XPath(newRow)).Text; 222 | 223 | if (rowText.Contains(Text)) 224 | { 225 | //this path must also have the Row Number wildcarded to allow elementAt to function 226 | var pathToClick = Driver.Instance.FindElement(By.XPath(newRow2)); 227 | pathToClick.Click(); 228 | break; 229 | } 230 | 231 | Console.WriteLine(newRow); 232 | } 233 | } 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /Check.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using OpenQA.Selenium; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Configuration; 7 | using System.Data; 8 | using System.Data.SqlClient; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading; 13 | using System.Threading.Tasks; 14 | using Dapper; 15 | using Automation.Utils; 16 | 17 | using OpenQA.Selenium.Support.UI; 18 | using TechTalk.SpecFlow.Assist; 19 | using SeleniumExtras.WaitHelpers; 20 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions; 21 | using TechTalk.SpecFlow; 22 | 23 | namespace Automation 24 | { 25 | public class Check 26 | { 27 | private readonly IWebDriver _driver; 28 | 29 | 30 | public Check(IWebDriver driver) 31 | { 32 | _driver = driver; 33 | } 34 | 35 | //Wait for Angular Load 36 | public void waitForAngularLoad() 37 | { 38 | IJavaScriptExecutor jsExec = (IJavaScriptExecutor)_driver; 39 | 40 | String angularReadyScript = @"var callback = arguments[arguments.length - 1]; 41 | var el = document.querySelector('html'); 42 | if (!window.angular) { 43 | callback('False') 44 | } 45 | if (angular.getTestability) { 46 | angular.getTestability(el).whenStable(function(){callback('True')}); 47 | } else { 48 | if (!angular.element(el).injector()) { 49 | callback('False') 50 | } 51 | var browser = angular.element(el).injector().get('$browser'); 52 | browser.notifyWhenNoOutstandingRequests(function(){callback('True')}); 53 | }"; 54 | 55 | //Wait for ANGULAR to load 56 | Boolean angularLoad = Convert.ToBoolean(jsExec.ExecuteAsyncScript(angularReadyScript)); 57 | } 58 | 59 | public static void sleep(int miliseconds) 60 | { 61 | 62 | try 63 | { 64 | Thread.Sleep(miliseconds); 65 | } 66 | catch (Exception e) 67 | { 68 | Console.WriteLine(e.ToString()); 69 | } 70 | } 71 | 72 | public bool WaitForObject(string obj, int timeoutInSeconds) 73 | { 74 | // IWebDriver driver = Driver.Instance; 75 | for (int i = 0; i < timeoutInSeconds; i++) 76 | { 77 | if (IsElementPresentByXPath(obj) is true) 78 | if (_driver.FindElement(By.XPath(obj)).Displayed 79 | && _driver.FindElement(By.XPath(obj)).Enabled) 80 | { 81 | return true; 82 | } 83 | 84 | Thread.Sleep(1000); 85 | } 86 | 87 | return false; 88 | } 89 | 90 | public bool FluentWait(string obj, int timeoutInSeconds) 91 | { 92 | if (timeoutInSeconds > 0) 93 | { 94 | var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(timeoutInSeconds)); 95 | var test = wait.Until(ExpectedConditions.ElementExists(By.XPath(obj))); 96 | 97 | // if (wait.Until(drv => drv.FindElement(By.XPath(obj))) != null) 98 | if (test != null) 99 | { 100 | return true; 101 | } 102 | } 103 | 104 | return true; ; 105 | } 106 | 107 | public bool WaitForClass(string obj, int timeoutInSeconds) 108 | { 109 | 110 | for (int i = 0; i < timeoutInSeconds; i++) 111 | { 112 | if (IsElementPresentByClass(obj) is true) 113 | { 114 | return true; 115 | } 116 | 117 | Thread.Sleep(1000); 118 | } 119 | 120 | return false; 121 | } 122 | 123 | 124 | public bool WaitForCss(string obj, int timeoutInSeconds) 125 | { 126 | // IWebDriver driver = Driver.Instance; 127 | for (int i = 0; i < timeoutInSeconds; i++) 128 | { 129 | if (IsElementPresentByCss(obj) is true) 130 | { 131 | return true; 132 | } 133 | 134 | Thread.Sleep(1000); 135 | } 136 | 137 | return false; 138 | } 139 | 140 | //Will need to find a better wait mechanism 141 | public void WaitForElementsAndLogo(string elementToWaitFor) 142 | { 143 | 144 | WaitForElements(elementToWaitFor); 145 | } 146 | 147 | public void WaitForElements(string elementToWaitFor) 148 | { 149 | FluentWait(elementToWaitFor, 20); 150 | WaitForObject(elementToWaitFor, 20); 151 | } 152 | 153 | public bool WaitForObjectToDisappear(string obj, int timeoutInSeconds) 154 | { 155 | IWebDriver driver = Driver.Instance; 156 | for (int i = 0; i < timeoutInSeconds; i++) 157 | { 158 | if (driver.FindElement(By.XPath(obj)).Displayed is false) 159 | { 160 | return true; 161 | } 162 | 163 | Thread.Sleep(1000); 164 | } 165 | 166 | return false; 167 | } 168 | 169 | public void IfXPathElementIsThere(string obj, string args) 170 | { 171 | Assert.IsTrue(IsElementPresentByXPath(obj), args); 172 | IWebElement element = _driver.FindElement(By.XPath(obj)); 173 | Assert.IsTrue(element.Displayed && element.Enabled, args); 174 | } 175 | 176 | public void IfXPathElementIsNotThere(string obj, string args) 177 | { 178 | if (IsElementPresentByXPath(obj) is true) 179 | { 180 | IWebElement element = _driver.FindElement(By.XPath(obj)); 181 | Assert.IsFalse(element.Displayed && element.Enabled, args); 182 | } 183 | else 184 | { 185 | Assert.IsFalse(IsElementPresentByXPath(obj), args); 186 | } 187 | } 188 | 189 | public bool IsElementPresentByCss(string El) 190 | { 191 | try 192 | { 193 | _driver.FindElement(By.CssSelector(El)); 194 | return true; 195 | } 196 | catch 197 | { 198 | return false; 199 | } 200 | } 201 | 202 | public void IfCssElementIsThere(string obj, string args) 203 | { 204 | Assert.IsTrue(IsElementPresentByCss(obj), args); 205 | IWebElement element = _driver.FindElement(By.CssSelector(obj)); 206 | Assert.IsTrue(element.Displayed && element.Enabled, args); 207 | } 208 | 209 | public void DbCheck(string DbValue, string value) 210 | { 211 | Assert.IsTrue(DbValue == value); 212 | } 213 | 214 | public void IfCssElementIsNotThere(string obj, string args) 215 | { 216 | if (IsElementPresentByCss(obj) is true) 217 | { 218 | IWebElement element = _driver.FindElement(By.CssSelector(obj)); 219 | Assert.IsFalse(element.Displayed && element.Enabled, args); 220 | } 221 | else 222 | { 223 | Assert.IsFalse(IsElementPresentByCss(obj), args); 224 | } 225 | } 226 | 227 | 228 | public void IfXPathContainsText(string obj, string text) 229 | { 230 | var Text = string.Empty; 231 | Text = _driver.FindElement(By.XPath(obj)).Text; 232 | Assert.IsTrue(Text.Contains(text), "Text: " + text + " not found or incorrect"); 233 | } 234 | 235 | 236 | public void IfXPathDoesNotContainText(string obj, string text) 237 | { 238 | var Text = _driver.FindElement(By.XPath(obj)).Text; 239 | Assert.IsFalse(Text.Contains(text)); 240 | } 241 | 242 | public void IfCssContainsText(string obj, string text) 243 | { 244 | var Text = _driver.FindElement(By.CssSelector(obj)).Text; 245 | Assert.IsTrue(Text.Contains(text), "Text: " + text + " not found or incorrect"); 246 | } 247 | 248 | public void IfCssAttributeContainsText(string obj, string attribute, string text) 249 | { 250 | String Text = _driver.FindElement(By.CssSelector(obj)).GetAttribute(attribute); 251 | Assert.IsTrue(Text.Contains(text), "Text: " + text + " not found or incorrect"); 252 | } 253 | 254 | public void IfClassContainsText(string obj, string text) 255 | { 256 | var Text = _driver.FindElement(By.CssSelector(obj)).Text; 257 | Assert.IsTrue(Text.Contains(text), "Text: " + text + " not found or incorrect"); 258 | } 259 | 260 | 261 | 262 | public void IfCssDoesNotContainText(string obj, string text) 263 | { 264 | var Text = _driver.FindElement(By.CssSelector(obj)).Text; 265 | Assert.IsFalse(Text.Contains(text)); 266 | } 267 | 268 | public void CssIsSelected(string obj) 269 | { 270 | IWebElement checkbox = _driver.FindElement(By.CssSelector(obj)); 271 | Assert.IsTrue(checkbox.Selected); 272 | } 273 | 274 | public void CssIsNotSelected(string obj) 275 | { 276 | IWebElement checkbox = _driver.FindElement(By.CssSelector(obj)); 277 | Assert.IsFalse(checkbox.Selected); 278 | } 279 | 280 | public void XPathIsSelected(string obj) 281 | { 282 | IWebElement checkbox = _driver.FindElement(By.XPath(obj)); 283 | Assert.IsTrue(checkbox.Selected); 284 | } 285 | 286 | public void XPathIsNotSelected(string obj) 287 | { 288 | IWebElement checkbox = _driver.FindElement(By.XPath(obj)); 289 | Assert.IsFalse(checkbox.Selected); 290 | } 291 | 292 | public bool IsElementPresentByXPath(string El) 293 | { 294 | try 295 | { 296 | _driver.FindElement(By.XPath(El)); 297 | return true; 298 | } 299 | catch 300 | { 301 | return false; 302 | } 303 | } 304 | 305 | public bool IsElementPresentByClass(string El) 306 | { 307 | try 308 | { 309 | var e = _driver.FindElement(By.ClassName(El)); 310 | return true; 311 | } 312 | catch (Exception ex) 313 | { 314 | 315 | Console.WriteLine(ex.ToString()); 316 | return false; 317 | } 318 | } 319 | 320 | public void IfPageTitleContainText(string title) 321 | { 322 | 323 | Assert.IsTrue(_driver.Title.Contains(title)); 324 | } 325 | 326 | public bool IsElementVisableByXPath(string El) 327 | { 328 | try 329 | { 330 | var i = _driver.FindElement(By.XPath(El)); 331 | return true; 332 | } 333 | catch 334 | { 335 | return false; 336 | } 337 | } 338 | 339 | public void IsElementAttributeEqual(string checkValue, string attrib, string path) 340 | { 341 | Assert.IsTrue(_driver.FindElement(By.XPath(path)).GetAttribute(attrib).Equals(checkValue)); 342 | } 343 | 344 | public void IfXPathContainsValue(string obj, string value) 345 | { 346 | var val = Driver.Instance.FindElement(By.XPath(obj)).GetAttribute("value"); 347 | if (val != null) 348 | { 349 | string newVal = val.ToString(); 350 | Console.WriteLine("Expected value is: " + value + " and the value found was: " + newVal); 351 | Assert.IsTrue(newVal == value, "Fail: Value incorrect"); 352 | Console.WriteLine("Success"); 353 | } 354 | else 355 | { 356 | Assert.Fail("Test Fail: Value not found for Object: " + obj); 357 | } 358 | } 359 | 360 | public string GetInventoryLocationIdFromTheUrl() 361 | { 362 | string url = _driver.Url; 363 | string[] test = url.Split(new[] { "location/", "/detail" }, StringSplitOptions.RemoveEmptyEntries); 364 | List s = StringHelper.ExtractFromString(url, "location/", "/detail"); 365 | return s[0].ToString(); 366 | //https://localhost:44300/main/#/task/inventory/settings/location/31033/detail 367 | } 368 | 369 | 370 | 371 | private void GetGridDate(string GridName, string ExcelFilename) 372 | { 373 | var elemTable = _driver.FindElement(By.XPath(GridName)); 374 | 375 | // Get all Row of the table 376 | List lstTrElem = new List(elemTable.FindElements(By.TagName("tr"))); 377 | DataTable dt = new DataTable(); 378 | String strRowData = ""; 379 | String strHeadData = ""; 380 | int r = 0; 381 | 382 | // Go through each Row 383 | foreach (var elemTr in lstTrElem) 384 | { 385 | dt.Rows.Add(); 386 | // Get columns or Headers from Rows 387 | List lstTdElem = new List(elemTr.FindElements(By.TagName("td"))); 388 | List lstThElem = new List(elemTr.FindElements(By.TagName("th"))); 389 | if (lstTdElem.Count > 0) 390 | { 391 | int c = 0; 392 | // Get each Column value 393 | foreach (var elemTd in lstTdElem) 394 | { 395 | strRowData = strRowData + elemTd.Text + "\t"; 396 | dt.Rows[r][c] = elemTd.Text; 397 | c = c + 1; 398 | } 399 | } 400 | else 401 | { 402 | // Get each Header 403 | foreach (var elemHead in lstThElem) 404 | { 405 | strHeadData = strHeadData + elemHead.Text + "\t"; 406 | dt.Columns.Add(elemHead.Text.Replace("\r\n", "") 407 | .Replace(" ", "") 408 | .Replace("%", "") 409 | .Replace("=", "")); 410 | } 411 | } 412 | 413 | //Output Data to Console 414 | Console.Write(strHeadData.Replace("\r\n", "")); 415 | strHeadData = String.Empty; 416 | Console.WriteLine(strRowData.Replace("\r\n", "")); 417 | strRowData = String.Empty; 418 | r = r + 1; 419 | } 420 | 421 | //Output DataTable to Console 422 | foreach (DataColumn col in dt.Columns) 423 | { 424 | Console.Write(col.ToString() + "\t"); 425 | } 426 | 427 | foreach (DataRow row in dt.Rows) 428 | { 429 | Console.WriteLine(); 430 | for (int x = 0; x < dt.Columns.Count; x++) 431 | { 432 | Console.Write(row[x].ToString() + "\t"); 433 | } 434 | } 435 | 436 | // DataRow[] rows = dt.Select(ColumnName + "= '" + Check +"'"); 437 | 438 | WriteGridToExcel(dt, ExcelFilename); 439 | } 440 | 441 | public void CheckTableValue(string gridName, string columnName, String check) 442 | { 443 | bool found = false; 444 | // WaitForObject(MainBody.General.Loading, 5); 445 | var table = _driver.FindElement(By.XPath(gridName)); 446 | foreach (var tr in table.FindElements(By.TagName("tr"))) 447 | { 448 | var tds = tr.FindElements(By.TagName("td")); 449 | for (var i = 0; i < tds.Count; i++) 450 | { 451 | 452 | if (tds[i].Text.Trim().Contains(check)) 453 | { 454 | Assert.IsTrue(true); 455 | found = true; 456 | break; 457 | } 458 | 459 | } 460 | } 461 | if (found == false) 462 | { 463 | Assert.True(false); 464 | } 465 | } 466 | public static void WriteGridToExcel(DataTable dt, string SheetName) 467 | { 468 | var ExcelPath = Path.Combine(TestContext.CurrentContext.TestDirectory, ConfigurationManager.AppSettings["ExcelSheetsPath"] + "\\" + SheetName); 469 | StreamWriter wr = new StreamWriter(ExcelPath); 470 | 471 | try 472 | { 473 | 474 | for (int i = 0; i < dt.Columns.Count; i++) 475 | { 476 | wr.Write(dt.Columns[i].ToString().ToUpper() + "\t"); 477 | } 478 | 479 | wr.WriteLine(); 480 | 481 | //write rows to excel file 482 | for (int i = 0; i < (dt.Rows.Count); i++) 483 | { 484 | for (int j = 0; j < dt.Columns.Count; j++) 485 | { 486 | if (dt.Rows[i][j] != null) 487 | { 488 | wr.Write(Convert.ToString(dt.Rows[i][j]) + "\t"); 489 | } 490 | else 491 | { 492 | wr.Write("\t"); 493 | } 494 | } 495 | //go to next line 496 | wr.WriteLine(); 497 | } 498 | //close file 499 | wr.Close(); 500 | } 501 | catch (Exception ex) 502 | { 503 | throw ex; 504 | } 505 | } 506 | 507 | public void XPathColumnText(string xPath, int num, string text) 508 | { 509 | //XPath is the column 510 | //Num is how many you want to find 511 | //Get the XPath and replace TEXT with input from Specflow for search 512 | // Note: the Xpath must be in the following format to search in a particular column: - 513 | //*[@id=\"ctl00_MainContent_datafileViewer_gvMirrorErrorListView\"]/tbody/tr[*]/td[contains(text(),\"TEXT\")] 514 | string column = xPath; 515 | column = column.Replace("TEXT", (text)); 516 | Console.WriteLine(column); 517 | var count = _driver.FindElements(By.XPath(column)).Count; 518 | Console.WriteLine("row count of Status " + (text) + " is " + (count)); 519 | Assert.AreEqual(num, count, "There are incorrect values and/or number of values found in the list"); 520 | } 521 | 522 | /// 523 | /// Based on the table that is passed in it will search for the identifying value 524 | /// passed in against the column name provided, this identifies the row to search against. 525 | /// Then it will look for the column name that holds the cell for the value to check against and use the 526 | /// row combined with these values to find the actual cell value and check this with the check value that is passed in 527 | /// 528 | /// 529 | /// 530 | /// 531 | /// 532 | /// 533 | public void XpathCheckTableCellWithRowElement(string gridName, string colNameForId, string identifingValue, string columnNameHoldingValueToVerify, string valueTocheck) 534 | { 535 | // WaitForObject(MainBody.General.Loading, 5); 536 | IWebElement table = _driver.FindElement(By.XPath(gridName)); 537 | 538 | var row = (from e in TableHelper.ReadTable(table) 539 | where e.ColumnName == colNameForId && e.ColumnValue == identifingValue 540 | select e.RowNumber).SingleOrDefault(); 541 | 542 | string cellValue = TableHelper.ReadCell(columnNameHoldingValueToVerify, row); 543 | 544 | Console.WriteLine(identifingValue + " " + cellValue); 545 | Assert.IsTrue(valueTocheck == cellValue, "Fail: Value incorrect"); 546 | Console.WriteLine("Success"); 547 | 548 | } 549 | 550 | //Commented out as the models have moved out of the project have to find a way to pass in the models to create and 551 | //make this method generic 552 | 553 | //public void CheckTableWithPaginationContainsValue(Table table, string pagination, string tableRowCellForTheId, 554 | // string tableRowCellForTheValueToCheck, string nextPage, string pageOne, TypeOfValue Model) 555 | //{ 556 | // int pageWeAreOn = 1; 557 | // Table singleRowTable = null; 558 | 559 | // var paginationCount = Driver.Instance.FindElements(By.XPath(pagination)).Count; 560 | // Console.WriteLine("Total pages = " + paginationCount.ToString()); 561 | 562 | // //as we have >> at the start we have to start the pagination with + 1 , so page 1 is now (2) page 2 is (3) etc 563 | 564 | // //You can use the below in google developer console to validate your xpath 565 | // //"$x("//ul[@class='pagination ng-table-pagination']//following-sibling::a[not(contains(.,'»') or contains(.,'«'))]")" 566 | // foreach (var row in table.Rows) 567 | // { 568 | // waitForAngularLoad(); 569 | // int rowCount = Driver.Instance.FindElements( 570 | // By.XPath(tableRowCellForTheId)).Count; 571 | // Console.WriteLine("Starting checks on row = " + rowCount); 572 | 573 | // singleRowTable = new Table(table.Header.ToArray()); 574 | // singleRowTable.AddRow(row); 575 | 576 | // var testData = singleRowTable.CreateInstance(); 577 | 578 | // for (int rowWeAreOn = 1; rowWeAreOn <= rowCount; rowWeAreOn++) 579 | // { 580 | // string numPath = tableRowCellForTheId; 581 | // numPath = numPath.Replace("*", rowWeAreOn.ToString()); 582 | 583 | // //get the path to the id for the text we want to find for the row 584 | // var numPathText = Driver.Instance.FindElement(By.XPath(numPath)).Text; 585 | // Console.WriteLine(numPathText); 586 | 587 | // //get the cell for the value we are checking for 588 | // string valuePath = tableRowCellForTheValueToCheck; 589 | // valuePath = valuePath.Replace("*", rowWeAreOn.ToString()); 590 | 591 | // var pathText = _driver.FindElement(By.XPath(valuePath)).Text; 592 | 593 | // Console.WriteLine("The path text = " + pathText); 594 | // Console.WriteLine("rowWeAreOn = " + rowWeAreOn.ToString()); 595 | // Console.WriteLine(" The row path = " + numPath + " The date path =" + valuePath); 596 | // Console.WriteLine(" Checking if id we are passing in to find " + testData.Task.ToString() + 597 | // " matches the row text = " + numPathText.ToString()); 598 | 599 | // if (testData.Task == numPathText) 600 | // { 601 | // Console.WriteLine( 602 | // "We the match wahoo! now we check to see if the value you want to check matches what is displayed "); 603 | // Console.WriteLine("testData.DateDue = " + testData.DateDue.ToString()); 604 | // Console.WriteLine("datePathText.ToString() = " + pathText.ToString()); 605 | 606 | // Assert.IsTrue(testData.DateDue.ToString() == pathText.ToString(), 607 | // "The values do not match looking for =" + testData.DateDue.ToString() + " found = " + 608 | // pathText.ToString()); 609 | 610 | // break; 611 | // } 612 | // else if (rowWeAreOn == (rowCount)) 613 | // { 614 | 615 | // Console.WriteLine("Id we want to find not found check we are not on the last page"); 616 | 617 | // Console.WriteLine("Page we are = " + (pageWeAreOn - 1).ToString()); 618 | // Console.WriteLine("Pagination count = " + (paginationCount).ToString()); 619 | 620 | // //check we have not come to the end of the pages 621 | // if ((pageWeAreOn - 1) != paginationCount) 622 | // { 623 | // Console.WriteLine("Moving on to the next page"); 624 | // //click the next the page 625 | // _driver.FindElement(By.XPath(nextPage)).Click(); 626 | 627 | // waitForAngularLoad(); 628 | // pageWeAreOn = pageWeAreOn + 1; 629 | 630 | // //We are moving on to the next page so we have to reset the counter of the row we are on to 1 631 | // rowWeAreOn = 1; 632 | 633 | // // As we don't know how the amount of rows are on the page we have to get these each time 634 | // rowCount = _driver.FindElements( 635 | // By.XPath(tableRowCellForTheId)).Count; 636 | // Console.WriteLine("Page number " + (paginationCount).ToString() + " row count = " + rowCount); 637 | // } 638 | // else 639 | // { 640 | // //we are on the last page so fail just printing out for a sanity check 641 | // Console.WriteLine("we are on the last page failed to find the id nothing Page number = " + (paginationCount).ToString()); 642 | 643 | // Assert.IsTrue(testData.Task == numPathText, " Did not find ID = " + testData.Task.ToString()); 644 | 645 | // } 646 | // } 647 | // } 648 | // //now we have to reset the counts as we are going back to the start on page 1 649 | // _driver.FindElement(By.XPath(pageOne)).Click(); 650 | // waitForAngularLoad(); 651 | // pageWeAreOn = 1; 652 | // } 653 | //} 654 | } 655 | } 656 | --------------------------------------------------------------------------------