azaria77

proverki 2chast

May 25th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. using NUnit.Framework;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4. using OpenQA.Selenium.Interactions;
  5. using OpenQA.Selenium.Support.UI;
  6. using SeleniumExtras.WaitHelpers;
  7. using System;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Threading;
  11.  
  12. namespace Demoqa
  13. {
  14. [TestFixture]
  15. class Demoqa
  16. {
  17. private IWebDriver _driver;
  18. private WebDriverWait _wait;
  19. private Actions _builder;
  20.  
  21. [SetUp]
  22. public void SetUp()
  23. {
  24. _driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
  25. _driver.Manage().Window.Maximize();
  26. _driver.Navigate().GoToUrl("http://www.demoqa.com/");
  27. _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(4));
  28. _builder = new Actions(_driver);
  29.  
  30. var interactionsButtonNavigation = _driver.FindElement(By.XPath("//*[@id=\"app\"]/div/div/div[2]/div/div[5]/div/div[3]"));
  31. interactionsButtonNavigation.Click();
  32.  
  33. //Scroll to the end
  34. IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
  35. js.ExecuteScript("window.scrollBy(0,document.body.scrollHeight)");
  36. }
  37.  
  38. [Test]
  39. public void Test1_1_ObjectIsDragable()
  40. {
  41. var dragableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[5]")));
  42. dragableButtonNavigation.Click();
  43.  
  44. IWebElement dragableObject = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("dragBox")));
  45.  
  46. var sourcePositionXBefore = dragableObject.Location.X;
  47.  
  48. Thread.Sleep(500);
  49. _builder.DragAndDropToOffset(dragableObject, 224, 102).Perform();
  50.  
  51. var sourcePositionXAfter = dragableObject.Location.X;
  52.  
  53. Assert.AreNotEqual(sourcePositionXBefore, sourcePositionXAfter);
  54. }
  55.  
  56.  
  57. [Test]
  58. public void Test1_2_MoveDraggableToLeftTopCorner()
  59. {
  60. var dragableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[5]")));
  61. dragableButtonNavigation.Click();
  62.  
  63. IWebElement dragableObject = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("dragBox")));
  64.  
  65. var sourcePositionXBefore = dragableObject.Location.X;
  66.  
  67. Thread.Sleep(500);
  68. _builder.DragAndDropToOffset(dragableObject, -294, -435).Perform();
  69.  
  70. var sourcePositionXAfter = dragableObject.Location.X;
  71.  
  72. Assert.AreNotEqual(sourcePositionXBefore, sourcePositionXAfter);
  73. }
  74.  
  75.  
  76. [Test]
  77. public void Test1_3_MoveDraggableToEnd()
  78. {
  79.  
  80. }
  81.  
  82.  
  83. [Test]
  84. public void Test2_1_DragAndDropToTheCenterOfDropArea()
  85. {
  86. var droppableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[4]")));
  87. droppableButtonNavigation.Click();
  88.  
  89. IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
  90. IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
  91.  
  92. var colorBefore = targetBox.GetCssValue("background-color");
  93.  
  94. Thread.Sleep(500);
  95. _builder.DragAndDrop(sourceBox, targetBox).Perform();
  96.  
  97. var colorAfter = targetBox.GetCssValue("background-color");
  98.  
  99. Assert.AreNotEqual(colorBefore, colorAfter);
  100. }
  101.  
  102.  
  103. [Test]
  104. public void Test2_2_DragAndDropToTheDownLeftCornerOfDropAreaStillNotDropped()
  105. {
  106. var droppableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[4]")));
  107. droppableButtonNavigation.Click();
  108.  
  109. IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
  110. IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
  111.  
  112. var colorBefore = targetBox.GetCssValue("background-color");
  113.  
  114. Thread.Sleep(500);
  115. _builder.DragAndDropToOffset(sourceBox, 224, 102).Perform();
  116.  
  117. var colorAfter = targetBox.GetCssValue("background-color");
  118.  
  119. Assert.AreEqual(colorBefore, colorAfter);
  120. }
  121.  
  122.  
  123. [Test]
  124. public void Test2_3_DragAndDropMessageCheck()
  125. {
  126. var droppableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[4]")));
  127. droppableButtonNavigation.Click();
  128.  
  129. IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
  130. IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
  131.  
  132. var messageBefore = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"droppable\"]/p")));
  133. Assert.AreEqual("Drop here", messageBefore.Text);
  134.  
  135. Thread.Sleep(500);
  136. _builder.DragAndDrop(sourceBox, targetBox).Perform();
  137.  
  138. var messageAfter = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"droppable\"]/p")));
  139. Assert.AreEqual("Dropped!", messageAfter.Text);
  140. }
  141.  
  142.  
  143. [Test]
  144. public void Test3_1_Resizable()
  145. {
  146. var resizableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[3]")));
  147. resizableButtonNavigation.Click();
  148. }
  149.  
  150.  
  151. [Test]
  152. public void Test3_2_Resizable()
  153. {
  154.  
  155. }
  156.  
  157.  
  158. [Test]
  159. public void Test4_1_Selectable()
  160. {
  161. var selectableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[2]")));
  162. selectableButtonNavigation.Click();
  163. }
  164.  
  165.  
  166. [Test]
  167. public void Test4_2_Selectable()
  168. {
  169.  
  170. }
  171.  
  172.  
  173. [Test]
  174. public void Test5_1_Sortable()
  175. {
  176. var sortableButtonNavigation = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/div/div/div[2]/div[1]/div/div/div[5]/div/ul/li[1]")));
  177. sortableButtonNavigation.Click();
  178. }
  179.  
  180.  
  181. [Test]
  182. public void Test5_2_Sortable()
  183. {
  184.  
  185. }
  186.  
  187. [TearDown]
  188. public void TearDown()
  189. {
  190. _driver.Quit();
  191. }
  192. }
  193. }
Add Comment
Please, Sign In to add comment