Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="7.0.0" />
<PackageReference Include="Appium.WebDriver" Version="8.0.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="7.0.0" />
<PackageReference Include="Appium.WebDriver" Version="8.0.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
Expand Down
15 changes: 10 additions & 5 deletions src/Controls/tests/TestCases.Shared.Tests/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ but both can happen.
{
case TestDevice.Android:
environmentName = "android";
var deviceApiLevel = (long)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceApiLevel");
var deviceScreenSize = (string)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceScreenSize");
var deviceScreenDensity = (long)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceScreenDensity");
var deviceApiLevel = (long?)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceApiLevel")
?? throw new InvalidOperationException("deviceApiLevel capability is missing or null.");
var deviceScreenSize = (string?)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceScreenSize")
?? throw new InvalidOperationException("deviceScreenSize capability is missing or null.");
var deviceScreenDensity = (long?)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceScreenDensity")
?? throw new InvalidOperationException("deviceScreenDensity capability is missing or null.");

if (!(deviceApiLevel == 30 && deviceScreenSize == "1080x1920" && deviceScreenDensity == 420))
{
Expand All @@ -199,8 +202,10 @@ but both can happen.
break;

case TestDevice.iOS:
var platformVersion = (string)((AppiumApp)App).Driver.Capabilities.GetCapability("platformVersion");
var device = (string)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceName");
var platformVersion = (string?)((AppiumApp)App).Driver.Capabilities.GetCapability("platformVersion")
?? throw new InvalidOperationException("platformVersion capability is missing or null.");
var device = (string?)((AppiumApp)App).Driver.Capabilities.GetCapability("deviceName")
?? throw new InvalidOperationException("deviceName capability is missing or null.");

if (device.Contains(" Xs", StringComparison.OrdinalIgnoreCase) && platformVersion == "18.0")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="7.0.0" />
<PackageReference Include="Appium.WebDriver" Version="8.0.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="7.0.0" />
<PackageReference Include="Appium.WebDriver" Version="8.0.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ protected CommandResponse ActivateContextMenu(IDictionary<string, object> parame
{
var appiumElement = GetAppiumElement(element);

if (appiumElement == null)
{
return CommandResponse.FailedEmptyResponse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var longPress = new ActionSequence(touchDevice, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ CommandResponse ToggleAirplaneMode(IDictionary<string, object> parameters)
if (_appiumApp.Driver is AndroidDriver androidDriver)
{
// Toggle airplane mode on device.
androidDriver.ToggleAirplaneMode();
var currentConnectivity = androidDriver.ExecuteScript("mobile:getConnectivity") as IDictionary<string, object>;

return CommandResponse.SuccessEmptyResponse;
if (currentConnectivity is not null && currentConnectivity.TryGetValue("airplaneMode", out var currentState))
{
bool newState = !(bool)currentState;

var connectivityParams = new Dictionary<string, object> { { "airplaneMode", newState } };
androidDriver.ExecuteScript("mobile:setConnectivity", connectivityParams);

return CommandResponse.SuccessEmptyResponse;
}
}

return CommandResponse.FailedEmptyResponse;
Expand All @@ -73,9 +81,18 @@ CommandResponse ToggleData(IDictionary<string, object> parameters)
{
if (_appiumApp.Driver is AndroidDriver androidDriver)
{
androidDriver.ToggleData();
// Toggle device data.
var currentConnectivity = androidDriver.ExecuteScript("mobile:getConnectivity") as IDictionary<string, object>;

return CommandResponse.SuccessEmptyResponse;
if (currentConnectivity is not null && currentConnectivity.TryGetValue("data", out var currentState))
{
bool newState = !(bool)currentState;

var connectivityParams = new Dictionary<string, object> { { "data", newState } };
androidDriver.ExecuteScript("mobile:setConnectivity", connectivityParams);

return CommandResponse.SuccessEmptyResponse;
}
}

return CommandResponse.FailedEmptyResponse;
Expand All @@ -85,10 +102,18 @@ CommandResponse ToggleWifi(IDictionary<string, object> parameters)
{
if (_appiumApp.Driver is AndroidDriver androidDriver)
{
// Switch the state of the wifi service
androidDriver.ToggleWifi();
// Switch the state of the WiFi service
var currentConnectivity = androidDriver.ExecuteScript("mobile:getConnectivity") as IDictionary<string, object>;

return CommandResponse.SuccessEmptyResponse;
if (currentConnectivity is not null && currentConnectivity.TryGetValue("wifi", out var currentState))
{
bool newState = !(bool)currentState;

var connectivityParams = new Dictionary<string, object> { { "wifi", newState } };
androidDriver.ExecuteScript("mobile:setConnectivity", connectivityParams);

return CommandResponse.SuccessEmptyResponse;
}
}

return CommandResponse.FailedEmptyResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ public AppiumAndroidVirtualKeyboardActions(AppiumApp app)

protected override CommandResponse DismissKeyboard(IDictionary<string, object> parameters)
{
if (_app.Driver.IsKeyboardShown())
try
{
_app.Driver.HideKeyboard();

return CommandResponse.SuccessEmptyResponse;
}
catch
{
return CommandResponse.FailedEmptyResponse;
}
return CommandResponse.SuccessEmptyResponse;
}

protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
Expand Down
10 changes: 10 additions & 0 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumMouseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ CommandResponse DoubleClick(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element == null)
{
return CommandResponse.FailedEmptyResponse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Mouse);
var sequence = new ActionSequence(touchDevice, 0);
sequence.AddAction(touchDevice.CreatePointerMove(element, 0, 0, TimeSpan.FromMilliseconds(5)));
Expand Down Expand Up @@ -189,6 +194,11 @@ CommandResponse LongPress(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element == null)
{
return CommandResponse.FailedEmptyResponse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Mouse);
var longPress = new ActionSequence(touchDevice, 0);

Expand Down
17 changes: 16 additions & 1 deletion src/TestUtils/src/UITest.Appium/Actions/AppiumTouchActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ CommandResponse PressDown(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element == null)
{
return CommandResponse.FailedEmptyResponse;
}

// Currently only pen and touch pointer input source types are supported, but this works fine
OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);

Expand Down Expand Up @@ -178,6 +183,11 @@ CommandResponse DoubleTap(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element == null)
{
return CommandResponse.FailedEmptyResponse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var sequence = new ActionSequence(touchDevice, 0);
sequence.AddAction(touchDevice.CreatePointerMove(element, 0, 0, TimeSpan.FromMilliseconds(5)));
Expand Down Expand Up @@ -211,7 +221,12 @@ CommandResponse DoubleTapCoordinates(float x, float y)
CommandResponse TouchAndHold(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);


if (element == null)
{
return CommandResponse.FailedEmptyResponse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var longPress = new ActionSequence(touchDevice, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/TestUtils/src/UITest.Appium/UITest.Appium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="7.0.0" />
<PackageReference Include="Appium.WebDriver" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading