Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1.  
  2. using System;
  3. using OpenQA.Selenium;
  4. using OpenQA.Selenium.Chrome;
  5. using OpenQA.Selenium.Support.UI;
  6.  
  7. class EntryPoint
  8. {
  9.     static IWebDriver driver = new ChromeDriver();
  10.     static void Main()
  11.     {
  12.         string url = "https://test.docs4home.co.uk/Account/Login";
  13.         string User = "SolTestABC@radu.dev.cbiz.ro";
  14.         string Password = "Tester123!";
  15.  
  16.        
  17.         driver.Navigate().GoToUrl(url);
  18.  
  19.         IWebElement loginField = driver.FindElement(By.Id("Email"));
  20.         IWebElement passwordField = driver.FindElement(By.Id("Password"));
  21.         IWebElement loginButton = driver.FindElement(By.CssSelector("body > div.body-content.align-center > form > div > div > div:nth-child(6) > div > input"));
  22.  
  23.         try
  24.         {
  25.             if (loginField.Displayed && passwordField.Displayed && loginButton.Displayed)
  26.             {
  27.                 loginField.SendKeys(User);
  28.                 passwordField.SendKeys(Password);
  29.                 loginButton.Click();
  30.                 Console.ForegroundColor = ConsoleColor.Blue;
  31.                 Console.WriteLine("Fields & login button present - user and password values entered! ");
  32.                 Console.ForegroundColor = ConsoleColor.White;
  33.             }
  34.  
  35.         }
  36.  
  37.         catch (NoSuchElementException)
  38.         {
  39.             Console.ForegroundColor = ConsoleColor.Red;
  40.             Console.WriteLine("Fields or login button not present - user and password values have not been entered! ");
  41.             Console.ForegroundColor = ConsoleColor.White;
  42.         }
  43.  
  44.  
  45.         IWebElement D4HlogoAfterLogin;
  46.         try
  47.  
  48.         {
  49.             WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
  50.             wait.Until(ExpectedConditions.ElementExists(By.CssSelector("#navbar-container > div.navbar-header.pull-left > a > small > img")));
  51.             D4HlogoAfterLogin = driver.FindElement(By.CssSelector("#navbar-container > div.navbar-header.pull-left > a > small > img"));
  52.  
  53.            
  54.  
  55.             if (D4HlogoAfterLogin.Displayed)
  56.             {
  57.                 Console.ForegroundColor = ConsoleColor.Blue;
  58.                 Console.WriteLine("D4H Logo is present - login was successful! ");
  59.                 Console.ForegroundColor = ConsoleColor.White;
  60.             }
  61.  
  62.         }
  63.  
  64.         catch
  65.         {
  66.             Console.ForegroundColor = ConsoleColor.Red;
  67.             Console.WriteLine("D4H Logo is not present - login was not successful or D4H logo is missing! ");
  68.             Console.ForegroundColor = ConsoleColor.White;
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement