Before we start, please download the latest version of Testdroid Recorder and install it in Eclipse. Here you will find instruction how to do it. Restart your IDE and start testing your application.
We will use Instagram application as an example to show how to use Testdroid Recorder and how it works with market applications. Let’s start :)

Login action

First screen in the application is login screen. We propose to do login action in different testcase and then we can simply manipulate order of testcases. We ran Testdroid Recorder, chose Instagram apk and recorded all clicks. Testcase class was really good but we should polish something. One thing that normally needs some optimization is sleep times.

When you are recording your tests, Recorder automatically records also wait times.

[sourcecode language="java"]
solo.sleep(500); //this is automatically added by Recorder
solo.clickOnView(extSolo
.findViewById("com.instagram.android.R.id.toolbar_button_login"));
solo.sleep(2000); //this is automatically added by Recorder
solo.clearEditText(0);
[/sourcecode]

Settings of the application

If you change something in applications settings, the settings are set for all testcases. So please be aware of it.  You can edit your test class and check if current item is active/selected/chosen and then decide to click on it or not. We also propose to do it in different testcase or test method.

[sourcecode language="java"]
CheckBox box = (CheckBox) extSolo
.findViewById("com.instagram.android.R.id.row_camera_settings_checkbox");
if (box!=null & !box.isChecked()) { //get a state of the camera settings
solo.clickOnView(extSolo
.findViewById("com.instagram.android.R.id.row_camera_settings_checkbox"));
solo.sleep(3000);
solo.clickOnView(extSolo
.findViewById("com.instagram.android.R.id.button1"));
solo.sleep(3000);
}[/sourcecode]

Dynamic Data

There isn't yet a perfect solution for handling the dynamically loaded data (like pics from the server). A simple solution is to set sleep() with 5-10 seconds and then try to click on downloaded item. We are working on a feature in Testdroid Recorder to make the handling of dynamic data more sophisticated and hopefully it will be available as one of the new features in the next release.

Quick tips how to improve testcases which are accessing dynamic data:

1. If current activity fetches data from server, you should use wait (solo.waitForxxx() -functions) and/or sleep() at least 5 second to manage the differences in device performance and network latency .

[sourcecode language="java"]
// Search for text
if(!solo.waitForText("Testdroid", 1, 30000)) { //wait until text: "Testdroid" is available (30sesc timeout)
solo.assertCurrentActivity(TAG, "Could not find Testdroid");
}
[/sourcecode]
2. After takeScreenshot() we strongly suggest to add sleep(1000). This way you can get a proper screen shots from slower devices too.
[sourcecode language="java"]
extSolo.takeScreenshot("com.instagram.android.testSendPhotoWithGeoLocation_scr_1");
solo.sleep(1000);
[/sourcecode]
3. If waitForActivity() has a problem with your application (never ending loop) please use sleep() with 2-5 seconds sleep time. We are working on a more elegant solution to solve this problem as well.

4. If your application uses camera intent, share intent or other activities outside your application, please remember that those cannot be automated as part of same test suite due to limitations in Android Instrumentation framework (instrumentation has no rights for other processes than its own).

5. At the end you should choose proper order for your testcases. Create a Test Suite and add all tests in required order.
[sourcecode language="java"]
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(Login.class);
suite.addTestSuite(Test1Twitter.class);
[/sourcecode]

In the next post we will show how the tests work in Testdroid Cloud.

"/>

Instagram test cases created with Testdroid Recorder

Bitbar, the mobile devops company. Logo, large

Before we start, please download the latest version of Testdroid Recorder and install it in Eclipse. Here you will find instruction how to do it. Restart your IDE and start testing your application.
We will use Instagram application as an example to show how to use Testdroid Recorder and how it works with market applications. Let’s start 🙂

Login action

First screen in the application is login screen. We propose to do login action in different testcase and then we can simply manipulate order of testcases. We ran Testdroid Recorder, chose Instagram apk and recorded all clicks. Testcase class was really good but we should polish something. One thing that normally needs some optimization is sleep times.

When you are recording your tests, Recorder automatically records also wait times.

[sourcecode language=”java”]
solo.sleep(500); //this is automatically added by Recorder
solo.clickOnView(extSolo
.findViewById(“com.instagram.android.R.id.toolbar_button_login”));
solo.sleep(2000); //this is automatically added by Recorder
solo.clearEditText(0);
[/sourcecode]

Settings of the application

If you change something in applications settings, the settings are set for all testcases. So please be aware of it.  You can edit your test class and check if current item is active/selected/chosen and then decide to click on it or not. We also propose to do it in different testcase or test method.

[sourcecode language=”java”]
CheckBox box = (CheckBox) extSolo
.findViewById(“com.instagram.android.R.id.row_camera_settings_checkbox”);
if (box!=null & !box.isChecked()) { //get a state of the camera settings
solo.clickOnView(extSolo
.findViewById(“com.instagram.android.R.id.row_camera_settings_checkbox”));
solo.sleep(3000);
solo.clickOnView(extSolo
.findViewById(“com.instagram.android.R.id.button1”));
solo.sleep(3000);
}[/sourcecode]

Dynamic Data

There isn’t yet a perfect solution for handling the dynamically loaded data (like pics from the server). A simple solution is to set sleep() with 5-10 seconds and then try to click on downloaded item. We are working on a feature in Testdroid Recorder to make the handling of dynamic data more sophisticated and hopefully it will be available as one of the new features in the next release.

Quick tips how to improve testcases which are accessing dynamic data:

1. If current activity fetches data from server, you should use wait (solo.waitForxxx() -functions) and/or sleep() at least 5 second to manage the differences in device performance and network latency .

[sourcecode language=”java”]
// Search for text
if(!solo.waitForText(“Testdroid”, 1, 30000)) { //wait until text: “Testdroid” is available (30sesc timeout)
solo.assertCurrentActivity(TAG, “Could not find Testdroid”);
}
[/sourcecode]
2. After takeScreenshot() we strongly suggest to add sleep(1000). This way you can get a proper screen shots from slower devices too.
[sourcecode language=”java”]
extSolo.takeScreenshot(“com.instagram.android.testSendPhotoWithGeoLocation_scr_1”);
solo.sleep(1000);
[/sourcecode]
3. If waitForActivity() has a problem with your application (never ending loop) please use sleep() with 2-5 seconds sleep time. We are working on a more elegant solution to solve this problem as well.

4. If your application uses camera intent, share intent or other activities outside your application, please remember that those cannot be automated as part of same test suite due to limitations in Android Instrumentation framework (instrumentation has no rights for other processes than its own).

5. At the end you should choose proper order for your testcases. Create a Test Suite and add all tests in required order.
[sourcecode language=”java”]
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(Login.class);
suite.addTestSuite(Test1Twitter.class);
[/sourcecode]

In the next post we will show how the tests work in Testdroid Cloud.


Calabash 101: Basics, Getting Started and Advanced Tips

Go through the basics of Calabash, how to create proper Calabash tests and how to make the most of them.

Download

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close