As time goes by, Google’s Android environment continues to grow. As we can observe, new mobile OEMs are being launched in different locations on the globe, with different screen sizes, chipsets, ROM/Firmwares, etc. It’s getting harder for the Android developers to adapt with this fragmentation.
Android and iOS developers are fortunate to have limitless access to some advanced could-based solution, like TestDroid Cloud. They will be able to run automated tests on a large scale for real devices to be assured of its quality. Android developer’s life has now become a little easier because of the rise of the Android testing frameworks.
These are the top 5 Android testing frameworks with example codes:
This only works provided that your Android devices have API level 16 or higher. This does have a disadvantage. Uiautomator doesn’t support webview which means that your Android objects is not accessible directly.
Code Example:
//Public void for the operation public void testSignInAndTweet() throws Exception { // Starting application: getUiDevice().wakeUp(); // Press Home button to ensure we're on homescreen getUiDevice().pressHome(); // Select 'Apps' and click button new UiObject(new UiSelector().description("Apps")).click(); // Select 'Twitter' and click new UiObject(new UiSelector().text("Twitter")).click(); // Locate and select 'Sign in' UiSelector signIn = new UiSelector().text("Sign In"); // If button is available, click UiObject signInButton = new UiObject(signIn); if (signInButton.exists()) { signInButton.click(); // Set the username new UiObject(new UiSelector().className("android.widget.EditText").instance(0)).setText("username"); new UiObject(new UiSelector().className("android.widget.EditText").instance(1)).setText("password"); new UiObject(new UiSelector().className("android.widget.Button"). text("Sign In").instance(0)).click(); // Wait Sign in progress window getUiDevice().waitForWindowUpdate(null, 2000); // Wait for main window getUiDevice().waitForWindowUpdate(null, 30000); } new UiObject(new UiSelector().description("New tweet")).click(); // Typing text for a tweet new UiObject(new UiSelector().className("android.widget.LinearLayout").instance(8)). setText("Awesome #Testdroid!"); // Tweeting! new UiObject(new UiSelector().text("Tweet")).click();
Code example:
<pre>Feature: Login feature Scenario: As a valid user I can log into my app I wait for text "Hello" Then I press view with id "Sign in" Then I enter text "username" into "login_username" Then I enter text "password" into "login_password" Then I wait for activity "HomeTabActivity" Then I press view with id "menu_compose_tweet" Then I enter text "Testdroid" into field with id "edit" Then I press view with id "composer_post"
Code Example:
public void testEspresso() { // Check if view with the text 'Hello.' is shown onView(withText("Hello.")).check(matches(isDisplayed())); // R class ID identifier for 'Sign in' - and click it onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/sign_in", null, null))).perform(click()); // R class ID identifier for entering username onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/login_username", null, null))).perform((typeText("username"))); // R class ID identifier for entering password onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/login_password", null, null))).perform((typeText("password"))); // R class ID identifier for clicking log in onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/login_login", null, null))).perform(click()); // Activate the text field to compose a tweet onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/menu_compose_tweet", null, null))).perform(click()); // Type the tweet onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/edit", null, null))).perform((typeText(”#Testdroid"))); // Tweeting! onView(withId(getInstrumentation().getTargetContext().getResources() .getIdentifier("com.twitter.android:id/composer_post", null, null))).perform(click()); }
This supports Androind through the following:
-uiautomator (API 16 or higher)
-Seledroid (API level lower than 16)
-iOS through UI Automation
-Mobile web Selenium driver for Android and iOS
You can write Appium scripts on using any programming languages such as Objective-C, PHP, Java, Python, Ruby, C#, etc and compatibility across the most important platforms such as Android and iOS. You are given freedom to select tools and to install and configure devices to test and more. For those who are familiar with Selenium, using Appium will probably be easy for you in mobile app test. Appium and Selenium uses the same WEbDriver and DesiredCapabilitites which is used on the same way. In configuring an application to run, Appium and Selenium has a lot of similarities.
Code Example:
# wait for hello sleep(3) textFields = driver.find_elements_by_tag_name('textField') assertEqual(textFields[0].get_attribute("value"), "Hello") # click sign-in button driver.find_elements_by_name('Sign in')[0].click() # find the text fields again, and enter username and password textFields = driver.find_elements_by_tag_name('textField') textFields[0].send_keys("twitter_username") textFields[1].send_keys("passw0rd") # click the Login button (the first button in the view) driver.find_elements_by_tag_name('button')[0].click() # sleep sleep(3) # click the first button with name "Compose" driver.find_elements_by_name('Compose')[0].click() # type in the tweet message driver.find_elements_by_tag_name('textField')[0].send_keys(”#Testdroid is awesome!") # press the Send button driver.find_elements_by_name('Send')[0].click() # exit driver.quit()
Code Example :
// Public void for the operation public void testRecorded() throws Exception { // Wait for the text 'Hello!' to be shown for newbie if (solo.waitForText("Hello!")) { // R class ID identifier for 'Sign in' - and click it solo.clickOnView(solo.findViewById("com.twitter.android.R.id.sign_in")); // R class ID identifier for entering username solo.enterText((EditText) solo.findViewById("com.twitter.android.R.id.login_username"),"username"); // R class ID identifier for entering password solo.enterText((EditText) solo.findViewById("com.twitter.android.R.id.login_password"),"password"); // R class ID identifier for clicking log in solo.clickOnView(solo.findViewById("com.twitter.android.R.id.login_login")); // Wait until log in is done solo.waitForActivity("HomeTabActivity"); } // Activate the text field to compose a tweet solo.clickOnView(solo.findViewById("com.twitter.android.R.id.menu_compose_tweet")); // Type the tweet solo.enterText((EditText) solo.findViewById("com.twitter.android.R.id.edit"), "Testdroid"); // Tweeting! solo.clickOnView(solo.findViewById("com.twitter.android.R.id.composer_post")); }
A recording tool was built using Robotium which is called Testdroid recorder for creating test script. This records every action you take while performing actions on your real device and then converts it to Javascript for any other modifications.
Additionally, you should fully download and use the extension Library which is the – ExtSolo.
These are the following useful tools that haven’t been incorporated in Robotium :
Pros and Cons on the top 5 android testing Frame works
As shown on the image, Appium is good in testing both Android and iOS versions simultaneously. Though, if you are an Android developer that only has Android-version then Robotium is also a good choice. To definitely save time and money in generating test scripts, you can rely on the TestDroid recorder, fyi, it’s free. Therefore we conclude, you should take note about your testing needs whether it is on compatibility testing , Ui testing , functional testing etc. After you take note of everything, you can then now choose the right and the best Android testing Framework for you.
Top 15 Best Android Apps For C Programming | 2018 Exclusive
15 Top PHP Frameworks For Startups | 2019
25 Tips for New Developers: 22 Advice from a (Mostly) Self-Taught Software Engineer
15 Best Free PHP Frameworks
5 Best Resources to Get Started with Android Nougat
Extracting Colors In Android 5.0 – “The Palette API”
Lock Screen Notifications In Android 5.0
Reveal Animation Example Introduced In Android 5.0