Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.41 KB | None | 0 0
  1. using OpenQA.Selenium;
  2. using OpenQA.Selenium.Chrome;
  3. using OpenQA.Selenium.Support.UI;
  4. using System;
  5. using System.Threading;
  6.  
  7. class EntryPoint
  8. {
  9.  
  10.     static string url = "https://test.docs4home.co.uk/Account/Login";
  11.     static string user = "SolTestABC@radu.dev.cbiz.ro";
  12.     static string password = "Tester123!";
  13.     static string emailFieldName = "Email";
  14.     static string passwordFieldName = "Password";
  15.     static string loginButtonCss = "body > div.body-content.align-center > form > div > div > div:nth-child(6) > div > input";
  16.     static string cssD4Hlogo = "#navbar-container > div.navbar-header.pull-left > a > small > img";
  17.     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";
  18.     static string testText = "Test Text";
  19.     static string newFolderLogo = "#emptystateTemplateRow > td > div > div.emptyStateImage > img";
  20.     static string userDropDownCSSButton = "#navbar-container > div.navbar-buttons.navbar-header.pull-right > ul > li > a > i";
  21.     static string userProfileMenuXpath = "//*[@id=\"navbar-container\"]/div[2]";
  22.  
  23.     static void Main()
  24.  
  25.  
  26.     {
  27.         IWebDriver driver = new ChromeDriver();
  28.         driver.Navigate().GoToUrl(url);
  29.  
  30.  
  31.  
  32.         IWebElement emailField = driver.FindElement(By.Name(emailFieldName));
  33.         IWebElement passwordField = driver.FindElement(By.Name(passwordFieldName));
  34.         IWebElement loginButton = driver.FindElement(By.CssSelector(loginButtonCss));
  35.         IWebElement folderLogo;
  36.         IWebElement searchBOX;
  37.         IWebElement D4HlogoAfterLogin;
  38.         IWebElement userDropDownMenuButton;
  39.         IWebElement profileMenu;
  40.  
  41.         /* IWebElement is needed for if condition - if condition does not accept string for Displayed statement */
  42.  
  43.         try
  44.         {
  45.  
  46.             if (emailField.Displayed && passwordField.Displayed && loginButton.Displayed)
  47.             {
  48.                 emailField.SendKeys(user);
  49.                 passwordField.SendKeys(password);
  50.                 loginButton.Click();
  51.  
  52.                 Console.ForegroundColor = ConsoleColor.Blue;
  53.                 Console.WriteLine("login elements present - login click OK! ");
  54.                 Console.ForegroundColor = ConsoleColor.White;
  55.             }
  56.  
  57.  
  58.         }
  59.  
  60.         catch
  61.         {
  62.             Console.ForegroundColor = ConsoleColor.Red;
  63.             Console.WriteLine("missing elemnts - login not OK! ");
  64.             Console.ForegroundColor = ConsoleColor.White;
  65.         }
  66.  
  67.         Thread.Sleep(2000);
  68.  
  69.         try
  70.         {
  71.  
  72.             /* IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
  73.             wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
  74.            
  75.              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
  76.              */
  77.  
  78.  
  79.  
  80.             WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10));
  81.             wait.Until(ExpectedConditions.ElementExists(By.CssSelector(cssD4Hlogo)));
  82.             D4HlogoAfterLogin = driver.FindElement(By.CssSelector(cssD4Hlogo));
  83.  
  84.  
  85.  
  86.             if (D4HlogoAfterLogin.Displayed)
  87.             {
  88.                 Console.ForegroundColor = ConsoleColor.Blue;
  89.                 Console.WriteLine("Logos are present after login - login was a success! ");
  90.                 Console.ForegroundColor = ConsoleColor.White;
  91.             }
  92.  
  93.         }
  94.  
  95.         catch
  96.         {
  97.             Console.ForegroundColor = ConsoleColor.Red;
  98.             Console.WriteLine("Logo is not present after login - login was not a success or a logo CSS is missing! ");
  99.             Console.ForegroundColor = ConsoleColor.White;
  100.         }
  101.  
  102.         try
  103.         {
  104.             WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
  105.             wait.Until(ExpectedConditions.ElementExists(By.CssSelector(searchBoxCSS)));
  106.             searchBOX = driver.FindElement(By.CssSelector(searchBoxCSS));
  107.             folderLogo = driver.FindElement(By.CssSelector(newFolderLogo));
  108.  
  109.             if (searchBOX.Displayed && folderLogo.Displayed)
  110.             {
  111.  
  112.                 searchBOX.SendKeys(testText);
  113.                 string enteredValeInSearchBox = searchBOX.GetAttribute("value");
  114.  
  115.                 if (enteredValeInSearchBox == testText)
  116.                 {
  117.                     Console.ForegroundColor = ConsoleColor.Blue;
  118.                     Console.WriteLine("input text is: " + searchBOX.GetAttribute("value"));
  119.                     Console.WriteLine("text input in searchbox ok! ");
  120.                     Console.ForegroundColor = ConsoleColor.White;
  121.                 }
  122.  
  123.                 else
  124.                 {
  125.  
  126.                     Console.ForegroundColor = ConsoleColor.Red;
  127.                     Console.WriteLine("input text is: " + searchBOX.GetAttribute("value"));
  128.                     Console.WriteLine("text input in searchbox not ok - entered text value does not match witch actual value! ");
  129.                     Console.ForegroundColor = ConsoleColor.White;
  130.  
  131.                 }
  132.  
  133.             }
  134.  
  135.         }
  136.  
  137.         catch (NoSuchElementException)
  138.         {
  139.             Console.ForegroundColor = ConsoleColor.Red;
  140.             Console.WriteLine("Logo element missing !");
  141.             Console.ForegroundColor = ConsoleColor.White;
  142.         }
  143.  
  144.         try
  145.         {
  146.  
  147.             WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
  148.             wait.Until(ExpectedConditions.ElementExists(By.CssSelector(userDropDownCSSButton)));
  149.             userDropDownMenuButton = driver.FindElement(By.CssSelector(userDropDownCSSButton));
  150.  
  151.             if (userDropDownMenuButton.Displayed)
  152.             {
  153.                 userDropDownMenuButton.Click();
  154.                 Console.ForegroundColor = ConsoleColor.Blue;
  155.                 Console.WriteLine("DropDownButton exisits element clicked!");
  156.                 Console.ForegroundColor = ConsoleColor.White;
  157.             }
  158.  
  159.  
  160.         }
  161.  
  162.         catch (NoSuchElementException)
  163.  
  164.         {
  165.             Console.ForegroundColor = ConsoleColor.Red;
  166.             Console.WriteLine("dropdown button not clicked - element missing! ");
  167.             Console.ForegroundColor = ConsoleColor.White;
  168.         }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.     }
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement