Or press ESC to close.

Simulating Network Disconnections: Airplane Mode in Mobile App Testing

Mar 10th 2024 6 min read
easy
mobile
appium2.0.1
javascriptES6
webdriverio8.33.1

In mobile app testing, simulating network disconnections is crucial for ensuring our app's resilience and proper behavior under various network conditions. This blog post explores the method of simulating network disconnections using Airplane Mode, providing insights into its functionalities, use cases, and code examples for implementation.

Airplane Mode: A Simple Yet Effective Approach

Airplane Mode offers a straightforward way to disconnect our device from all wireless networks (Wi-Fi, cellular data, Bluetooth). While convenient, it might be considered too broad for testing specific network scenarios. Despite its simplicity, this approach offers a basic disconnection scenario, lacking the fine-grained control over network behavior, such as delays or specific error codes.

To illustrate, the following code showcases how to enable and disable Airplane Mode using WebdriverIO and Appium, along with an explanation of the network connection codes and their meanings:

                                     
it("Airplane Mode Test", async () => {
    const companyName = await page.getCompanyName();
    const companyRepositories = await page.getCompanyRepositories();
    expect(companyName).toEqual("Company name: Meta");
    expect(companyRepositories).toEqual("Public repositories: 135");
                        
    await driver.setNetworkConnection(1); // airplane mode on, wifi off, data off
    await page.tapReloadButton();
                        
    const noCompanyName = await page.getCompanyName();
    const noCompanyRepositories = await page.getCompanyRepositories();
    expect(noCompanyName).toEqual("Company name: Error");
    expect(noCompanyRepositories).toEqual("Public repositories: Error");
});
                    

This code simulates Airplane Mode by setting the network connection type to 1 (airplane mode on) using driver.setNetworkConnection(1). The test retrieves initial data (company name and repository count) with the network enabled. Then, it simulates Airplane Mode and attempts to refresh the data. Since the network is disconnected, the app should display error messages, which are verified in the assertions.

Here is the list of all codes with their meanings:

0 -> airplane mode off, wifi off, data off
1 -> airplane mode on, wifi off, data off
2 -> airplane mode off, wifi on, data off
4 -> airplane mode off, wifi off, data on
6 -> airplane mode off, wifi on, data on

Note: This approach offers a basic disconnection scenario. It doesn't allow for fine-grained control over network behavior like delays or specific error codes.

Choosing the Right Network Simulation

While Airplane Mode provides a convenient means to simulate network disconnections, there are situations where alternative network simulation codes may be better suited for our testing needs. Understanding the distinct scenarios for each code can help us tailor our testing strategy to more accurately reflect real-world conditions. Here's a breakdown of when specific codes might be preferable over Airplane Mode:

1. Code 2 (Airplane Mode off, Wi-Fi on, Data off): Optimizing for Wi-Fi Scenarios

When our app relies heavily on Wi-Fi connectivity, using Code 2 allows us to isolate the impact of Wi-Fi interruptions without disrupting cellular data. This is beneficial when we want to specifically test how our application behaves when transitioning between different Wi-Fi networks or when dealing with intermittent Wi-Fi connections.

2. Code 4 (Airplane Mode off, Wi-Fi off, Data on): Emphasizing Cellular Data Performance

In scenarios where cellular data is the primary mode of connection, Code 4 becomes valuable. By enabling cellular data while keeping Wi-Fi off, we can evaluate how well our app performs under different data speed conditions or when transitioning between various cellular network types.

3. Code 6 (Airplane Mode off, Wi-Fi on, Data on): Comprehensive Network Testing

For a more holistic approach to network testing, Code 6 provides a combination of both Wi-Fi and cellular data. This code allows us to mimic scenarios where users seamlessly switch between different network types, providing insights into our app's adaptability and resilience in diverse network environments.

Choosing the Right Code: Considerations for Realistic Testing

When deciding on the appropriate network simulation code, it's essential to align our choice with the typical usage patterns of our app's target audience. Consider factors such as geographic locations, prevalent network types, and user behaviors to ensure that your testing scenarios mirror real-world conditions.

Moreover, keep in mind that Airplane Mode, while broad, may not cover all the intricacies of network behavior that your app might encounter. Utilizing specific codes allows for more targeted testing, providing a nuanced understanding of how an application performs under various network conditions.

Exploring Alternatives: The Role of Proxies in Network Simulation

While Airplane Mode serves as a straightforward method for disconnecting our device from all wireless networks, there are instances where alternative approaches, like network proxies, prove advantageous. Network proxies offer a more sophisticated and granular control over network conditions, providing several compelling reasons to consider them:

While Airplane Mode remains a useful tool for basic disconnection scenarios, the sophistication and control offered by network proxies make them a valuable addition to our testing toolkit. By incorporating proxies into our testing strategy, we can ensure a more nuanced and realistic evaluation of our mobile application's performance under diverse network conditions.

Conclusion

Simulating network disconnections is a crucial aspect of mobile app testing. While Airplane Mode offers a simple approach to achieve this, it provides a broad disconnection, lacking control over specific network behaviors. We explored alternative network simulation codes that enable targeted testing based on Wi-Fi or cellular data usage. Understanding these codes and their applications empowers us to tailor our testing strategy to reflect real-world network scenarios encountered by our target audience.

Proxies surpass Airplane Mode's capabilities by offering fine-grained control over network conditions, advanced delay and modification functionalities, comprehensive testing environments, and real-time monitoring and analysis. Integrating network proxies into our testing strategy arms us with a more powerful and nuanced approach to evaluating mobile app performance under diverse network conditions.

Through the strategic utilization of network simulation codes and the capabilities offered by network proxies, we can guarantee the resilience, adaptability, and delivery of an exceptional user experience in our mobile applications, irrespective of the network environment.

The code example mentioned in this blog post, along with a test Android app, is available on our GitHub repository. Feel free to try it out!