Skip to content

Commit c7311de

Browse files
committed
updates for Appium NovaWindows Driver installing
1 parent 210ba1f commit c7311de

File tree

7 files changed

+93
-61
lines changed

7 files changed

+93
-61
lines changed

src/Bellatrix.Desktop/components/ComboBox.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public virtual void SelectByText(string value)
3737
{
3838
Selecting?.Invoke(this, new ComponentActionEventArgs(this, value));
3939

40-
if (ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
40+
try
4141
{
4242
var itemToSelect = this.CreateAllByTag<ListItem>("ListItem")
4343
.FirstOrDefault(x => x.CreateByTag<Label>("Text").InnerText == value);
4444

4545
WrappedDriver.ExecuteScript("windows: select", itemToSelect);
4646
}
47-
else
47+
catch
4848
{
4949
if (WrappedElement.Text != value)
5050
{
@@ -59,11 +59,6 @@ public virtual ListItem SelectedItem
5959
{
6060
get
6161
{
62-
if (!ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
63-
{
64-
throw new InvalidOperationException("This option is supported only with ExperimentalDesktopDriver enabled");
65-
}
66-
6762
return new ComponentsRepository().CreateComponentThatIsFound<ListItem>(null,
6863
(AppiumElement)WrappedDriver.ExecuteScript("windows: selectedItem", WrappedElement));
6964
}
@@ -74,12 +69,14 @@ public virtual string InnerText
7469
{
7570
get
7671
{
77-
if (ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
72+
try
7873
{
7974
return SelectedItem.CreateByTag<Label>("Text").InnerText;
80-
}
81-
82-
return GetInnerText();
75+
}
76+
catch
77+
{
78+
return GetInnerText();
79+
}
8380
}
8481
}
8582

src/Bellatrix.Desktop/components/Core/Component.DefaultActions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ internal virtual void Hover(EventHandler<ComponentActionEventArgs> hovering, Eve
4141
{
4242
hovering?.Invoke(this, new ComponentActionEventArgs(this));
4343

44-
if (ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
45-
{
46-
new Actions(WrappedDriver).MoveToElement(WrappedElement).Perform();
47-
}
48-
else
44+
try
4945
{
5046
WrappedDriver.ExecuteScript("windows: hover", new Dictionary<string, object>
5147
{
@@ -54,6 +50,10 @@ internal virtual void Hover(EventHandler<ComponentActionEventArgs> hovering, Eve
5450
{ "durationMs", 0 }
5551
});
5652
}
53+
catch
54+
{
55+
new Actions(WrappedDriver).MoveToElement(WrappedElement).Perform();
56+
}
5757

5858
hovered?.Invoke(this, new ComponentActionEventArgs(this));
5959
}

src/Bellatrix.Desktop/components/Core/Component.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,15 @@ public virtual bool IsVisible
187187

188188
public virtual void ScrollToVisible()
189189
{
190-
if (ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
190+
ScrollingToVisible?.Invoke(this, new ComponentActionEventArgs(this));
191+
try
191192
{
192193
WrappedDriver.ExecuteScript("windows: scrollToVisible", WrappedElement);
193-
return;
194194
}
195-
196-
ScrollingToVisible?.Invoke(this, new ComponentActionEventArgs(this));
197-
198-
var touchActions = new Actions(WrappedDriver);
199-
System.Threading.Thread.Sleep(2000);
200-
touchActions.ScrollToElement(WrappedElement);
201-
this.ToBeVisible().ToExists().WaitToBe();
195+
catch
196+
{
197+
// ignore
198+
}
202199
ScrolledToVisible?.Invoke(this, new ComponentActionEventArgs(this));
203200
}
204201

src/Bellatrix.Desktop/components/ListItem.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,16 @@ public virtual void Hover()
3232

3333
public virtual void Select()
3434
{
35-
if (!ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
36-
{
37-
throw new InvalidOperationException("This option is supported only with ExperimentalDesktopDriver enabled");
38-
}
39-
4035
WrappedDriver.ExecuteScript("windows: select", WrappedElement);
4136
}
42-
37+
4338
public virtual void AddToSelection()
4439
{
45-
if (!ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
46-
{
47-
throw new InvalidOperationException("This option is supported only with ExperimentalDesktopDriver enabled");
48-
}
49-
5040
WrappedDriver.ExecuteScript("windows: addToSelection", WrappedElement);
5141
}
52-
42+
5343
public virtual void RemoveFromSelection()
5444
{
55-
if (!ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver)
56-
{
57-
throw new InvalidOperationException("This option is supported only with ExperimentalDesktopDriver enabled");
58-
}
59-
6045
WrappedDriver.ExecuteScript("windows: removeFromSelection", WrappedElement);
6146
}
6247
}

src/Bellatrix.Desktop/infrastructure/App.cs

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,87 @@ public static void StartAppiumServer()
6767

6868
var uri = new Uri(ConfigurationService.GetSection<DesktopSettings>().ExecutionSettings.Url);
6969

70-
// Anton(06.09.2018): maybe we can kill WinAppDriver every time
71-
if (ProcessProvider.IsProcessWithNameRunning("WinAppDriver") || ProcessProvider.IsPortBusy(uri.Port))
70+
var appiumPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "npm");
71+
if (!Directory.Exists(appiumPath))
7272
{
73-
return;
73+
throw new ArgumentException("Node.js is not installed on the machine. To use BELLATRIX Desktop libraries you need to install it first. You can download it from here: https://nodejs.org/en/download");
7474
}
7575

76-
var winAppDriverPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Application Driver");
77-
if (!Directory.Exists(winAppDriverPath))
76+
var appiumPs1Path = Path.Combine(appiumPath, "appium.ps1");
77+
78+
// Minimum Appium Version Check
79+
var process = new Process
80+
{
81+
StartInfo = new ProcessStartInfo
82+
{
83+
FileName = "powershell.exe",
84+
Arguments = $"-NoProfile -ExecutionPolicy RemoteSigned -File \"{appiumPs1Path}\" -v",
85+
RedirectStandardOutput = true,
86+
UseShellExecute = false,
87+
CreateNoWindow = true,
88+
WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
89+
}
90+
};
91+
92+
process.Start();
93+
var output = process.StandardOutput.ReadToEnd().Trim();
94+
process.WaitForExit();
95+
96+
if (Version.TryParse(output, out var version) && version < new Version(3, 1, 0))
7897
{
79-
throw new ArgumentException("Windows Application Driver is not installed on the machine. To use BELLATRIX Desktop libraries you need to install it first. You can download it from here: https://github.com/Microsoft/WinAppDriver/releases");
98+
throw new ArgumentException("Appium version 3.1.0 or higher is required. Please update Appium by running: npm install -g appium@latest");
8099
}
81100

82-
var appiumPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "npm");
83-
if (!Directory.Exists(appiumPath))
101+
const string latestVersion = "1.2.0-preview.1";
102+
103+
process = new Process
84104
{
85-
throw new ArgumentException("Node.js is not installed on the machine. To use BELLATRIX Desktop libraries you need to install it first. You can download it from here: https://nodejs.org/en/download");
105+
StartInfo = new ProcessStartInfo
106+
{
107+
FileName = "powershell.exe",
108+
Arguments = "-NoProfile -ExecutionPolicy RemoteSigned -Command \"appium driver list --installed --json\"",
109+
RedirectStandardOutput = true,
110+
UseShellExecute = false,
111+
CreateNoWindow = true,
112+
WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
113+
}
114+
};
115+
116+
process.Start();
117+
output = process.StandardOutput.ReadToEnd();
118+
process.WaitForExit();
119+
120+
var json = System.Text.Json.JsonDocument.Parse(output);
121+
// TODO: remove latestVersion when Appium 3 version is officially out
122+
if (!json.RootElement.TryGetProperty("novawindows", out var driver))
123+
{
124+
Console.WriteLine("NovaWindows driver not found. Installing...");
125+
Process.Start(
126+
"powershell.exe",
127+
$"-NoProfile -ExecutionPolicy RemoteSigned -Command \"appium driver install --source=npm appium-novawindows-driver@{latestVersion}\""
128+
)?.WaitForExit();
129+
}
130+
else
131+
{
132+
var installedVersion = driver.GetProperty("version").GetString() ?? "";
133+
if (installedVersion != latestVersion)
134+
{
135+
Console.WriteLine($"Updating NovaWindows driver to {latestVersion}...");
136+
Process.Start(
137+
"powershell.exe",
138+
"-NoProfile -ExecutionPolicy RemoteSigned -Command \"appium driver update novawindows\""
139+
)?.WaitForExit();
140+
}
141+
else
142+
{
143+
Console.WriteLine("NovaWindows driver is up to date.");
144+
}
86145
}
87146

88-
var appiumPs1Path = Path.Combine(appiumPath, "appium.ps1");
89147
_appiumServerProcess = ProcessProvider.StartProcess(
90148
"powershell.exe",
91149
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
92-
$"-NoProfile -ExecutionPolicy RemoteSigned -File \"{appiumPs1Path}\" -a {uri.Host} -p {uri.Port} --allow-insecure=power_shell",
150+
$"-NoProfile -ExecutionPolicy RemoteSigned -File \"{appiumPs1Path}\" -a {uri.Host} -p {uri.Port} --allow-insecure=novawindows:power_shell",
93151
true);
94152

95153
ProcessProvider.WaitPortToGetBusy(uri.Port);

src/Bellatrix.Desktop/services/WrappedWebDriverCreateService.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ public static WindowsDriver Create(AppInitializationInfo appConfiguration, Servi
4646
{ "ms:experimental-webdriver", true }
4747
};
4848

49-
appiumOptions.Add("automationName",
50-
ConfigurationService.GetSection<ExecutionSettings>().ExperimentalDesktopDriver
51-
? "UIAutomation"
52-
: "Windows");
49+
appiumOptions.Add("automationName", "NovaWindows");
5350

5451
if (appConfiguration.AppPath == "Root")
5552
{
@@ -96,7 +93,7 @@ public static WindowsDriver Create(AppInitializationInfo appConfiguration, Servi
9693
{ "endElementId", closeButton.Id },
9794
{ "durationMs", 0 }
9895
});
99-
96+
10097
wrappedWebDriver.SwitchTo().Window(wrappedWebDriver.CurrentWindowHandle);
10198
}
10299
catch (Exception e)
@@ -126,4 +123,4 @@ private static void ChangeWindowSize(Size windowSize, WindowsDriver wrappedWebDr
126123
throw;
127124
}
128125
}
129-
}
126+
}

src/Bellatrix.Desktop/settings/ExecutionSettings.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ public class ExecutionSettings
2626
public List<Dictionary<string, object>> Arguments { get; set; }
2727

2828
public bool IsCloudRun { get; set; }
29-
30-
public bool ExperimentalDesktopDriver { get; set; } = false;
3129
}

0 commit comments

Comments
 (0)