Skip to main content

Posts

Showing posts with the label android

Implementation of Page-Object-Model (POM) to Espresso (Native Android Testing) with Kotlin

What is Espresso Espresso is a native test automation tooling developed by Google for Android UI Tests. Espresso is open-source, very stable, and there are many frameworks that have been developed around Espresso. The  Espresso testing framework , provided by the Android Testing Support Library , provides APIs for writing UI tests to simulate user interactions within a single target app.  It has a full feature-set of Junit that works with Espresso Android Studio provides everything you need It provides white-box testing What Google says about it Page Object Model (POM) The main idea behind the Page Object Model (POM) design pattern, is to create an object repository for the pages in the application, which will then be used in the tests. In other words, instead of including the page elements and the test code together within the test, we separate them into 2 different entities: the pages and the test scenarios. Using this concept, each screen in the application will have a corresp

Bitrise Integrate Browserstack to Run Espresso Tests

Bitrise is one of the best solutions for mobile application development. It gives us many mobile app-related steps to create CI/CD (continuous integration / continuous deployment) pipelines (or workflows as in the Bitrise). Around the mobile application development ecosystem, we have many cloud solutions to make quick and reliable development processes. Browserstack is also one of them, it is widely used in web development and testing but also it also has nice features like 'App Live' and 'App Automate' for mobile app testing. In this post, I want to share how we can integrate Browserstack to Bitrise to run Espresso by directly calling the Browserstack API. Run Espresso on Browserstack via Bitrise If you want to run Espresso tests on a real device then you must build the android project testing so we need to add the ' Android Build for UI Testing ' step then add a script runner to run the Browserstack script. See the workflow: In this example, we are using a scr

Benefits of Using Native Mobile Automation Tooling: Espresso and XCUITest

Testing will be more efficient when testers and developers work in collaboration. Especially when it comes to automated testing, we have many challenging points that should be solved with the help of the other team members. This is a basic explanation of the cross-functional team. For mobile application automated end-to-end testing, this cross-functional team approach can be easily applied by contributing the same code base so native toolings give us this. This can increase the quality of the tests code and the framework by the feedback from the developers, and increase the quality of the tests by the feedback from the testers. In this post, I want to give some idea about the benefits of using native mobile automation toolings such as Espresso and XCUITest. What is Native Tooling Native mobile automation toolings are integrated libraries to the mobile application development framework so that developers can write UI tests for the products under development. Native toolings are part o

Getting the text of elements in Espresso

Espresso is not designed to play with UI objects. When you are considering it in terms of capability for testing, it needs to be improved more. It is not as mature as Android SDK itself so you need to customize somethings to handle your requirements. Even you may need to use other tools like UIAutomator integrated into your test suite. In this post, I want to show how we can handle getting the text of ViewInteraction view.  ViewInteraction view does not have .text function for getting the text of the object since it is designed to interact with the object. Another method which may solve the problem of the assertion is to use the .check for matching the text, as follows: However, this method is not a good way to assert that a certain field text equals a value. For this purpose, we need to get the text of the element and assert it. To get the text of the ViewInteraction element, we need to cast it to TextView with getting the assignable form of it then

How to Set Shared Preferences in Espresso Test for Kotlin and Java

I have experienced Espresso and needed to deep dive into Shared Preferences just because it is one of the main parameters used in the application we developed. As a long search in the online sources but there are some pretty old documents for Espresso with Java and very few documents about Espresso with Kotlin. In this post, I want to share my experiences with setting Shared Preferences with Kotlin and Java and how you can use it in your test design. You can follow up the steps for your test project. Shared Preferences is a way to store user data in local devices so it has been supported since the very early version of Android. Shared Preferences can be stored in the default file or custom file.  Using Default File for Shared Preferences If your application uses the default file it should stores the shared data in the default file provide by Android as in the following path in the device: /data/data/com.package.name/shared_prefs/com.package.name_preferences.xml This

Mobile Application Testing Change Host to Redirect Test Environment

When you need to test the server side development via Mobile application in isolation, you can redirect the host of the API over the hosts file in the emulator. By this way, with the same application that users have, you can test the new development before passing it to live servers. Android Application I have using GenyMotion for emulating android devices. You can edit the hosts file in GenyMotion by the following commands, at the third step you need to change `hosts` file then push it emulator. adb root adb pull /etc/hosts hosts adb remount adb push hosts /system/etc See the example below, the host of the application is www.morhipo.com which is now hitting the test server. The third step is important, if you don't remount new host file can not be push to device . ~ adb root adbd is already running as root ~ adb pull /etc/hosts hosts ~ cat hosts ~ echo "10.1.6.37 www.morhipo.com" > hosts ~ cat hosts 10.1.6.37 www.morhipo.com ~ adb remount remount

Mobile Test Automation: Appium with Python Client

Appium is an open source tool for mobile test automation, you can automate functional test cases for Android and iOS application. As in my some previous posts, I explained Calabash and I just used Ruby for writing test cases because Calabash only supports Ruby and as I know they have plan to support Java. However Appium doesn't have this language constriction. Since it uses Webdriver, it supports the languages which are supported by Webdriver. It means that Java, Objective-C, PHP, Python, C#, Clojure, Perl, JavaScript with Node.js and plus Ruby are supported. You just install the language client you want to test and then write your test cases. Check for the client for your favourite languages from Appium page . Install Appium: npm install -g appium Install Appium Client: npm install wd Install Python Appium Client: pip install Appium-Python-Client Ensure that you have Python installed, recommend to have 2.7 or above: python --version Ensure that you have

