Automotion – simple solution for complicated problems

Automotion – simple solution for complicated problems

In this article I decided review simple Java library for automation testing that is successfully implemented already for many different projects.

So, let’s start.

What are the main problems that we have when we want to start automation testing on a new project? Usually there are:

  1. Which technologies to choose? Java, Python, C#, Ruby or maybe try with JavaScript? Yeah, each of technologies has benefits and limitations. And usually we don’t know what we will need in the future.
  2. What kind of application do we want to test? Mobile or Web or maybe Mobile-Web? Maybe we will require to test RESTful services or mail services?
  3. Need to write many validators from scratch. Need to organise the structure of capabilities, drivers, getters and setters for configurations.

googley-eye-birdie-has-questions

So, I decided that need to write something that will help me to avoid such questions in the future. This “something” must be universal framework that can be easy connected to each project.

Now Automotion library is available on GitHub here

The main most useful functions that available in Automotion are:

  1. Super easy method for connection of WebDriver to the maven project. Support for Remote Web Driver and Appium Driver as well. Also it allows to run the tests in mobile simulation Chrome mode. You can update Your capabilities in the way You want. Also here is implemented methods for connection with SauceLabs.
  2. Powerful feature for performing HTTP(s) requests with attachments, authorisation, etc.
  3. Functions that allow to perform connection to IMAP mail services and verify mailboxes.
  4. Functions that allow to identify which of the languages are on the web and mobile pages. Support up to 70 languages.
  5. Smart text finder that allows to find even broken text. For example, You need to find the phrase “Try Again”, but You have recognised text like ” gh try gh 6%^7 hjgasd 7^& dfg!44d T@y GaIN#%hjk in”. People are able to find something similar to “Try Again”. It’s “T@y GaIN”. But machine cannot find it. So, this algorithm allows to find such phrases.
  6. Lots of useful helpers for the web and mobile automation testing:
    • Different variations of scrolling and swiping for iOS, Android and Web
    • Function that allow to hide keyboard on Android and iOS devices
    • Different smart functions for clicking on the web or mobile elements. For example, if You need to click on the right top corner of element
    • Functions for manipulating of network and settings on Android devices
  7. Smart functions for validation that elements on the page are aligned correctly. These functions are super useful for the validation of UI, especially header, footer and different static content.

All these functions could easy cover the most complicated cases in automation testing. With Automotion You don’t need anymore to look for the solutions. Everything is ready.

If You’re interesting to know more about Automotion library – feel free to contact with me directly. My email is available on the page About Me. Also, if You know another cases that could be added to Automotion – let me know or feel free to contribute on Github.

Thank You for reading this article and have a good automation!

10 tips and tricks in usage of Appium with iOS and Python

10 tips and tricks in usage of Appium with iOS and Python

Here is collected the list of tips and tricks how to solve some issue during automation of mobile iOS app with Appium.

1. Hide keyboard. It’s a simple method that easy work for Android but not so easy for iOS. So, the ways how to hide keyboard for iOS devices:

– self.driver.hide_keyboard(‘return’) – for iPhone will simulate the clicking on Return button. But sometimes this method is not hiding the keyboard but just switching to another text fields.

– Also for iPhone possible to simulate quick swipe from the middle of the screen to the bottom. I will close keyboard. This method work for 95% of cases.

– For iPad need to tap by coordinates on the bottom right side of the screen (minus 30 pixels for height and width).

2. How to send some keys without using of the known methods like set_value or send_keys using UI Automation calls? You need to click on the TextField to open a keyboard and then execute:

– self.driver.execute_script(

‘var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.setInterKeyDelay(0.1);vKeyboard.typeString(“some string”);’

)

3. How to set the date in the PickerWheel. You don’t need to swipe nothing. Just take the location of the correct PickerWheel and perform the method send_keys(‘value’) to this Picker element. After setting the date to this element – question: how to close it? Just click somewhere on the screen (not on the Picker).

4. Everybody knows that method send_keys() works very slow. So, You need to use method set_value(). It will set the value of Text Field immediately. Or, You can use trick from the list-item #2, just set keyDelay very short.

5. How to verify 10 elements on the page (let’s say just simple static text or labels)? Usually  – we call find_element_by_..() for each of elements. But it will perform the call to Appium server, getting XML for each element. It’s very long. So, You need to grab the page source using self.driver.page_source and look for each element in the already received XML document.

6. How not to fight with popup on iOS app. Usually popups are very painful question. Especially – how to close them if it’s unpredictable. If You don’t need to to verify the text on popup or something like this – You need to add the next capabilities:

‘autoAcceptAlerts’: True, ‘acceptAllAlerts’: True

7. But how to deal with popup if You don’t want to close everything automatically? You need to wrap such 2 methods:

self.driver.switch_to_alert().accept()
self.event.accept_alert()

The accepting of alerts is very unstable, so be ready to wrap it into try-except block.

8. How to handle some of alerts using direct call to UI Automation:

self.driver.execute_script(‘var target = UIATarget.localTarget();’)
self.driver.execute_script(‘target.frontMostApp().alert().cancelButton().tap();’)

9. How to minimise the time of searching elements for Your framework? For Android everything is obviously – need to use ID. But what to do with iOS. The better way to decrease the time of element’s searching is the using of accurate xpaths. It’s not very clear from the perspective of  clean code, but it’s faster. So, if You don’t care about quality but about speed use the full xpaths (e.g. //UIAApplication[1]/UIAWindow[1]/…)

10. How to use the last version of Appium every time? You need to pull the Appium code from GitHub, run the reset.sh file to build it and enable in the Developer Settings of Appium. Now You have the latest version of Appium.

 

How to extend the battery life on iPhone up to 3 days

How to extend the battery life on iPhone up to 3 days

Samsung-battery-life.

One of the most painful questions for smartphone’s users is  – how to extend the battery life? How to keep the smartphone alive without charging at least 2-3 days? Is it possible at all?
The answer is – Yes, it’s possible. I re-charge my iPhone every 3-4 days. And You can find several tricks how to do it.
I don’t want to iterate through all the battery-killer applications. And I don’t want to highlight well known tips like brightness, usage, etc.

1. Mail Client. 

Usually people have few mail boxes connected to their iPhone. And all the mail boxes are configured to fetch the data automatically each 30 mins. This is main battery killer.
What You can do? I suggest to leave the auto fetching of the mails for the only one of the most important mailbox. Only this trick allows You to extend You battery life for 6-7 hours (tested on my own iPhone)

2. Usage of 4G/LTE.

I’m sure that most of the users have configured the usage of LTE by default. But what happens when the cellular signal is low and not enough for LTE? iPhone uses 3G but also it tries to connect to 4G. And these attempts require the fortification of signal and as result battery usage. My suggestion is to use 3G (sometimes even 2G) mode during the problem with network.

3. Sorry, Facebook, but yes.

The Facebook application is battery killer. I suggest to use the web version of Facebook with Safari. You’ll see that You can save at least 5-6 hours of Your battery life. I know that it could be not very comfortable, especially if You used to use the Facebook authentication for another applications.

4.  Turn Off the usage of applications in background mode.

I was testing the usage of iPhone with turned on and turned off the function of background app usage. And to be honest – I didn’t find any difference except only one – I saved around 4 hours of the battery life.
How to do it: go to Settings -> General -> Background App Refresh and uncheck this feature.

5. Usage of location services (GPS).

When do You need the location services to be turned on? Usually only during the usage of maps or another applications. So, it’s better to turn off the usage of location services in background mode almost for all the applications except applications for tracking of outdoor activity.

How to do it: go to Settings -> Privacy -> Location Services and then need to go through the list of apps and turn off where it’s not required.

6. Human factor. Habit of clicking something in the every free second.

Unfortunately, this “feature” is most difficult to eliminate. But I suggest to try it at least for experiment. You will find that 5 hours of the battery life will be saved.

I’ll be very glad to read some feedbacks about these tips and tricks if it was helpful.

Thanks.

“Specification by Example” in example. Java, Selenium, Concordion, Junit, Maven.

Hello!
In this article I will try to explain, how to use approach “Specification by Example” on real project. What tool and framework You need for this. This example will include part of real automation testing framework (ATF) for testing of Web UI application. ATF is based on Java, JUnit, Maven, Selenium and Concordion.

Ok, so what You need to know to start with thing like this? First of all it’s good to have some practice with Java, JUnit and automation Web UI testing (I mean Selenium). If You know everything of it and if You know what is Page Object pattern – let’s imagine, that You have ready ATF based on Java, Selenium and start with implementing of Concordion into this ATF. This examples shows a real example of creation new item on Atlassian’s Jira test project.

Let’s do everything step by step.

Step 1.

Add dependency in pom.xml

<dependency>
    <groupId>org.concordion</groupId>
    <artifactId>concordion</artifactId>
    <version>1.4.7</version>
</dependency>

Step 2.

Need to configure pom.xml correctly for using correct folders and making of correct output reports. Add next section to Your pom.xml file:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-specs-source</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/src/test/specs</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-resource</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-resource</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/test/specs</directory>
                                <includes>
                                    <include>**/*.html</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
                <systemProperties>
                    <property>
                        <name>concordion.output.dir</name>
                        <value>target/specs</value>
                    </property>
                </systemProperties>
            </configuration>
            <executions>
                <execution>
                    <id>behavior-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <testSourceDirectory>src/test/java</testSourceDirectory>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/*Fixture.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Step 3.

From previous step You see, that out *.html example will be stored in /src/test/specs. So, create in Your project under /src/test folder specs. And create in this folder an empty HTML file. It will be our specification. Put next data into HTML file:

<html xmlns:concordion="http://www.concordion.org/2007/concordion">
    <head lang="en">
        <meta charset="UTF-8"/>
</head>
    <body>
        <h2>Test - create new issue and verify that it's created successfully</h2>
        <p>Given username</p>
         <span concordion:set="#username">denys.zaiats@gmail.com</span>
        <p>Given password</p>       
         <span concordion:set="#password">dzaiats2015</span>       
         <p concordion:execute="performLogin(#username, #password)">Step 1. Perform login</p>       
        <p>Summary: </p>
         <span concordion:set="#summary">New issue created by automated test</span>        
        <p>Description: </p>
         <span concordion:set="#description">Issue description</span>       
        <p>Priority: </p>
         <span concordion:set="#priority">Major</span>
         <p concordion:execute="createNewIssue(#summary, #description, #priority)">
            Step 2. Create new issue
         </p>     
         <p concordion:assertTrue="isIssueCreated()">Step 3. Assert - new issue is created</p>
    </body>
</html>

As You see – You need to use Concordion schema for using of concordion’s attributes. There are next most used concordion attributes which You can use:

  • concordion:assertEquals
  • concordion:assertTrue
  • concordion:set
  • concordion:execute
  • concordion:run
  • concordion:execute on a <table>
  • concordion:execute on a <list>
  • concordion:verifyRows

You can set parameters which You want to pass in methods. You can just execute method if You want to perform any void method. More information about using of this You can find here

Step 4.

Need to create correct java test with ConcordionRunner. Here is presented an example of it:

@RunWith(ConcordionRunner.class)
public class CreateNewIssueSuccessfullyTest extends TestBase{

    public void performLogin(String username, String password){
        LoginPage loginPage = home.loginPage();
        loginPage.login(username, password);
    }

    public void createNewIssue(String summary, String description, String priority){
        home.createNewIssue(summary, description, priority);
    }

    public boolean isIssueCreated(){
        return home.isNewIssueCreated();
    }
}

Step 5.

If You did everything correctly – You should be able to clean and install project without problem with using of Maven. After successful test run new report-file will appear in folder /target/specs/

What the benefits of using this approach? The answer is obviously. You have good readable living documentations which are the part of tests. And business logic is represented not only in the code, but also in readable view for non-technical stuff.

A bit later I will post a link to live example with source code of this implementation. If You have any question – just send me e-mail to itarray.net@gmail.com

Thanks for reading my articles.
Cheers.

Agile testing

Agile testing

If You want to start with agile testing on Your project – firstly You need to forget that You’re only QA/QC. In agile testing You are agile software development engineer which is involved in development processes from test perspective.
It’s very interesting – what are real responsibilities of agile tester?
Let’s think about usual responsibilities of testers on the project. Tester need to write test documentation, tester need to test application and report a bugs, tester need to prepare release documentation about defects, test process, etc.

But maybe it’s possible to avoid unwanted bugs? No – it’s impossible. But possible to reduce amount of the bugs. How to do it?
First of all – tester need start to think not only on the level of acceptance user. Try to think on unit level of application, on component and integration level. Try to think about behaviour of relationship between component.

Yes, I’m talking about TDD and BDD approaches. For this You need to know another agile testing approaches which are very useful and are required.

Test pyramid

idealautomatedtestingpyramid

As a agile tester You need to make test coverage on Your test application like it’s on image above. If You want to avoid long time verification during GUI testing, UAP testing – try to cover Your application by tests on unit and integration levels. This approach will help You to avoid the verification of a lot of cases on GUI level. This is ideal model.

Another approaches – Agile testing Quadrants (image is taken from http://lisacrispin.com/)

Agile-Testing-Quadrants

Important to divide You project for 4 Quadrants. Each of these quadrants covers another side of the project. You need to remember about importance of Automation testing on the project. Automation testing – it’s not only coverage of application on GUI level. It’s coverage by Unit tests, Behaviour tests.
Each of these quadrants also has priority. I will try to explain more about Agile testing quadrants in the next articles.

Let’s go next.

TDD and BDD

What is TDD (Test-driven development) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards (From Wikipedia).

16728

It’s mean that agile tester should really know development process.
What the tools are useful – all the unit-test framework. (JUnit, NUnit, TestNG etc.). It’s depend on platform where You’re working.

But what if You need to join all the created functions? You need to create some real behaviour scenarios and test it too. You need to think from business perspective and from test perspective on development level.
In this case it’s time to bethink about ATDD.
ATDD (Acceptance test-driven development) 
is a development methodology based on communication between the business customers, the developers, and the testers. ATDD encompasses many of the same practices as Specification by Example, Behaviour Driven Development (BDD), Example-Driven Development (EDD), and Story Test-Driven Development (SDD). All these processes aid developers and testers in understanding the customer’s needs prior to implementation and allow customers to be able to converse in their own domain language. ATDD is closely related to Test-Driven Development[TDD]. It differs by the emphasis on developer-tester-business customer collaboration. ATDD encompasses acceptance testing, but highlights writing acceptance tests before developers begin coding. (from Wikipedia)

The most popular practices is BDD. You can describe Your test story in human-readable text or html file and implement it in the code. This is very useful if You want to collect You test documentation and code in one place. It’s called Living documentation.
The most popular tools are JBehave, Cucumber, Concordion.

So, as You see – agile tester it’s a bit different tester from non-agile, because agile tester need to be able with developers on the same code. Don’t scare to use these approaches and practices on Your project. You will see benefits after some times. It will help to save the time of test execution.

Best regards,

Denys