{ "button", "ControlType.Button" }
};
- readonly WindowsDriver<WindowsElement> _session;
+ WindowsDriver<WindowsElement> _session;
readonly Dictionary<string, string> _translatePropertyAccessor = new Dictionary<string, string>
{
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()
MouseClickAt(x, y);
}
- public ITestServer TestServer { get; }
+ public ITestServer TestServer { get; private set; }
public void TouchAndHold(Func<AppQuery, AppQuery> query)
{
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
{
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")
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)
{
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);