Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. using NUnit.Framework;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4. using OpenQA.Selenium.Support.PageObjects;
  5. using OpenQA.Selenium.Support.UI;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using WebDriverDesignPatternLiveDemo.Models;
  12. using WebDriverDesignPatternLiveDemo.Pages.HomePage;
  13. using WebDriverDesignPatternLiveDemo.Pages.RegistrationPage;
  14.  
  15. namespace WebDriverDesignPatternLiveDemo
  16. {
  17. [TestFixture]
  18. public class RegistrationFormTests
  19. {
  20.  
  21. private IWebDriver driver;
  22.  
  23.  
  24. [SetUp]
  25. public void Init()
  26. {
  27.  
  28. this.driver = new ChromeDriver();
  29.  
  30. }
  31.  
  32. [TearDown]
  33. public void CleanUp()
  34. {
  35.  
  36. this.driver.Quit();
  37.  
  38. }
  39.  
  40. [Test, Property("Priority", 2)]
  41. [Author("Ventsislav Ivanov")]
  42. public void NavigateToRegistrationPage()
  43. {
  44. var homePage = new HomePage(driver);
  45. var registrationPage = new RegistrationPage(driver);
  46. PageFactory.InitElements(this.driver, homePage);
  47.  
  48. homePage.NavigateTo();
  49.  
  50. registrationPage.AssertRegistrationPageIsOpen("Registration");
  51. }
  52.  
  53.  
  54. [Test]
  55. public void RegistrateWithoutMail()
  56. {
  57.  
  58. RegistrationPage regPage = new RegistrationPage(this.driver);
  59. RegistrationUser user = new RegistrationUser("Ventsislav",
  60. "Ivanov",
  61. new List<bool>(new bool[] { true, false, false }),
  62. new List<bool>(new bool[] { true, true, true }),
  63. "Bulgaria",
  64. "3",
  65. "1",
  66. "1989",
  67. "8888888888",
  68. "Buro",
  69. "",
  70. @"C:\Users\Buro\Desktop\Seminar\Pics\enviroment.jpg",
  71. "OPSA",
  72. "12345678",
  73. "12345678");
  74.  
  75. regPage.NavigateTo();
  76. regPage.FillRegistrationForm(user);
  77. regPage.AssertMailErrorMessage("* This field is required");
  78.  
  79. }
  80.  
  81.  
  82. [Test]
  83. public void RegistrateWithoutPassword()
  84. {
  85.  
  86. RegistrationPage regPage = new RegistrationPage(this.driver);
  87. RegistrationUser user = new RegistrationUser("Ventsislav",
  88. "Ivanov",
  89. new List<bool>(new bool[] { true, false, false }),
  90. new List<bool>(new bool[] { true, true, true }),
  91. "Bulgaria",
  92. "3",
  93. "1",
  94. "1989",
  95. "8888888888",
  96. "Buro",
  97. "a@b.v",
  98. @"C:\Users\Buro\Desktop\Seminar\Pics\enviroment.jpg",
  99. "OPSA",
  100. "",
  101. "12345678");
  102.  
  103. regPage.NavigateTo();
  104. regPage.FillRegistrationForm(user);
  105. //regPage.AssertMailErrorMessage("* This field is required");
  106.  
  107. }
  108.  
  109.  
  110. [Test]
  111. public void RegistrateWithoutConfirmPassword()
  112. {
  113.  
  114. RegistrationPage regPage = new RegistrationPage(this.driver);
  115. RegistrationUser user = new RegistrationUser("Ventsislav",
  116. "Ivanov",
  117. new List<bool>(new bool[] { true, false, false }),
  118. new List<bool>(new bool[] { true, true, true }),
  119. "Bulgaria",
  120. "3",
  121. "1",
  122. "1989",
  123. "8888888888",
  124. "Buro",
  125. "a@b.v",
  126. @"C:\Users\Buro\Desktop\Seminar\Pics\enviroment.jpg",
  127. "OPSA",
  128. "12345678",
  129. "");
  130.  
  131. regPage.NavigateTo();
  132. regPage.FillRegistrationForm(user);
  133. //regPage.AssertMailErrorMessage("* This field is required");
  134.  
  135. }
  136.  
  137.  
  138.  
  139.  
  140. [Test]
  141. public void RegistrateWithoutNames()
  142. {
  143.  
  144. RegistrationPage regPage = new RegistrationPage(this.driver);
  145. RegistrationUser user = new RegistrationUser("",
  146. "",
  147. new List<bool>(new bool[] { true, false, false }),
  148. new List<bool>(new bool[] { true, true, true }),
  149. "Bulgaria",
  150. "3",
  151. "1",
  152. "1989",
  153. "8888888888",
  154. "Buro",
  155. "a@b.v",
  156. @"C:\Users\Buro\Desktop\Seminar\Pics\enviroment.jpg",
  157. "OPSA",
  158. "12345678",
  159. "12345678");
  160.  
  161. regPage.NavigateTo();
  162. regPage.FillRegistrationForm(user);
  163. regPage.AssertNamesErrorMessage();
  164.  
  165. }
  166.  
  167.  
  168.  
  169. [Test]
  170. public void RegistrateWithoutUsernames()
  171. {
  172.  
  173. driver.Manage().Window.Maximize();
  174. driver.Url = "http://www.demoqa.com/";
  175. var regButton = driver.FindElement(By.Id("menu-item-374"));
  176. regButton.Click();
  177. var firstName = driver.FindElement(By.Id("name_3_firstname"));
  178. Type(firstName, "Stanislav");
  179. var lastName = driver.FindElement(By.Id("name_3_lastname"));
  180. Type(lastName, "Todorov");
  181. var martialStatus = driver.FindElement(By.XPath("//*[@id='pie_register']/li[2]/div/div/input[1]"));
  182. martialStatus.Click();
  183. List<IWebElement> hobbys = driver.FindElements(By.Name("checkbox_5[]")).ToList();
  184. hobbys[0].Click();
  185. hobbys[1].Click();
  186.  
  187.  
  188. selectOption(driver, "dropdown_7", "Bulgaria");
  189. //var country = driver.FindElement(By.Id("dropdown_7"));
  190. //SelectElement countryOptrion = new SelectElement(country);
  191. //countryOptrion.SelectByText("Bulgaria");
  192. selectOption(driver, "mm_date_8", "3");
  193. selectOption(driver, "dd_date_8", "3");
  194. selectOption(driver, "yy_date_8", "1989");
  195. var phone = driver.FindElement(By.Id("phone_9"));
  196. Type(phone, "999999999999");
  197. //var userName = driver.FindElement(By.Id("username"));
  198. //Type(userName, "Berunko");
  199. var email = driver.FindElement(By.Id("email_1"));
  200. Type(email, "Berunko@abv.bg");
  201. var picture = driver.FindElement(By.Id("profile_pic_10"));
  202. picture.Click();
  203. driver.SwitchTo().ActiveElement().SendKeys(@"D:\stodorov\Desktop\work\pictures\homer.jpg");
  204. var password = driver.FindElement(By.Id("password_2"));
  205. Type(password, "123456789");
  206. var confirmPassword = driver.FindElement(By.Id("confirm_password_password_2"));
  207. Type(confirmPassword, "123456789");
  208. var registrationSubmit = driver.FindElement(By.Name("pie_submit"));
  209. registrationSubmit.Click();
  210. var regSuccess = driver.FindElement(By.XPath("//*[@id=\"post-49\"]/div/p"));
  211. Assert.AreEqual("Thank you for your registration", regSuccess.Text);
  212.  
  213.  
  214.  
  215. driver.Quit();
  216.  
  217. }
  218.  
  219.  
  220.  
  221. [Test]
  222. public void RegistrateWithInvalidPhone()
  223. {
  224.  
  225. driver.Manage().Window.Maximize();
  226. driver.Url = "http://www.demoqa.com/";
  227. var regButton = driver.FindElement(By.Id("menu-item-374"));
  228. regButton.Click();
  229. var firstName = driver.FindElement(By.Id("name_3_firstname"));
  230. Type(firstName, "Stanislav");
  231. var lastName = driver.FindElement(By.Id("name_3_lastname"));
  232. Type(lastName, "Todorov");
  233. var martialStatus = driver.FindElement(By.XPath("//*[@id='pie_register']/li[2]/div/div/input[1]"));
  234. martialStatus.Click();
  235. List<IWebElement> hobbys = driver.FindElements(By.Name("checkbox_5[]")).ToList();
  236. hobbys[0].Click();
  237. hobbys[1].Click();
  238.  
  239.  
  240. selectOption(driver, "dropdown_7", "Bulgaria");
  241. //var country = driver.FindElement(By.Id("dropdown_7"));
  242. //SelectElement countryOptrion = new SelectElement(country);
  243. //countryOptrion.SelectByText("Bulgaria");
  244. selectOption(driver, "mm_date_8", "3");
  245. selectOption(driver, "dd_date_8", "3");
  246. selectOption(driver, "yy_date_8", "1989");
  247. var phone = driver.FindElement(By.Id("phone_9"));
  248. Type(phone, "dsadasdasd");
  249. var userName = driver.FindElement(By.Id("username"));
  250. Type(userName, "Berunko");
  251. var email = driver.FindElement(By.Id("email_1"));
  252. Type(email, "Berunko@abv.bg");
  253. var picture = driver.FindElement(By.Id("profile_pic_10"));
  254. picture.Click();
  255. driver.SwitchTo().ActiveElement().SendKeys(@"D:\stodorov\Desktop\work\pictures\homer.jpg");
  256. var password = driver.FindElement(By.Id("password_2"));
  257. Type(password, "123456789");
  258. var confirmPassword = driver.FindElement(By.Id("confirm_password_password_2"));
  259. Type(confirmPassword, "123456789");
  260. var registrationSubmit = driver.FindElement(By.Name("pie_submit"));
  261. registrationSubmit.Click();
  262. var regSuccess = driver.FindElement(By.XPath("//*[@id=\"post-49\"]/div/p"));
  263. Assert.AreEqual("Thank you for your registration", regSuccess.Text);
  264.  
  265.  
  266.  
  267. driver.Quit();
  268.  
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. private void Type(IWebElement element, string text)
  277. {
  278.  
  279. element.Clear();
  280. element.SendKeys(text);
  281.  
  282. }
  283.  
  284. private void selectOption(IWebDriver driver, string selector, string text)
  285. {
  286.  
  287. var dropdown = driver.FindElement(By.Id(selector));
  288. SelectElement dropDownOption = new SelectElement(dropdown);
  289. dropDownOption.SelectByText(text);
  290. }
  291. }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement