"One-Click Build" Automation Testing

Brief:

We created automation test script for web-Portals, Android and iOS apps. Also, we implemented 'OneClick Build' functionality which automatically does the build installation and runs the automation test script by just running one single script file (One-Click)! This reduces the configuration and installation time after which you are all set to start automation test without any other manual action. 

We executed automation test script on all environment(Portal, Android and iOS). You can set the time intervals when you want the script to run using Jenkins tool.

Need:

To reduce the work and time required in manual testing, automation testing is introduced as a better solution. There are multiple automation tools that are available in market like - Selenium, QTP, Appium etc. You all might have faced that the existing functionality breaks due to new functionality/conflict in code due to New changes. We can easily encounter such issues in existing functionality using automation testing.

How It Works:

Portal/Web Application: 

For portal, we used Selenium web driver TestNG framework to automate the testing.
Separate test scripts are created for every module, which are clubbed in one testsuite for testing all modules(using xml).
In 'OneClick Execution', one can create .bat file for windows or .sh file Mac OS. Within .bat and .sh file all automation settings can be configured. For continuous testing .bat should be configured in Jenkins tool where it is executed as per set time or time interval.
We implemented screenshot functionality which captures the screen when script execution on a test script fails. Due to this we easily understand where is the issue in UI.
Reports are generated once the automation test script completes. The reports output is in HTML format.

For Device(iOS and Android):

For devices, we used Appium automation tool.
Here also we implemented 'OneClick Build' functionality.
This again, as discussed above for portal, helps to install application build on device/simulator/emulator automatically and execute the script by just OneClick.
After executing automation script generates test reports. OneClick Build is executed after every application code(Device only) committed on server.

Portal:
Selenium TestSuit:
testSuit.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Project Suite Name" verbose="1" >
<test name="Regression suite 1">
<classes>
<class name="com.ProjectName.demo.ModuleName1"/>
<class name="com.ProjectName.demo.ModuleName2"/>
<class name="com.ProjectName.demo.ModuleName3"/>
</classes>
</test>
</suite>

OnClick Execution File:
 
run.bat
=========================================================================
::|| ASSUMPTIONS ||
::|| 1. JAVA has been installed ||
::|| 2. The 'java' command is a recognized command ||
::|| 3. JAVA_HOME environment variable is set to the correct java directory ||
::|| 4. This run script is located at the ROOT project directory ||
=========================================================================
mkdir bin

dir /s /B *.java > sources.txt

javac -cp lib\* -d bin @sources.txt

java -cp bin;lib\* org.testng.TestNG src\TestSuite.xml

Spring Data

Brief:

It is a data access technology based on spring framework. It can be used for relational as well as non-relational data. Spring data consists of  many sub-projects specific to databases like Spring Data Commons and Spring Data Java Persistence API (JPA). We can create repositories by extending base repositories so that we can directly use the methods to access data for example if we create JPA repository which extends CRUD repository we don't need to write queries for CRUD operations. And for complex queries we can write custom queries.


Need:

For basic CRUD operations and simple queries, developers usually spend a lot of time but using Spring Data we can save that time. Also it will help to write the structural data access code. Using this DAO implementation will be completely removed . Since only the interface methods are needed to be defined to get the needed data from database, the scope for bugs is reduced drastically.
      

How It Works:

The entities will be defined as per the JPA standards annotated entities will be used. We will take example of one entity which uses mongodb collection.
  
    @Document(collection = StateEntity.COLLECTION_NAME)
    public class StateEntity {

        public static final String COLLECTION_NAME = "state";

        public static final String COLUMN_NAME = "name";
        public static final String COLUMN_STATUS = "status";
        public static final String COLUMN_COUNTRY = "country";

        @Id
        private String id;

        @Field(COLUMN_STATUS)
        private Boolean status;

        @Field(COLUMN_NAME)
        private String name;

        @Field(COLUMN_COUNTRY)
        private CountryEntity countryEntity;

        public String getId() {
        return id;
        }

        public void setId(String id) {
        this.id = id;
        }

        public Boolean getStatus() {
        return status;
        }

        public void setStatus(Boolean status) {
        this.status = status;
        }

        public String getName() {
        return name;
        }

        public void setName(String name) {
        this.name = name;
        }

        public CountryEntity getCountryEntity() {
        return countryEntity;
        }

        public void setCountryEntity(CountryEntity countryEntity) {
        this.countryEntity = countryEntity;
        }
  
    }

  
In the above entity we added fields, collection name and id by adding annotations.

Now we will create a simple crud operation using CRUD repository. So we need to create one repository class .
  
    @Repository
    public interface StateRepository extends CrudRepository<StateEntity, Serializable> {
        public StateEntity findById(String id);
        public List<StateEntity> findByStatusIsTrue();
        public List<StateEntity> findByCountryEntityName(String name);

    }

  
This state repository extends CrudRepository and we define some methods.
  
Now we can use the methods directly by creating repository object and pass entities but for removing the dependency of a database from the presentation layer.

