This commit is contained in:
Gilles Khouzam 2016-08-24 17:01:16 -07:00
Родитель cb24e3aca5 40c92ac1a6
Коммит 69236cb937
7 изменённых файлов: 565 добавлений и 0 удалений

Просмотреть файл

@ -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<IOSElement> session;
[TestInitialize]
public void TestInit()
{
// Save application window original size and position
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", CommonTestSettings.EdgeAppId);
session = new IOSDriver<IOSElement>(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);
}
}
}

Просмотреть файл

@ -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");
}
}
}

Просмотреть файл

@ -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");
}
}
}

Просмотреть файл

@ -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");
}
}
}

Просмотреть файл

@ -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");
}
}
}

Просмотреть файл

@ -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");
}
}
}

Просмотреть файл

@ -76,6 +76,7 @@
<ItemGroup>
<Compile Include="AlarmClockBase.cs" />
<Compile Include="Forward.cs" />
<Compile Include="TouchBase.cs" />
<Compile Include="ElementAttribute.cs" />
<Compile Include="Selected.cs" />
<Compile Include="Screenshot.cs" />
@ -83,6 +84,11 @@
<Compile Include="Sessions.cs" />
<Compile Include="Location.cs" />
<Compile Include="Back.cs" />
<Compile Include="TouchFlick.cs" />
<Compile Include="TouchDoubleClick.cs" />
<Compile Include="TouchLongClick.cs" />
<Compile Include="TouchScroll.cs" />
<Compile Include="TouchClick.cs" />
<Compile Include="Title.cs" />
<Compile Include="Status.cs" />
<Compile Include="Window.cs" />