Skip to content

Commit 82a9551

Browse files
authoredFeb 9, 2025
test: replace AppiumDriver with AndroidDriver in NetworkTests and simplify method calls (#892)
1 parent a6e7652 commit 82a9551

File tree

1 file changed

+34
-49
lines changed

1 file changed

+34
-49
lines changed
 

‎test/integration/Android/Device/NetworkTests.cs

+34-49
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Appium.Net.Integration.Tests.Android.Device
99
{
1010
internal class NetworkTests
1111
{
12-
private AppiumDriver _driver;
12+
private AndroidDriver _driver;
1313
private AppiumOptions _androidOptions;
1414

1515
[OneTimeSetUp]
@@ -25,109 +25,94 @@ public void SetUp()
2525
[OneTimeTearDown]
2626
public void TearDown()
2727
{
28-
if (_driver != null)
29-
{
30-
_driver.Dispose();
31-
}
28+
_driver?.Dispose();
3229
}
3330

3431
[Test]
3532
public void CanToggleDataTest()
3633
{
37-
var androidDriver = (AndroidDriver) _driver;
38-
39-
androidDriver.ToggleData();
40-
ConnectionType currentConnectionType = androidDriver.ConnectionType;
41-
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.WifiOnly));
42-
androidDriver.ToggleData();
43-
currentConnectionType = androidDriver.ConnectionType;
44-
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.AllNetworkOn));
34+
ConnectionType beforeToggle = _driver.ConnectionType;
35+
_driver.ToggleData();
36+
// Toggle data connection and get the new connection type
37+
ConnectionType afterFirstToggle = _driver.ConnectionType;
38+
Assert.That(beforeToggle, Is.Not.EqualTo(afterFirstToggle));
39+
_driver.ToggleData();
40+
// afterSecondToggle stores the connection type after the second toggle to verify it matches the initial state
41+
ConnectionType afterSecondToggle = _driver.ConnectionType;
42+
Assert.That(afterSecondToggle, Is.EqualTo(beforeToggle));
4543
}
4644

4745
[Test]
4846
public void CanToggleAirplaneModeTest()
4947
{
50-
var androidDriver = (AndroidDriver) _driver;
51-
52-
androidDriver.ToggleAirplaneMode();
48+
_driver.ToggleAirplaneMode();
5349

54-
var currentConnectionType = androidDriver.ConnectionType;
50+
var currentConnectionType = _driver.ConnectionType;
5551
Assert.That(currentConnectionType, Is.EqualTo(ConnectionType.AirplaneMode));
56-
57-
androidDriver.ToggleAirplaneMode();
52+
_driver.ToggleAirplaneMode();
5853
}
5954

6055
[Test]
6156
public void CanToggleWifiTest()
6257
{
63-
var androidDriver = (AndroidDriver) _driver;
64-
var beforeToggleConnectionType = androidDriver.ConnectionType;
65-
androidDriver.ToggleWifi();
58+
var beforeToggleConnectionType = _driver.ConnectionType;
59+
_driver.ToggleWifi();
6660

67-
var currentConnectionType = androidDriver.ConnectionType;
61+
var currentConnectionType = _driver.ConnectionType;
6862
Assert.That(currentConnectionType, Is.Not.EqualTo(beforeToggleConnectionType));
69-
70-
androidDriver.ToggleWifi();
63+
_driver.ToggleWifi();
7164
}
7265

7366
[Test]
7467
public void CanMakeGsmCallTest()
7568
{
76-
var androidDriver = (AndroidDriver) _driver;
77-
7869
Assert.Multiple(() =>
7970
{
80-
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Call));
81-
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Accept));
82-
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Cancel));
83-
Assert.DoesNotThrow(() => androidDriver.MakeGsmCall("5551234567", GsmCallActions.Hold));
71+
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Call));
72+
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Accept));
73+
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Cancel));
74+
Assert.DoesNotThrow(() => _driver.MakeGsmCall("5551234567", GsmCallActions.Hold));
8475
});
8576
}
8677

8778
[Test]
8879
public void CanSetGsmSignalStrengthTest()
8980
{
90-
var androidDriver = (AndroidDriver) _driver;
91-
9281
Assert.Multiple(() =>
9382
{
94-
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.NoneOrUnknown));
95-
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Poor));
96-
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Good));
97-
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Moderate));
98-
Assert.DoesNotThrow(() => androidDriver.SetGsmSignalStrength(GsmSignalStrength.Great));
83+
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.NoneOrUnknown));
84+
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Poor));
85+
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Good));
86+
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Moderate));
87+
Assert.DoesNotThrow(() => _driver.SetGsmSignalStrength(GsmSignalStrength.Great));
9988
});
10089
}
10190

10291
[Test]
10392
public void CanSetGsmVoiceStateTest()
10493
{
105-
var androidDriver = (AndroidDriver) _driver;
106-
10794
Assert.Multiple(() =>
10895
{
10996
Assert.DoesNotThrow(() =>
110-
androidDriver.SetGsmVoice(GsmVoiceState.Unregistered));
97+
_driver.SetGsmVoice(GsmVoiceState.Unregistered));
11198
Assert.DoesNotThrow(() =>
112-
androidDriver.SetGsmVoice(GsmVoiceState.Home));
99+
_driver.SetGsmVoice(GsmVoiceState.Home));
113100
Assert.DoesNotThrow(() =>
114-
androidDriver.SetGsmVoice(GsmVoiceState.Roaming));
101+
_driver.SetGsmVoice(GsmVoiceState.Roaming));
115102
Assert.DoesNotThrow(() =>
116-
androidDriver.SetGsmVoice(GsmVoiceState.Denied));
103+
_driver.SetGsmVoice(GsmVoiceState.Denied));
117104
Assert.DoesNotThrow(() =>
118-
androidDriver.SetGsmVoice(GsmVoiceState.Off));
105+
_driver.SetGsmVoice(GsmVoiceState.Off));
119106
Assert.DoesNotThrow(() =>
120-
androidDriver.SetGsmVoice(GsmVoiceState.On));
107+
_driver.SetGsmVoice(GsmVoiceState.On));
121108
}
122109
);
123110
}
124111

125112
[Test]
126113
public void CanSendSmsTest()
127114
{
128-
var androidDriver = (AndroidDriver) _driver;
129-
130-
Assert.DoesNotThrow(() => androidDriver.SendSms("5551234567", "Hey lol"));
115+
Assert.DoesNotThrow(() => _driver.SendSms("5551234567", "Hey lol"));
131116
}
132117
}
133118
}

0 commit comments

Comments
 (0)