We create another layer as service layer in this layer we create CRUD methods and pass them models and in the implementation of a service we create entity object and pass it to repositories which are autowired in service implementation.
  
  
     public interface StateService {
            public void save(StateModel stateModel);
            public void update(StateModel stateModel);
            public StateModel getById(String id);
            public List<StateModel> getAll();
            public void delete(String id);
    }

  
Above class is a interface of StateService so that if we switch to any other database then we will just implement the service as per new database and our other implementation will remain unaffected. Now we will see the implementation.

Note : In the above class StateModel is a class with same entities as StateEntity it is used as DTO.(Data Transfer Object)
  
    @Service
    public class StateServiceImpl implements StateService {

        @Autowired
        private StateRepository stateRepository;
  
        @Override
        public void save(StateModel stateModel) {

            stateRepository.save(StateModel.createEntity(stateModel));

        }

        @Override
        public void update(StateModel stateModel) {

            stateRepository.save(StateModel.createEntity(stateModel));

        }


        @Override
        public StateModel getById(String id) {
            return StateModel.createModel(stateRepository.findById(id));
        }

        @Override
        public List<StateModel> getAll() {
            return StateModel.createListModels(stateRepository.findByStatusIsTrue());
        }


        @Override
        public void delete(String id) {

            StateEntity stateEntity = stateRepository.findById(id);
            if (stateEntity != null) {
                stateEntity.setStatus(false);
                stateRepository.save(stateEntity);
            }

        }

    }
    

Now our implementation is ready for use so following is example for how to use above services.

First we need to add autowired object of StateService.
  
    @Autowired
    private StateService stateService;
  
 For Saving data just call the method of service and pass models.
  
      stateService.save(model);
  
 Same for update and delete just call their methods
  
      stateService.update(model);
  
      stateService.delete(id);
  
 and for get all records call the getAll method
  
      stateService.getAll();
  
Another example is that if you want get record by any column value we can define method in repository directly with column name in it and it will return the record for example if u want to find by First Name then define method in repository as
  
   public StateEntity findByFirstName(String name);
    
It will parse the column name and pass the parameters and give us the record. Also we can write custom queries by implementing the defined methods in repositoryImplclass.
   

Introduction to JavaFx

Brief :

JavaFx8 is a "client UI library for java" promoted by the Oracle Corporation replacing Swing. Currently Swing is popular in developers, but the way JavaFx8 supports porting of Swing applications to JavaFx8 without breaking existing functionalities and enables to use new features of JavaFx as well, so its time to say good bye to Swing. Oracle in its MAJOR release of java version (JAVA8) included javaFx as an integral part of core distribution of java.

JavaFx has been around since 2008, but it got fame when Oracle adopted Sun MicroSystems and started developing JavaFx in new style as a side project. JavaFx8 is emerging rapidly as JAVA is available for all platforms like Windows, Mac OSX, Linux. Everyone who wants to develop all-in-one application for desktop, web and mobile devices can choose JavaFx8 as their first choice. You will surely make up your mind to use JavaFx8 as your GUI designing tool after reading this blog.


Need :

JavaFx8 is a software platform for developing rich internet & desktop applications that are available for use on a single click escaping the hectic installation process. It also enables you to create native bundles for installation.

Self contained application packaging makes it platform independent as application package itself optionally includes the java runtime environment (JRE) and all resources needed within a bundle. So we do not need to worry about whether java environment is available on client machine or not.

You can design hassle free UI without writing a single line of code with the help of Scene Builder. Scene Builder provides drag n drop feature for creating layouts. It creates FXML code in background. FXML is html-like language which keeps user interface separate from business logic.

Developers like me would love to work with JavaFx8 as they can design and customize UI design without writing a business logic. Support of CSS helps to provide elegant look and feel for application.

JavaFx8 is not only good in terms of creating fluid user interfaces but also developers can write pre-business logic with ease and send it to server with the help of API calls. Oracle provides ports for converting JavaFx applications to mobile applications for android and IOS but not yet supported for Windows8 mobiles. At the same time application can be distributed over the web from web browsers without dealing with what kind of browser it is.


JavaFx8 supports 3D effects and animations for creating rich user interface. With JavaFx8 you can enjoy cool features in java8 like Stream API and lambda expressions which drastically improves performance and readability of your application.



How it works :


Main components behind the scene for running JavaFx applications are :

   1) Prism - high performance graphics engine for supporting 2D and 3D graphics.

   2) Glass - It is light weight windowing system called as Glass Windowing Toolkit (GWT). Its main function is to deal with windows, timers and surfaces. It connects javaFx with operating system.

   3) Media engine - It provides cross platform support for media types like audio and video of all formats. Media functionality is further broken down in three separate components:

                                i) "Media" object represent media file

                               ii) "MediaPlayer" responsible for playing media file.

                              iii) "MediaView" displays media in graphical format.

   4) Web engine - It is web browser engine that enables rendering HTML, CSS styling, SVG, DOM, event handling and Javascript support.

                                

How javaFx applications runs :

  •     Application is main class of JavaFx applications. It is must for each javaFx program to extend Application Class.
  •     JavaFx application execution starts from start() method in Application class.
  •     JavaFx application consist of Stage, Scene, Panes and Controls.
  •     Stage is the window for application and Scene the actual visual content of the application.
  •     Panes are different types of layouts for holding controls like TextField, Button etc.

     

