Last active
September 26, 2018 15:30
-
-
Save nadvolod/137175dff787386109be2c60c2e1da84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NUnit.Framework; | |
using OpenQA.Selenium.Firefox; | |
using OpenQA.Selenium.Support.UI; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Interactions; | |
using System.IO; | |
namespace DragDropTutorial | |
{ | |
[TestFixture] | |
public class DragDropTests | |
{ | |
private IWebDriver _driver; | |
private WebDriverWait _wait; | |
private Actions _actions; | |
[SetUp] | |
public void Setup() | |
{ | |
_driver = new FirefoxDriver(); | |
_wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(6)); | |
_actions = new Actions(_driver); | |
} | |
[Test] | |
public void Example1() | |
{ | |
_driver.Navigate().GoToUrl("http://jqueryui.com/droppable/"); | |
_wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.ClassName("demo-frame"))); | |
var sourceLocator = _driver.FindElement(By.Id("draggable")); | |
var destinationLocator = _driver.FindElement(By.Id("droppable")); | |
_actions.DragAndDrop(sourceLocator, destinationLocator).Build().Perform(); | |
var droppedText = destinationLocator.Text; | |
Assert.AreEqual("Dropped!", droppedText); | |
} | |
[Test] | |
public void DifferentWayToDragDrop() | |
{ | |
_driver.Navigate().GoToUrl("http://jqueryui.com/droppable/"); | |
_wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.ClassName("demo-frame"))); | |
var sourceLocator = _driver.FindElement(By.Id("draggable")); | |
var destinationLocator = _driver.FindElement(By.Id("droppable")); | |
_actions | |
.ClickAndHold(sourceLocator) | |
.MoveToElement(destinationLocator) | |
.Release(destinationLocator) | |
.Build() | |
.Perform(); | |
var droppedText = destinationLocator.Text; | |
Assert.AreEqual("Dropped!", droppedText); | |
} | |
[Test] | |
public void jQueryDragDropQuiz() | |
{ | |
_driver.Navigate().GoToUrl("http://www.pureexample.com/jquery-ui/basic-droppable.html"); | |
_wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id("ExampleFrame-94"))); | |
var sourceLocator = _driver.FindElement(By.XPath("//*[@class='square ui-draggable']")); | |
var destinationLocator = _driver.FindElement(By.XPath("//*[contains(text(),'Drop here')]")); | |
_actions.DragAndDrop(sourceLocator, destinationLocator).Build().Perform(); | |
var droppedText = destinationLocator.Text; | |
Assert.AreEqual("dropped!", droppedText); | |
} | |
//Not supported by Selenium Webdriver - http://stackoverflow.com/questions/29381233/how-to-simulate-html5-drag-and-drop-in-selenium-webdriver | |
//https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6315 | |
[Test] | |
public void TestHtml5_Quiz() | |
{ | |
_driver.Navigate().GoToUrl("http://the-internet.herokuapp.com/drag_and_drop"); | |
var source = _wait.Until(ExpectedConditions.ElementIsVisible(By.Id("column-a"))); | |
var jsFile = File.ReadAllText(@"C:\Automated_Testing\drag_and_drop_helper.js"); | |
IJavaScriptExecutor js = _driver as IJavaScriptExecutor; | |
//Execute java script - #{{id value}} | |
js.ExecuteScript(jsFile + "$('#column-a').simulateDragDrop({ dropTarget: '#column-b'});"); | |
} | |
public void UserInteractionsTest() | |
{ | |
_driver.Navigate().GoToUrl("https://compendiumdev.co.uk/selenium/gui_user_interactions.html"); | |
} | |
[TearDown] | |
public void Cleanup() | |
{ | |
_driver.Close(); | |
//_driver.Quit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment