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

test: NetworkTests Improvements #892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
83 changes: 34 additions & 49 deletions test/integration/Android/Device/NetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Appium.Net.Integration.Tests.Android.Device
{
internal class NetworkTests
{
private AppiumDriver _driver;
private AndroidDriver _driver;
private AppiumOptions _androidOptions;

[OneTimeSetUp]
Expand All @@ -25,109 +25,94 @@ public void SetUp()
[OneTimeTearDown]
public void TearDown()
{
if (_driver != null)
{
_driver.Dispose();
}
_driver?.Dispose();
}

[Test]
public void CanToggleDataTest()
{
var androidDriver = (AndroidDriver) _driver;

androidDriver.ToggleData();
ConnectionType currentConnectionType = androidDriver.ConnectionType;
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.WifiOnly));
androidDriver.ToggleData();
currentConnectionType = androidDriver.ConnectionType;
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.AllNetworkOn));
ConnectionType beforeToggle = _driver.ConnectionType;
_driver.ToggleData();
// Toggle data connection and get the new connection type
ConnectionType afterFirstToggle = _driver.ConnectionType;
Assert.That(beforeToggle, Is.Not.EqualTo(afterFirstToggle));
_driver.ToggleData();
// afterSecondToggle stores the connection type after the second toggle to verify it matches the initial state
ConnectionType afterSecondToggle = _driver.ConnectionType;
Assert.That(afterSecondToggle, Is.EqualTo(beforeToggle));
}

[Test]
public void CanToggleAirplaneModeTest()
{
var androidDriver = (AndroidDriver) _driver;

androidDriver.ToggleAirplaneMode();
_driver.ToggleAirplaneMode();

var currentConnectionType = androidDriver.ConnectionType;
var currentConnectionType = _driver.ConnectionType;
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.AirplaneMode));

androidDriver.ToggleAirplaneMode();
_driver.ToggleAirplaneMode();
}

[Test]
public void CanToggleWifiTest()
{
var androidDriver = (AndroidDriver) _driver;
var beforeToggleConnectionType = androidDriver.ConnectionType;
androidDriver.ToggleWifi();
var beforeToggleConnectionType = _driver.ConnectionType;
_driver.ToggleWifi();

var currentConnectionType = androidDriver.ConnectionType;
var currentConnectionType = _driver.ConnectionType;
Assert.That(currentConnectionType, Is.Not.EqualTo(beforeToggleConnectionType));

androidDriver.ToggleWifi();
_driver.ToggleWifi();
}

[Test]
public void CanMakeGsmCallTest()
{
var androidDriver = (AndroidDriver) _driver;

Assert.Multiple(() =>
{
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Call));
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Accept));
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Cancel));
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Hold));
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Call));
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Accept));
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Cancel));
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Hold));
});
}

[Test]
public void CanSetGsmSignalStrengthTest()
{
var androidDriver = (AndroidDriver) _driver;

Assert.Multiple(() =>
{
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.NoneOrUnknown));
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Poor));
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Good));
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Moderate));
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Great));
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.NoneOrUnknown));
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Poor));
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Good));
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Moderate));
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Great));
});
}

[Test]
public void CanSetGsmVoiceStateTest()
{
var androidDriver = (AndroidDriver) _driver;

Assert.Multiple(() =>
{
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.Unregistered));
_driver.SetGsmVoice(GsmVoiceState.Unregistered));
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.Home));
_driver.SetGsmVoice(GsmVoiceState.Home));
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.Roaming));
_driver.SetGsmVoice(GsmVoiceState.Roaming));
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.Denied));
_driver.SetGsmVoice(GsmVoiceState.Denied));
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.Off));
_driver.SetGsmVoice(GsmVoiceState.Off));
Assert.DoesNotThrow(() =>
androidDriver.SetGsmVoice(GsmVoiceState.On));
_driver.SetGsmVoice(GsmVoiceState.On));
}
);
}

[Test]
public void CanSendSmsTest()
{
var androidDriver = (AndroidDriver) _driver;

Assert.DoesNotThrow(() => androidDriver.SendSms("5551234567", "Hey lol"));
Assert.DoesNotThrow(() => _driver.SendSms("5551234567", "Hey lol"));
}
}
}
Loading