Effective Testing: Using LOGCAT for Android Testing

If you tend to use tools effectively, testing is easy and enjoyable. For mobile testing there are lots of challenges and to be honest if you don't push yourself to improve your ability as every developer does you can not test the mobile application good enough. Instead of testing mobile application manually, we can automate the stories whenever the stories are prepared by business analyst with writing cucumber files and then we can start writing the code of automation and finally we can run it when the stories are developed by developer for agile development environment. This is iteration based approach, means you can repeat this steps for each iteration. At the end of the milestone you can run your whole automation code and see the result. For the remaining time you can still test application by using Exploratory Testing techniques to find-out any bugs.  The important point is to make your job effective and efficient. For this you should automate or scripted some repetiti

Fix for Calabash-android Run INSTRUMENTATION_FAILED exception

When you set-up a new android devices or update your .apk file, you may possible get INSTRUMENTATION_FAILED exception: android.util.AndroidException: INSTRUMENTATION_FAILED: com.package.name/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner at com.android.commands.am.Am.runInstrument(Am.java:1093) at com.android.commands.am.Am.onRun(Am.java:371) at com.android.internal.os.BaseCommand.run(BaseCommand.java:47) at com.android.commands.am.Am.main(Am.java:100) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:251) To fix this issue you can follow the instruction below: Create new folder Copy your .apk file into the newly created folder go to your newly created folder and run this command to create calabash-android project calabash-android gen run calabash-android via your new devices calabash-android run latest.apk features ADB_DEVICE_ARG=192.168.56.101:5555 resign .apk

Effective Use of Cucumber with Calabash

BDD, which is stand for behaviour driven development, is created by Dan North . BDD is developed on the top of TDD, which is stand for test driven development to remove the gap of unit testing and acceptance testing. In TDD, every unit is started to be written right after defining the expectations from the units, by the unit testing. However by BDD, regarding the agile story, every unit is specified and tested in terms of desired behaviour. This 'desired behaviour' is what exactly business requires in agile stories.  BDD can be applied by the help of some tools to interpret the business 'desired behaviour' to test code. There are some tools that help this aim such as Behat  for PHP, JBhave  for Java world, and the most famous one Cucumber  for the Ruby world. In this post I want to give some points on how to effectively we can use Cucumber for a Calabash project to automate some agile stories for sample android application. Cucumber takes some keywords lik

Android Test Automation with Cucumber and Calabash

In my previous post I explained the Cucumber Capybara and Calabash and behaviour driven development. In this post I want to explain how we can implement and run cucumber and calabash for automating test cases for android applications. If you have not set-up your environment yet, you can read this post . You should also have an android virtual devices or a real devices that is connected to your computer in debugging mode. Your android version should be higher than 2.2.  If your system is ready for testing, you can clone the repository that I created for mobile test automation purposes. Sure, it may be more sophisticated if a real android developer develop something but from this application you can have a fresh starting. git clone https://github.com/gunesmes/calabash_android_automation.git You can check the images on the github so that get information what the application is looking like. Just open the project file and  look at the two important files in feature directory: cala

Mobile Test Automation: Calabash, Cucumber

Mobile test automation is just another era for test automation since the trends for mobile devices are increasing. For more sophisticated testing approach, we should apply the technics what we have learnt from the test automation for desktop/web applications. As test automation is a part of continuos development, it should be run after each commit to test environment. For mobile application we can use the same method to be more responsible.  Cucumber is used describe the test cases and it very easy to understand for anyone so we can use it for user behaviour as behaviour driven development, BDD . Capybara is a library to simulate user behaviour for just web application. However we can use Calabash for mobile test automation.  It means that we can use Calabash and Cucumber together for mobile test automations. As in Capybara, in Calabash there are not much functions to learn. It has basically, finding element, inserting text into textEdit fields, clicking and assertion function

Eggplant: Mobil Test Otomasyonu İçin Pratik Bİr Araç

Egglant Testing Tools Eggplant GUI (graphic user interface) ve mobil uygulamaların testlerinde kullanılabilecek olduk ç a yararlı bir test otomasyon aracı olarak görülebilir. Ayrıca perfomans testlerinde de kullanılabilme imkanı sunuyor. Kendine has bir dil ğeliştirilmiş ve bu sayede hızlı bir şekilde test scriptleri yazmak mümkün. Test suite üzerinde hiç bir yazılım bilgisi olmaksızın komutları ekleyerek istenilen script kolaylıkla hazırlanabilir. Burada değinilmesi gereken bir başka yenilik ise Image Doctor olarak adlandırılan bir özelliği ile resmi alınan buton veya herhangi bir objenin ekran üzerinde aratılarak buldugunda uygun fonsiyonu yerine getirmesi istenilebilir. Yani test edilen uygulamanın teknolojisi göz ardı edilebilir. Kaydedilen imajları tekrar tekrar farklı test case hazırlanırken kullanılabilir. Bu sayede hız kazanabilirsiniz. Eggplant vs Platform SUT (system under test) test edilecek sistem olarak geçen sistem demektir. Mobil cihazların testleri için