Testing and Mobile Web testing
In the last three decades, the world of software testing has been developed and advanced to the point where no one has any skepticism about its importance, especially today in the DEV/OPS era, where an application’s change is exposed almost immediately in a production environment. There are many methodologies and tools developed to support this segment, and today you can even find tools that are open source. Still, not all the tools are equal and not all the tools are designed for testing mobile web applications. Thus choosing the right testing tools is a crucial step for the entire project’s success.
The world of mobile web development is characterized by its richness of development frameworks e.g. JQM, ExtJS, Angular etc. So it is very important that your chosen testing tool will be part of this world, moreover it is very important that this testing tool will be able to execute your tests on both environments, the mobile emulator, and the real device.
What is CATJS?
CATJS is an open source automation framework for testing mobile web applications. CATJS executes tests on the real device as well on emulators. CATJS supports popular frameworks like JQM, ExtJS or Angular. For more information about CATJS and for installation instructions please visit http://catjsteam.github.io/ and/or https://github.com/ransnir/catjs-jqm-seed.
The AUT (Application Under Test)
Building The Tests
Let’s analyze the login process (Figure 1).
The user is asked to provide his username and password. If he tries to login-in with an empty username, the login will fail and a message, “Missing Username”, will appear in the message bar. If he fills out the username, but leaves the password empty, the login will fail with “Invalid Username or wrong password” in the message bar. The user will get same response if he will fill out a username and password that do not exist in the system. When using correct credentials, the system will move to the next screen that shows the user’s event list. Now let’s think about testing, sounds simple doesn’t it? We need 3 different tests, one for each scenario.
Test 1: Login attempt with an empty username and password.
Test 2: Login with a username but with an empty password (we should use a name that exists in the system)
Test 3: Login with a username and password that do not exist in the system.
Test 4: Login with a username and password that exist in the system.
As a matter of fact, I can think of about at least 3 other test in addition, but we will stick with these 4 tests for now.
Firstly I would like to start with a quick guide about the CATJS test structure. A CATJS test called a scrap.
It is a comment inside the HTML/JS file (you can see an example in figure 2).
Now after we are done with the short CATJS scrap introduction let’s start designing our test cases. In the below figure you can see a flowchart diagram with the login flow. On the left side you can see a box for each planed test. Our first test is quite simple. In the login screen, we just need to click on the login button without filling up the username or the password. Then we need to verify that the correct message appears.
<!-- @[scrap @@name test_one @@embed true @@jqm setText("#username", ""); @@jqm setText("#password", ""); @@jqm clickButton(“#loginbtn”); @@assert ok($('#message').text()=="Missing username.”,”test one passed”); ]@—>
Let’s see what we have in the above scrap.
On lines 4 and 5 we set the username and the password to an empty string, we use the function setText with the object id as a selector. Immediately after that you can find the clickButton command which will performs a click on the login button. To complete the test the last line is an @@assert command, a verification point that tests if the desired message appears in the message bar.
Bases on the above test we can easily create the other tests.
<!-- @[scrap @@name test_two @@embed true @@jqm setText("#username", "jodoe"); @@jqm setText("#password", ""); @@jqm clickButton(“#loginbtn”); @@log test the login screen with empty password @@assert ok($('#message').text()=="invalid username or wrong password.”,”test two passed”); ]@—>
This time I fill the username field. In addition I also used the @@log command (line 8) which prints a message into the run log.
<!-- @[scrap @@name test_three @@embed true @@jqm setText("#username", "johndoe"); @@jqm setText("#password", "nopass"); @@jqm clickButton("#loginbtn"); @@assert ok($('#message').text()=="invalid username or wrong password.”,”test three passed”); ]@—>
The test populates the username and the password, however the user is not registered in the system thus the login should fail again.
<!-- @[scrap @@name test_four @@embed true @@jqm setText("#username", "admin"); @@jqm setText("#password", "iamadmin"); @@jqm clickButton("#loginbtn"); @@assert ok($.mobile.activePage.attr("id") =="reminders","login/logout success"); ]@—>
In the fourth test, I use the credentials of an existing user, thus the verification point needs to test if the application moved onto the next screen.
Running The Tests
Now all we need is to run the tests. To do so we need to build the CATJS project by running the
following command: catcli -init (see the figure below). Then follow the instructions and complete the configuration.
Now lets move into the newly created folder called cat-project and within this folder lets run the following command catcli —task t@autotest. This command scans the project source code, pickup all the scraps and automatically creates a CATJS scenario.
Let’s build and start the local test server with the following command: catcli -cbs
Within a web browser enter this address: http://localhost:8089.
The test will start running immediately and on the side you can see the test execution progress.