This section explains how testing can be done for the offline features both on Android as well as Chrome extension.
Setup Bahmni Connect by following the instructions here
Using Charles tool for network throttling
Charles is a HTTP proxy tool which can be used to intercept the network traffic from the client (Android device or Chrome browser) and the Bahmni server and apply different profiles on it to simulate various network conditions. Though Chrome can be used for network throttling on Chrome browser which helps in testing of Chrome extension, for the purposes of uniformity across Android app and Chrome extension, it is suggested to use Charles for testing. Also, the current version of Chrome does not support network throttling for remote debugging of mobile web views. Please download the tool from http://www.charlesproxy.com/download/.
Usage and configuration
Steps to do on Mac (similar steps apply for Windows) which acts as a proxy
Open Charles tool and go to Proxy menu and select Mac OS X Proxy. This configures proxy settings on Mac. Allow Charles to do if it prompts for permissions.
Go to Proxy menu and select Proxy Settings. Here, in the Proxies tab, Enable transparent HTTP proxying. Leave the port number as 8888 which is the default port on which Charles runs.
Go to Proxy menu and select SSL Proxying Settings. In the SSL Proxying tab, Enable SSL Proxying. Thereafter, add locations for which this proxying has to be enabled. You can either give the IP address of the device for which proxying has to be applied or apply it to all by using wild chars (*:*).
Go to Proxy menu and select Access Control Settings. This is required to authorize the devices to use this proxy. Here, you can give the IP address of the device just to make sure that, you are applying network settings only to the device you want.
Steps to do on Android device
Visit http://charlesproxy.com/getssl from any mobile browser and download and install the certificate. Or, you can go to Help menu in Charles and then select Save Root Certificate. This will bring up a file selector dialog. Save the certificate in an appropriate location. Copy this certificate to the device. Navigate to the location where this certificate is saved on the device and click on it which will trigger installation of certificate.
Configure the proxy ip/hostname and port in the network settings of the chosen network. Note that the ip address is the address of the machine on which Charles is running and port is 8888 by default. (Note: You can modify the network settings by following the steps - Settings App → Network → Long press on the appropriate network name → Modify Network)
Network throttling configuration
The following steps are suggested to do testing with different network presets-
In Charles tool, go to Proxy menu and select Throttle Settings. Enable Throttling and apply this for Only selected hosts.
Add the hosts for which throttling has to be applied.
Either use the already present presets or define your own custom presets. The following configuration is suggested for simulating a not so good 2G cellular network-
Bandwidth of 256 kbps (both upload and download)
Utilisation of 100%
Latency of 300 ms
MTU of 1500 bytes
Reliability of 75%
Stability of 75%
Unstable quality range of 20% to 25%
Similarly other presets can be defined.
For complete offline mode, the bandwidth can be set to 0.
Automation test setup for Chrome app
Basically the existing functional test scenarios will cover most of the bahmni features in web application. For bahmni to support offline usage we have android app and chrome extension. We made changes to automate the test set up for chrome extension.
Existing functional tests uses Firefox web driver to run test scenarios, we don’t have chrome support built in our functional tests, therefore we added offline_spec_helper.rb which actually instantiates the chrome driver and loads the chrome extension in the the chrome instance.
1) We have separate set of functional tests for offline scenarios . They are in the offline package under specs directory.
2) To run these specific specs we should know whether it is offline scenarios or not, so that we can load specific selenium web driver i.e. if the scenarios are offline then we will use chrome driver, otherwise we will use the default firefox web driver.
3) We installed a go-agent and chrome driver on a ubuntu machine which will run the functional tests by loading the extension. Specifically ubuntu machine because, we can’t find some dependency for chrome driver in CentOS. We have chosen chrome driver because functional tests are running against chromium app.
4) To run the functional test in headless mode you need to install Xvfb(X virtual frame buffer,Xvfb performs all graphical operations in memory without showing any screen output)
sudo apt-get install xvfb
5) We need a server which is a bahmni instance, from which the data has to sync to the Bahmni Connect (chrome app), and Bahmni can’t be setup on Ubuntu box, we have to have taken another plain CentOS VM, and installed bahmni on it. To setup bahmni on plain CentOS VM follow the following documentation.