* [UWP] if a UI tests crashes the UWP window this will restart the window so all the rest of the tests can run

* simplify
This commit is contained in:
Shane Neuville 2019-03-05 11:07:57 -07:00 коммит произвёл Samantha Houts
Родитель a372395fb2
Коммит 0776812cbf
3 изменённых файлов: 37 добавлений и 24 удалений

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

@ -27,7 +27,7 @@ namespace Xamarin.Forms.Core.UITests
{ "button", "ControlType.Button" }
};
readonly WindowsDriver<WindowsElement> _session;
WindowsDriver<WindowsElement> _session;
readonly Dictionary<string, string> _translatePropertyAccessor = new Dictionary<string, string>
{
@ -42,9 +42,19 @@ namespace Xamarin.Forms.Core.UITests
WindowsElement _window;
public WinDriverApp(WindowsDriver<WindowsElement> session)
{
Init(session);
}
void Init(WindowsDriver<WindowsElement> session)
{
_session = session;
TestServer = new WindowsTestServer(_session);
TestServer = new WindowsTestServer(_session, this);
}
public void RestartFromCrash()
{
Init(WindowsTestBase.CreateWindowsDriver());
}
public void Back()
@ -511,7 +521,7 @@ namespace Xamarin.Forms.Core.UITests
MouseClickAt(x, y);
}
public ITestServer TestServer { get; }
public ITestServer TestServer { get; private set; }
public void TouchAndHold(Func<AppQuery, AppQuery> query)
{

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

@ -1,20 +1,11 @@
using System;
using System.Diagnostics;
using System.Resources;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Remote;
using Xamarin.Forms.Xaml;
using Xamarin.UITest;
using OpenQA.Selenium.Appium;
using System.Collections.Generic;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Appium.Windows.Enums;
using System.Windows.Input;
using Xamarin.UITest;
namespace Xamarin.Forms.Core.UITests
{
@ -26,19 +17,24 @@ namespace Xamarin.Forms.Core.UITests
public static IApp ConfigureApp()
{
if (Session == null)
{
AppiumOptions options = new AppiumOptions();
options.AddAdditionalCapability("app", "0d4424f6-1e29-4476-ac00-ba22c3789cb6_ph1m9x8skttmg!App");
options.AddAdditionalCapability("appArguments", "RunningAsUITests");
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), options);
Assert.IsNotNull(Session);
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
Reset();
}
Session = CreateWindowsDriver();
return new WinDriverApp(Session);
}
public static WindowsDriver<WindowsElement> CreateWindowsDriver()
{
AppiumOptions options = new AppiumOptions();
options.AddAdditionalCapability("app", "0d4424f6-1e29-4476-ac00-ba22c3789cb6_ph1m9x8skttmg!App");
options.AddAdditionalCapability("appArguments", "RunningAsUITests");
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), options);
Assert.IsNotNull(Session);
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
Reset();
return Session;
}
internal static void HandleAppClosed(Exception ex)
{
if (ex is InvalidOperationException && ex.Message == "Currently selected window has been closed")

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

@ -7,10 +7,12 @@ namespace Xamarin.Forms.Core.UITests
internal class WindowsTestServer : ITestServer
{
readonly WindowsDriver<WindowsElement> _session;
readonly WinDriverApp _winDriverApp;
public WindowsTestServer(WindowsDriver<WindowsElement> session)
public WindowsTestServer(WindowsDriver<WindowsElement> session, WinDriverApp winDriverApp)
{
_session = session;
_winDriverApp = winDriverApp;
}
public string Post(string endpoint, object arguments = null)
@ -31,6 +33,11 @@ namespace Xamarin.Forms.Core.UITests
{
return _session.CurrentWindowHandle;
}
catch (OpenQA.Selenium.WebDriverException we)
when (we.Message.Contains("Currently selected window has been closed"))
{
_winDriverApp.RestartFromCrash();
}
catch (Exception exception)
{
WindowsTestBase.HandleAppClosed(exception);