Network conditioning
Mostly, we test a mobile app in a perfect condition of best and fast network; however, in reality the devices might be moving and the network may be fluctuating between Edge connections (2G), 3G, or even LTE. Sometimes, the automation test has to run at a lower data speed or even test some offline functionality.
Appium exposes the driver.setConnection()
method, which can help in setting the network condition between WiFi, airplane, data, or none. Any of the following statements can be used, based on which data connectivity you want to set up:
driver.setConnection(Connection.AIRPLANE); driver.setConnection(Connection.WIFI); driver.setConnection(Connection.DATA); driver.setConnection(Connection.NONE); driver.setConnection(Connection.ALL );
The connection is an enum
that defines these bit masks:
Connection Type | Bit Mask |
| 0 |
| 1 |
| 2 |
| 4 |
| 6 |
Once the value is set, it persists for the life of the driver instance, so we must reset it back to the data connectivity we want...