Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Chrome;
- using OpenQA.Selenium.Interactions;
- using OpenQA.Selenium.Support.UI;
- using SeleniumExtras.WaitHelpers;
- using System;
- using System.IO;
- using System.Reflection;
- using System.Threading;
- namespace Demoqa
- {
- [TestFixture]
- class Demoqa
- {
- private IWebDriver _driver;
- private WebDriverWait _wait;
- private Actions _builder;
- [SetUp]
- public void SetUp()
- {
- _driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
- _driver.Manage().Window.Maximize();
- _driver.Navigate().GoToUrl("http://www.demoqa.com/");
- _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(4));
- _builder = new Actions(_driver);
- var interactionsButtonNavigation = _driver.FindElement(By.XPath("//*[@id=\"app\"]/div/div/div[2]/div/div[5]/div/div[3]"));
- interactionsButtonNavigation.Click();
- //Scroll to the end
- IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
- js.ExecuteScript("window.scrollBy(0,document.body.scrollHeight)");
- }
- [Test]
- public void Test1_1_ObjectIsDragable()
- {
- 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]")));
- dragableButtonNavigation.Click();
- IWebElement dragableObject = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("dragBox")));
- var sourcePositionXBefore = dragableObject.Location.X;
- Thread.Sleep(500);
- _builder.DragAndDropToOffset(dragableObject, 224, 102).Perform();
- var sourcePositionXAfter = dragableObject.Location.X;
- Assert.AreNotEqual(sourcePositionXBefore, sourcePositionXAfter);
- }
- [Test]
- public void Test1_2_MoveDraggableToLeftTopCorner()
- {
- 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]")));
- dragableButtonNavigation.Click();
- IWebElement dragableObject = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("dragBox")));
- var sourcePositionXBefore = dragableObject.Location.X;
- Thread.Sleep(500);
- _builder.DragAndDropToOffset(dragableObject, -294, -435).Perform();
- var sourcePositionXAfter = dragableObject.Location.X;
- Assert.AreNotEqual(sourcePositionXBefore, sourcePositionXAfter);
- }
- [Test]
- public void Test1_3_MoveDraggableToEnd()
- {
- }
- [Test]
- public void Test2_1_DragAndDropToTheCenterOfDropArea()
- {
- 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]")));
- droppableButtonNavigation.Click();
- IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
- IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
- var colorBefore = targetBox.GetCssValue("background-color");
- Thread.Sleep(500);
- _builder.DragAndDrop(sourceBox, targetBox).Perform();
- var colorAfter = targetBox.GetCssValue("background-color");
- Assert.AreNotEqual(colorBefore, colorAfter);
- }
- [Test]
- public void Test2_2_DragAndDropToTheDownLeftCornerOfDropAreaStillNotDropped()
- {
- 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]")));
- droppableButtonNavigation.Click();
- IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
- IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
- var colorBefore = targetBox.GetCssValue("background-color");
- Thread.Sleep(500);
- _builder.DragAndDropToOffset(sourceBox, 224, 102).Perform();
- var colorAfter = targetBox.GetCssValue("background-color");
- Assert.AreEqual(colorBefore, colorAfter);
- }
- [Test]
- public void Test2_3_DragAndDropMessageCheck()
- {
- 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]")));
- droppableButtonNavigation.Click();
- IWebElement sourceBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("draggable")));
- IWebElement targetBox = _wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("droppable")));
- var messageBefore = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"droppable\"]/p")));
- Assert.AreEqual("Drop here", messageBefore.Text);
- Thread.Sleep(500);
- _builder.DragAndDrop(sourceBox, targetBox).Perform();
- var messageAfter = _wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"droppable\"]/p")));
- Assert.AreEqual("Dropped!", messageAfter.Text);
- }
- [Test]
- public void Test3_1_Resizable()
- {
- 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]")));
- resizableButtonNavigation.Click();
- }
- [Test]
- public void Test3_2_Resizable()
- {
- }
- [Test]
- public void Test4_1_Selectable()
- {
- 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]")));
- selectableButtonNavigation.Click();
- }
- [Test]
- public void Test4_2_Selectable()
- {
- }
- [Test]
- public void Test5_1_Sortable()
- {
- 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]")));
- sortableButtonNavigation.Click();
- }
- [Test]
- public void Test5_2_Sortable()
- {
- }
- [TearDown]
- public void TearDown()
- {
- _driver.Quit();
- }
- }
- }
Add Comment
Please, Sign In to add comment