Cucumber Introduction

Brief:

Cucumber is a behavior-driven development (BDD) testing tool which programmers use for testing other softwares. It has its own syntax and language for writing the test cases. It is also called as Given-Then-When language. The test cases are written in gherkin language which has its own writing style in which we write multiple test cases for each feature and each feature contains multiple scenario. Usually these features are written by quality analyst QA Engineers.
 
Then these features are given to the test programmers who convert these features and scenarios in steps which are written in specific programming language. Basically cucumber is developed in Ruby but  it exist for popular languages including Java, Java Script, and Python. It is also called as story based testing tool as the test cases are written like stories and in simple native language.

Need:
  
It is very tedious job for programmers to write test cases or for QA's to write automation testing code. To overcome this problem, cucumber is one of the best available solutions so that QA's can write acceptance test cases in their native language in the form of features and scenarios and give it to programmers, programmers will write steps. Also for BDD, it is very convenient it will take less time to write tests. Due to automation we don't need to test at least acceptance test manually again and again. Also the business stakeholders can understand the test cases. We can also include stakeholders in the test process. It bridges developers & non-developers in a team from the requirements perspective.

How It Works:


1 . First thing you have to create a feature file which is in non technical language and it has the feature and scenario for generating feature.
  
       Sample feature file looks like this
     
        LogInTest.feature
      
        @login // this is tag for feature file
        Feature:As a user I want to be able to login into the system
      
        Scenario:
        Given the user is on landing page
        When he provides the user name as user@email.com
        And he provides the password as user123
        And he clicks log-in
        Then he should be logged in

In above sample the user@email.com, user123 are the scenario outlines which will pass to steps as parameter above feature will execute with steps.
      
2 . Second thing you need to create steps for your features that is write programmatic behavior of each scenario in this case we will take example of Java language

        We will write steps for above sample feature file.
      
            public class LogInTest {
  
                WebDriver driver = new FirefoxDriver();

                @Given("^the user is on landing page$")
                public void setup() throws Throwable {
                driver.get("www.landingpage.com/login");
                }

                @And("^he provides the user name as ([^\"]*)$")
                public void he_provides_the_last_name_as(String username) throws Throwable {
                driver.findElement(By.id("useremail")).sendKeys(username);
                }

                @And("^he clicks log-in")
                public void he_clicks_log-in() throws Throwable {
                driver.findElement(By.id("login")).submit();
                }

                @Then("^he should be logged in$")
                public void he_should_be_logged_in() throws Throwable {
                String message = "Log in successful";
                new WebDriverWait(driver, 10).until (ExpectedConditions.visibilityOfElementLocated(By.className("toast toast-success")));
                Assert.assertTrue(message.equals(driver.findElement(By.className("toast-message")).getText()));
                driver.close();
              }
             }
    

3 . Third and the final thing in this  we need one Cucumber test class for executing all the test cases that we have written like following is the class that will execute our log in test.
  
            @RunWith(Cucumber.class)
            @Cucumber.Options(tags ={"@login"},format = "json:target/rest.json")
            public class CucumberTest {
   
            }


Above class will execute the log in feature file and it will give result on console.
      
  

Litmus


Litmus is an online tool (web app) for testing emails and webpages across browsers and email clients. Litmus displays the preview of sent webpages or newsletter in different browsers/clients like Outlook 2013, Gmail, Yahoo mail, Android, iPhone etc.
Go to https://litmus.com/ and click login. 
Once you are successfully logged in, this should be your preview screen.

To start a new test, click New Email Test.
You’ll get a list of email clients to select.  Select the clients on which you want to test the webpages/newsletters. After that, click on start test.

 

When you’ll click Start Test, you will get a popup giving you an email address.  Copy/paste this email into the test email field where you want to test the pages.  After you’ve sent the email, click the ‘Yes. I’ve sent it’ button in the pop up.
It will take some time, but after loading you will see the webpage in all the email clients/browsers you have selected. Click on the one that you want to view.


 

After clicking on a particular page, you will view that webpage in full screen. You can also scroll through that page. If it’s a mobile view you will have buttons to scroll up/down. You’ll have a horizontal scroll bar at the top to navigate through the test clients you have selected or you can use the previous and next buttons. There’s also a check mark and an x button in the top right.  You can use these to select which ones do and don’t pass QA.

Desktop view:




Mobile view:

For mobile view, you will have buttons to scroll up and down




Also you can view thumbnail view after clicking ‘Show client Thumbnail’.

Also, there are few keyboard shortcuts which will help you to view these pages.

After Email preview, you can also check the ‘Subject Line’ view that how the subject is displayed in the entire email environment.



Also, you can test the availability of the Links/Buttons on the page. You can check the number of pass/failed links. 

This is all the testing part, that you can do using Litmus. There is a lot more that you can do.

Boston Byte Grabs a Spot in Clutch’s List of Top Software Developers in Massachusetts

Boston Byte is a collective of highly-skilled and highly-professional developers dedicated to solving your technological ...