diff --git a/Tests/W3CWebDriver/TouchBase.cs b/Tests/W3CWebDriver/TouchBase.cs new file mode 100644 index 0000000..d939b29 --- /dev/null +++ b/Tests/W3CWebDriver/TouchBase.cs @@ -0,0 +1,138 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using System; +using System.IO; +using System.Net; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium.Appium.iOS; +using OpenQA.Selenium.Remote; +using Newtonsoft.Json.Linq; + +namespace W3CWebDriver +{ + public class TouchBase + { + protected static IOSDriver session; + + [TestInitialize] + public void TestInit() + { + // Save application window original size and position + DesiredCapabilities appCapabilities = new DesiredCapabilities(); + appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId); + session = new IOSDriver(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities); + Assert.IsNotNull(session); + Assert.IsNotNull(session.SessionId); + } + + [TestCleanup] + public void TestClean() + { + if (session != null) + { + session.Quit(); + session = null; + } + } + + protected static HttpWebResponse SendTouchPost(String touchType, JObject requestObject) + { + var request = WebRequest.Create(CommonTestSettings.WindowsApplicationDriverUrl + "/session/" + session.SessionId + "/touch/" + touchType); + request.Method = "POST"; + request.ContentType = "application/json"; + + String postData = requestObject.ToString(); + byte[] byteArray = Encoding.UTF8.GetBytes(postData); + request.ContentLength = byteArray.Length; + Stream dataStream = request.GetRequestStream(); + dataStream.Write(byteArray, 0, byteArray.Length); + dataStream.Close(); + return request.GetResponse() as HttpWebResponse; + } + + public void ErrorTouchClosedWindow(string touchType) + { + JObject enterRequestObject = new JObject(); + enterRequestObject["element"] = session.FindElementByAccessibilityId("m_newTabPageGoButton").GetAttribute("elementId"); + session.Close(); + HttpWebResponse response = SendTouchPost(touchType, enterRequestObject); + Assert.Fail("Exception should have been thrown because there is no such window"); + } + + public void ErrorTouchInvalidElement(string touchType) + { + JObject enterRequestObject = new JObject(); + enterRequestObject["element"] = "InvalidElementId"; + HttpWebResponse response = SendTouchPost(touchType, enterRequestObject); + Assert.Fail("Exception should have been thrown because there is no such element"); + } + + public void ErrorTouchStaleElement(string touchType) + { + Assert.IsNotNull(session.SessionId); + var title = session.Title; + + GoToGitHub(); + + // Make sure the page you went to is not the page you started on + Assert.AreNotEqual(title, session.Title); + + // Create a request to touch Microsoft link + JObject microsoftClickRequest = new JObject(); + microsoftClickRequest["element"] = session.FindElementByName("Microsoft").GetAttribute("elementId"); + + // Navigate back to the original page + JObject backRequestObject = new JObject(); + backRequestObject["element"] = session.FindElementByName("Back").GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("click", backRequestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + + // Make sure you are on the original page + Assert.AreEqual(title, session.Title); + + // Try to touch the microsoft button + HttpWebResponse staleResponse = SendTouchPost(touchType, microsoftClickRequest); + } + + public void ErrorTouchInvalidArguments(string touchType) + { + JObject enterRequestObject = new JObject(); + HttpWebResponse response = SendTouchPost(touchType, enterRequestObject); + session.Close(); + Assert.Fail("Exception should have been thrown because there are insufficient arguments"); + } + + protected void GoToGitHub() + { + IOSElement addressEditBox = session.FindElementByAccessibilityId("addressEditBox"); + Assert.IsNotNull(addressEditBox); + + addressEditBox.SendKeys("https://github.com/Microsoft/WinAppDriver"); + + JObject enterRequestObject = new JObject(); + enterRequestObject["element"] = session.FindElementByAccessibilityId("m_newTabPageGoButton").GetAttribute("elementId"); + HttpWebResponse response = SendTouchPost("click", enterRequestObject); + Assert.IsNotNull(response); + + System.Threading.Thread.Sleep(3000); + } + } +} \ No newline at end of file diff --git a/Tests/W3CWebDriver/TouchClick.cs b/Tests/W3CWebDriver/TouchClick.cs new file mode 100644 index 0000000..edb0588 --- /dev/null +++ b/Tests/W3CWebDriver/TouchClick.cs @@ -0,0 +1,79 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using System.Net; + +namespace W3CWebDriver +{ + [TestClass] + public class TouchClick : TouchBase + { + + [TestMethod] + public void TouchSingleClick() + { + Assert.IsNotNull(session.SessionId); + var title = session.Title; + + GoToGitHub(); + + // Make sure the page you went to is not the page you started on + Assert.AreNotEqual(title, session.Title); + + // Navigate back to the original page + JObject backRequestObject = new JObject(); + backRequestObject["element"] = session.FindElementByName("Back").GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("click", backRequestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + + // Make sure you are on the original page + Assert.AreEqual(title, session.Title); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchClickClosedWindow() + { + ErrorTouchClosedWindow("click"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchClickInvalidElement() + { + ErrorTouchInvalidElement("click"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchClickStaleElement() + { + ErrorTouchStaleElement("click"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchClickInvalidArguments() + { + ErrorTouchInvalidArguments("click"); + } + } +} diff --git a/Tests/W3CWebDriver/TouchDoubleClick.cs b/Tests/W3CWebDriver/TouchDoubleClick.cs new file mode 100644 index 0000000..7f61a1f --- /dev/null +++ b/Tests/W3CWebDriver/TouchDoubleClick.cs @@ -0,0 +1,92 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using System.Net; + +namespace W3CWebDriver +{ + [TestClass] + public class TouchDoubleClick : TouchBase + { + + [TestMethod] + public void TouchDoubleClickBackButton() + { + Assert.IsNotNull(session.SessionId); + var firstTitle = session.Title; + + // Navigate forward a page + GoToGitHub(); + + // Make sure the page you went to is not the page you started on + var secondTitle = session.Title; + Assert.AreNotEqual(firstTitle, secondTitle); + + // Navigate forward another page + JObject microsoftClickRequest = new JObject(); + microsoftClickRequest["element"] = session.FindElementByName("Microsoft").GetAttribute("elementId"); + HttpWebResponse bingSearchResponse = SendTouchPost("click", microsoftClickRequest); + Assert.IsNotNull(bingSearchResponse); + + System.Threading.Thread.Sleep(1000); + + // Make sure the page you went to is not either of the previous pages + var finalTitle = session.Title; + Assert.AreNotEqual(firstTitle, finalTitle); + Assert.AreNotEqual(secondTitle, finalTitle); + + JObject doubleClickRequestObject = new JObject(); + doubleClickRequestObject["element"] = session.FindElementByName("Back").GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("doubleclick", doubleClickRequestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + + Assert.AreEqual(firstTitle, session.Title); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchDoubleClickClosedWindow() + { + ErrorTouchClosedWindow("doubleclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchDoubleClickInvalidElement() + { + ErrorTouchInvalidElement("doubleclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchDoubleClickStaleElement() + { + ErrorTouchStaleElement("doubleclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchDoubleClickInvalidArguments() + { + ErrorTouchInvalidArguments("doubleclick"); + } + } +} diff --git a/Tests/W3CWebDriver/TouchFlick.cs b/Tests/W3CWebDriver/TouchFlick.cs new file mode 100644 index 0000000..cc00834 --- /dev/null +++ b/Tests/W3CWebDriver/TouchFlick.cs @@ -0,0 +1,88 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using System.Net; + +namespace W3CWebDriver +{ + [TestClass] + public class TouchFlick : TouchBase + { + [TestMethod] + public void TouchFlickWithoutElement() + { + Assert.IsNotNull(session.SessionId); + + GoToGitHub(); + + JObject requestObject = new JObject(); + requestObject["xspeed"] = 0; + requestObject["yspeed"] = 1000; + + HttpWebResponse response2 = SendTouchPost("flick", requestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + } + + [TestMethod] + public void TouchFlickOnElement() + { + Assert.IsNotNull(session.SessionId); + + GoToGitHub(); + + JObject flickRequestObject = new JObject(); + flickRequestObject["xoffset"] = 0; + flickRequestObject["yoffset"] = -100; + flickRequestObject["speed"] = 1; + flickRequestObject["element"] = session.FindElementByName("Explore").GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("flick", flickRequestObject); + Assert.IsNotNull(response2); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchFlickClosedWindow() + { + ErrorTouchClosedWindow("flick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchFlickInvalidElement() + { + ErrorTouchInvalidElement("flick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchFlickStaleElement() + { + ErrorTouchStaleElement("flick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchFlickInvalidArguments() + { + ErrorTouchInvalidArguments("flick"); + } + } +} diff --git a/Tests/W3CWebDriver/TouchLongClick.cs b/Tests/W3CWebDriver/TouchLongClick.cs new file mode 100644 index 0000000..dabcceb --- /dev/null +++ b/Tests/W3CWebDriver/TouchLongClick.cs @@ -0,0 +1,72 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using OpenQA.Selenium.Appium.iOS; +using System.Net; + +namespace W3CWebDriver +{ + [TestClass] + public class TouchLongClick : TouchBase + { + [TestMethod] + public void TouchLongClickNavigationBar() + { + Assert.IsNotNull(session.SessionId); + + GoToGitHub(); + + JObject requestObject = new JObject(); + IOSElement addressEditBox = session.FindElementByAccessibilityId("addressEditBox"); + requestObject["element"] = addressEditBox.GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("longclick", requestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchLongClickClosedWindow() + { + ErrorTouchClosedWindow("longclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchLongClickInvalidElement() + { + ErrorTouchInvalidElement("longclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchLongClickStaleElement() + { + ErrorTouchStaleElement("longclick"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchLongClickInvalidArguments() + { + ErrorTouchInvalidArguments("longclick"); + } + } +} diff --git a/Tests/W3CWebDriver/TouchScroll.cs b/Tests/W3CWebDriver/TouchScroll.cs new file mode 100644 index 0000000..2d9d0b4 --- /dev/null +++ b/Tests/W3CWebDriver/TouchScroll.cs @@ -0,0 +1,90 @@ +//****************************************************************************** +// +// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +//****************************************************************************** + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using System.Net; + +namespace W3CWebDriver +{ + [TestClass] + public class TouchScroll : TouchBase + { + [TestMethod] + public void TouchScrollWithoutElement() + { + Assert.IsNotNull(session.SessionId); + + GoToGitHub(); + + JObject requestObject = new JObject(); + requestObject["xoffset"] = 0; + requestObject["yoffset"] = 100; + + HttpWebResponse response2 = SendTouchPost("scroll", requestObject); + Assert.IsNotNull(response2); + + System.Threading.Thread.Sleep(1000); + } + + [TestMethod] + public void TouchScrollOnElement() + { + Assert.IsNotNull(session.SessionId); + + GoToGitHub(); + + JObject newTabRequestObject = new JObject(); + newTabRequestObject["element"] = session.FindElementByAccessibilityId("AddTabButton").GetAttribute("elementId"); + + JObject scrollRequestObject = new JObject(); + scrollRequestObject["xoffset"] = 0; + scrollRequestObject["yoffset"] = -100; + scrollRequestObject["element"] = session.FindElementByName("Explore").GetAttribute("elementId"); + + HttpWebResponse response2 = SendTouchPost("scroll", scrollRequestObject); + Assert.IsNotNull(response2); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchScrollClosedWindow() + { + ErrorTouchClosedWindow("scroll"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchScrollInvalidElement(string touchType) + { + ErrorTouchInvalidElement("scroll"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchScrollStaleElement(string touchType) + { + ErrorTouchStaleElement("scroll"); + } + + [TestMethod] + [ExpectedException(typeof(System.Net.WebException))] + public void ErrorTouchScrollInvalidArguments() + { + ErrorTouchInvalidArguments("scroll"); + } + } +} diff --git a/Tests/W3CWebDriver/W3CWebDriver.csproj b/Tests/W3CWebDriver/W3CWebDriver.csproj index 4bb1224..6083986 100644 --- a/Tests/W3CWebDriver/W3CWebDriver.csproj +++ b/Tests/W3CWebDriver/W3CWebDriver.csproj @@ -76,6 +76,7 @@ + @@ -83,6 +84,11 @@ + + + + +