Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using OpenQA.Selenium;
- using OpenQA.Selenium.Chrome;
- using OpenQA.Selenium.Support.UI;
- using System;
- using System.Threading;
- class EntryPoint
- {
- static string url = "https://test.docs4home.co.uk/Account/Login";
- static string user = "SolTestABC@radu.dev.cbiz.ro";
- static string password = "Tester123!";
- static string emailFieldName = "Email";
- static string passwordFieldName = "Password";
- static string loginButtonCss = "body > div.body-content.align-center > form > div > div > div:nth-child(6) > div > input";
- static string cssD4Hlogo = "#navbar-container > div.navbar-header.pull-left > a > small > img";
- static string searchBoxCSS = "#main-container > div.main-content > div > div > div:nth-child(25) > div.col-xs-12.col-sm-12.col-md-5.col-lg-5.no-padding > div > input";
- static string testText = "Test Text";
- static string newFolderLogo = "#emptystateTemplateRow > td > div > div.emptyStateImage > img";
- static string userDropDownCSSButton = "#navbar-container > div.navbar-buttons.navbar-header.pull-right > ul > li > a > i";
- static string userProfileMenuXpath = "//*[@id=\"navbar-container\"]/div[2]";
- static void Main()
- {
- IWebDriver driver = new ChromeDriver();
- driver.Navigate().GoToUrl(url);
- IWebElement emailField = driver.FindElement(By.Name(emailFieldName));
- IWebElement passwordField = driver.FindElement(By.Name(passwordFieldName));
- IWebElement loginButton = driver.FindElement(By.CssSelector(loginButtonCss));
- IWebElement folderLogo;
- IWebElement searchBOX;
- IWebElement D4HlogoAfterLogin;
- IWebElement userDropDownMenuButton;
- IWebElement profileMenu;
- /* IWebElement is needed for if condition - if condition does not accept string for Displayed statement */
- try
- {
- if (emailField.Displayed && passwordField.Displayed && loginButton.Displayed)
- {
- emailField.SendKeys(user);
- passwordField.SendKeys(password);
- loginButton.Click();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("login elements present - login click OK! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("missing elemnts - login not OK! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- Thread.Sleep(2000);
- try
- {
- /* IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
- wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
- found this while searching the web on waits dun't fully understand what it does what it does just copy pasted and gave it a shot doesn't really work tho
- */
- WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10));
- wait.Until(ExpectedConditions.ElementExists(By.CssSelector(cssD4Hlogo)));
- D4HlogoAfterLogin = driver.FindElement(By.CssSelector(cssD4Hlogo));
- if (D4HlogoAfterLogin.Displayed)
- {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Logos are present after login - login was a success! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Logo is not present after login - login was not a success or a logo CSS is missing! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- try
- {
- WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
- wait.Until(ExpectedConditions.ElementExists(By.CssSelector(searchBoxCSS)));
- searchBOX = driver.FindElement(By.CssSelector(searchBoxCSS));
- folderLogo = driver.FindElement(By.CssSelector(newFolderLogo));
- if (searchBOX.Displayed && folderLogo.Displayed)
- {
- searchBOX.SendKeys(testText);
- string enteredValeInSearchBox = searchBOX.GetAttribute("value");
- if (enteredValeInSearchBox == testText)
- {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("input text is: " + searchBOX.GetAttribute("value"));
- Console.WriteLine("text input in searchbox ok! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("input text is: " + searchBOX.GetAttribute("value"));
- Console.WriteLine("text input in searchbox not ok - entered text value does not match witch actual value! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- }
- catch (NoSuchElementException)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Logo element missing !");
- Console.ForegroundColor = ConsoleColor.White;
- }
- try
- {
- WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
- wait.Until(ExpectedConditions.ElementExists(By.CssSelector(userDropDownCSSButton)));
- userDropDownMenuButton = driver.FindElement(By.CssSelector(userDropDownCSSButton));
- if (userDropDownMenuButton.Displayed)
- {
- userDropDownMenuButton.Click();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("DropDownButton exisits element clicked!");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- catch (NoSuchElementException)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("dropdown button not clicked - element missing! ");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement