Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Node path to compile with appium 2 and make him cross-platform #659

Merged
merged 37 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ad72b1e
fix: Update WindowsNode path to compile with appium 2
Dor-bl Oct 3, 2023
0a1df1b
refactor!: Retrieve npm prefix path and use cross-platform commands t…
Dor-bl Oct 4, 2023
7665d51
fix: npm install prefix and npm install path mixup
Dor-bl Oct 5, 2023
aee59f4
fix: make PathToNode compatible with both Windows and Unix-based systems
Dor-bl Oct 5, 2023
8a2f5f2
Merge branch 'main' into Appiumjs_path
Dor-bl Oct 5, 2023
8e862d2
chore: Remove redundant NodePaths from the resources
Dor-bl Oct 5, 2023
88ea1c4
Merge branch 'Appiumjs_path' of https://github.com/Dor-bl/dotnet-clie…
Dor-bl Oct 5, 2023
ad2289d
chore: Remove comment section
Dor-bl Oct 5, 2023
9ca328d
chore: Add exception if npm path cannot be detected
Dor-bl Oct 5, 2023
aef7d02
chore: Rename _pathToCustomizedAppiumJs
Dor-bl Oct 5, 2023
4619f2b
chore: Add timeout for RunCommand
Dor-bl Oct 5, 2023
8bab6ef
chore: Optimize code performance
Dor-bl Oct 5, 2023
9cfd93c
chore: Optimize path readability on Windows platforms
Dor-bl Oct 5, 2023
abad288
chore: Switch from `npm list -g --depth=0` to `npm -g root` for bette…
Dor-bl Oct 5, 2023
7ac682a
chore: Remove comment section
Dor-bl Oct 5, 2023
ca7bff0
chore: Throw specific exception for npm commands
Dor-bl Oct 5, 2023
af3a35a
chore: Move declaration near reference
Dor-bl Oct 5, 2023
1e66da4
chore: Rename GetAppiumJsPath
Dor-bl Oct 5, 2023
cedd7e0
chore: Improve NPM path not found exception
Dor-bl Oct 6, 2023
187f693
chore: Rename resource file name
Dor-bl Oct 6, 2023
f94fd18
Merge branch 'main' into Appiumjs_path
Dor-bl Nov 11, 2023
ace2dbb
chore: Remove path replacement and add XML DOC
Dor-bl Nov 11, 2023
496c849
chore: Verify exit code on RunCommand() from Npm
Dor-bl Nov 11, 2023
27988b6
chore: Use GetNpmExecutablePath() on all platforms
Dor-bl Nov 11, 2023
70896e0
chore: log command upon errorin RunCommand()
Dor-bl Nov 11, 2023
76c1afa
chore: Improve NpmNotFoundException log
Dor-bl Nov 11, 2023
5a0a7d2
chore: Rename GetAppiumPackageIndexPath()
Dor-bl Nov 11, 2023
587859c
chore: Simplify InitAppiumPackageIndexPath()
Dor-bl Nov 11, 2023
8623567
chore: Simplify paths creation
Dor-bl Nov 12, 2023
4245ee3
chore: More exceptions mapping for RunCommand
Dor-bl Nov 12, 2023
ab5ace6
fix: More exceptions improvements in RunCommand()
Dor-bl Nov 13, 2023
e1bb71a
fix: Exceptions makeover pt. 3
Dor-bl Nov 13, 2023
58fd0c9
Merge branch 'main' into Appiumjs_path
Dor-bl Nov 13, 2023
981a645
fix: npm typo
Dor-bl Nov 13, 2023
951fef5
Merge branch 'Appiumjs_path' of https://github.com/Dor-bl/dotnet-clie…
Dor-bl Nov 13, 2023
7d4d700
chore: Minimise try-catch
Dor-bl Nov 13, 2023
4eb9393
chore: Remove unnecessary using
Dor-bl Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions test/integration/ServerTests/AppiumLocalServerLaunchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Net;
using System.Text;
using System.Threading;
using Appium.Net.Integration.Tests.Properties;
using Appium.Net.Integration.Tests.Helpers;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Service;
Expand All @@ -24,9 +23,6 @@ public class AppiumLocalServerLaunchingTest
[OneTimeSetUp]
public void BeforeAll()
{
var isWindows = Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows);
var isMacOs = Platform.CurrentPlatform.IsPlatformType(PlatformType.Mac);
var isLinux = Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux);

IPHostEntry host;
var hostName = Dns.GetHostName();
Expand All @@ -41,25 +37,8 @@ public void BeforeAll()
}
Console.WriteLine(_testIp);

byte[] bytes;
if (isWindows)
{
bytes = Resources.PathToWindowsNode;
_pathToCustomizedAppiumJs = Encoding.UTF8.GetString(bytes);
return;
}
if (isMacOs)
{
bytes = Resources.PathToMacOSNode;
_pathToCustomizedAppiumJs = Encoding.UTF8.GetString(bytes);
return;
}
if (isLinux)
{
bytes = Resources.PathToLinuxNode;
_pathToCustomizedAppiumJs = Encoding.UTF8.GetString(bytes);
return;
}
Paths paths = new Paths();
_pathToCustomizedAppiumJs = paths.PathToCustomizedAppiumJs;
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion test/integration/helpers/PathToWindowsNode
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
%USERPROFILE%/AppData/Roaming/npm/node_modules/appium/lib/appium.js
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 73 additions & 0 deletions test/integration/helpers/Paths.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Appium.Net.Integration.Tests.Properties;
using OpenQA.Selenium;
using System;
using System.Text;

namespace Appium.Net.Integration.Tests.Helpers
{
internal class Paths
{
private bool _isWindows;
private bool _isMacOs;
private bool _isLinux;
private string _pathToCustomizedAppiumJs;
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved

public Paths()
{
// Detect the platform during object creation.
_isWindows = Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows);
_isMacOs = Platform.CurrentPlatform.IsPlatformType(PlatformType.Mac);
_isLinux = Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux);
}

public string PathToCustomizedAppiumJs
{
get
{
if (_pathToCustomizedAppiumJs == null)
{
GetAppiumJsPath();
}
return _pathToCustomizedAppiumJs;
}
}

private void GetAppiumJsPath()
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
{
byte[] bytes;
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
string appiumJsPath = null;

if (_isWindows)
{
bytes = Resources.PathToWindowsNode;
appiumJsPath = Encoding.UTF8.GetString(bytes);
}
else if (_isMacOs)
{
bytes = Resources.PathToMacOSNode;
appiumJsPath = Encoding.UTF8.GetString(bytes);
}
else if (_isLinux)
{
bytes = Resources.PathToLinuxNode;
appiumJsPath = Encoding.UTF8.GetString(bytes);
}
else
{
// Handle unsupported platform
throw new PlatformNotSupportedException("Unsupported platform");
}

if (appiumJsPath.Contains("%USERPROFILE%"))
{
string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
userProfile = userProfile.Replace("\\", "/");
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
_pathToCustomizedAppiumJs = appiumJsPath.Replace("%USERPROFILE%", userProfile);
}
else
{
_pathToCustomizedAppiumJs = appiumJsPath;
}
}
}
}