Archive

Archive for July, 2015

Pros and Cons of Robotium

Hi guys, I am writing just a summary about Robotium, because maybe I will start to work with it. So, if you have any tips or suggestion, please feel free to comment here.

Robotium is a popular Android automation framework for testing native and hybrid Android apps using the black box method. Licensed under an Apache 2.0 license and first released in 2010.

To use Robotium, you need either the source code or apk file for the app, Eclipse for building a test project, ADT (Android Development Tools), SDK (Software Development Kit), JDK (Java Development Kit), and the Robotium.jar file.

Benefits:
• You can develop powerful test cases, with minimal knowledge of the application under test.
• Allows user to test more flexible and convenient for analyzing results.
• Robotium allows us to take screenshots anywhere in the test (both for Emulator and Device) and save it to device internal memory or SD Card or Emulator
• The framework handles multiple Android activities automatically.
• Minimal time needed to write solid test cases.
• Readability of test cases is greatly improved, compared to standard instrumentation tests.
• Test cases are more robust due to the run-time binding to GUI components.
• Blazing fast test case execution.
• Automatic timing and delays.

Limitations of Robotium:
• Tied to JUnit 3 Instrumentation on device.
• Tied to one app process.
• It can’t work with different Applications in on test – if your application call another one (like Camera) – Robotium can’t “see” it and press any buttons there.

Parallel tests:

I’ve found this API: https://github.com/square/spoon, but I believe that we can configure parallel tests with Jenkins too.

 

Thank you guys ! See you next week 🙂

 

Sources:

https://saucelabs.com/resources/articles/open-source-tools-robotium-android-appium

https://code.google.com/p/robotium/

https://www.linkedin.com/grp/post/3769150-5852687643892002817

http://blog.mobinius.com/robotium-best-testing-framework-for-android/

Third script with Velocity (VM)

Hi guys, I’ve been busy this week, for this reason I am posting today not Wednesday as I am used to post. Ok, So I will finish the examples with vm scripts in this post.

I’ve updated the last script and the template with another stuff that you can do with vm template. So, as you can see, you can write Java code inside the template. Like, if you want a template which it will share some parts of another template, you can put a condition and then you will be reducing the number of the templates.

– You can keep the getters and setters from Customer.Class

– You will need modify CostumerSearch: Add the petlist (New value which we are sending) and create the hashmap with different values

package test;
import org.apache.velocity.Template;
import java.io.StringWriter;
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Map;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;
import test.Customer;

public class CustomerSearch  {
    
    public static void main(String[] args) throws Exception { 

     CustomerSearch cs = new CustomerSearch(); 

     StringWriter writer = cs.getTemplate(); 
     System.out.println(writer.toString());
    }
    public StringWriter getTemplate()  {

        Template template = null;
        StringWriter writer = new StringWriter();
        Customer customer = getCustomer();
        
        ArrayList<Map> list = new ArrayList<Map>(); 
        Map<String, String> map = new HashMap<String, String>(); 
        
        map.put("category", "dog"); 
        map.put("name", "Whisky"); 
        list.add( map ); 

        map = new HashMap<String, String>(); 
        map.put("category", "cat"); 
        map.put("name", "Madonna"); 
        list.add( map ); 

        map = new HashMap<String, String>(); 
        map.put("category", "fish"); 
        map.put("name", "Levels"); 
        list.add( map );
        VelocityContext context = new VelocityContext();
        try  {
            context.put("petList", list);
            context.put("customer", customer);
            template = Velocity.getTemplate("src/customer.vm");
            template.merge(context, writer); 
        }  catch( Exception e )  {
          System.err.println("Exception caught: " + e.getMessage());
        }

        return writer;
    }

    private Customer getCustomer()  {
        Customer customer = new Customer();
        customer.setCustomerNumber("ABC123");
        customer.setName("Joe JavaRanch");
        customer.setAddress("123 Rancho Javo");
        customer.setCity("Bueno Ranch");
        customer.setState("CO");
        customer.setZip("63121");
        customer.setPhone("303-555-1212");
        return customer;
    }
}

– Now you need to modify the template. In this example, I created a for with the hashmap and added a condition to write pets unless fish.

<html> 
  <head>
   <title>Customer Search Results - $customer.customerNumber</title>
  </head>
  <body bgcolor="#faf7f1"> 
  <h1>Customer information for customer number $customer.customerNumber</h1>
  <b>Name:</b> $customer.name<br>
  <b>Address:</b> $customer.address<br>
  <b>City:</b> $customer.city<br>
  <b>State:</b> $customer.state<br>
  <b>Zip:</b> $customer.zip<br>
  <b>Phone:</b> $customer.phone<br>
  
  #foreach( $pet in $petList ) 
   #if ($pet.category != "fish") 
    <b>$pet.category </b>- Name: $pet.name<br> 
   #end 
  #end 

  </body>
</html>

I mixed a lot of things here (Hashmap,singleton, etc.), but now you can write the way you need. I hope something here helps you 🙂

Cheers guys !

Source:

http://www.javaworld.com/article/2075966/core-java/start-up-the-velocity-template-engine.html

How to: Take a screenshot with CodedUI and C#

July 15, 2015 1 comment

Hi guys,

Last week I was on holidays, for this reason I haven’t posted anything. So, I will continue with VM scripts and what you can do with them next week. Today, I will post a very, very, very old code that I have done when I was building a framework for a desktop application with Coded UI and C#. It is a function to take screenshots in your automation.

I will refactor this code other time, because I know that it is not following all the best practices, but for now you can copy and change where you want.

The code is on my github:

https://github.com/rafaelaazevedo/CodedUI/blob/master/PrintScreen.cs

First: you can see what are the parameters that you need to send:  (PublicFunctions Values, string _stringMessage, Boolean FULLSCREEN = false, Boolean FAIL = false)

Second: intFail is a failure counter and stringPath is a variable that you need to update with the path where will be placed your screenshot

Third: Thread.Sleep(2000) you can remove this and put something like wait for, it is not the best solution use Thread.Sleep

Fourth: This part will take the FULLSCREEN or not, depending what you have sent

Fifth: This part is just formatting the date/time.

Sixth: Now it is saving the picture with the path and the date/time. It is missing a try/catch here, please don’t forget to put in your code xD

Seventh: It is clearing the clipboard for the next screenshot

Eighth: It is counting the failure and catching the failure message

Ninth: The last step is inserting the failure into the database with all the information that you are passing

Thank you guys ! See you next week 🙂

Second script with Velocity (VM)

Hi guys, Today I will post another example of VM template, sorry for not to post something new, but I’ve got flu this week, I am feeling like a zombie 😦

This example is more complete and I have tested, so it is working 😀 I just made some changes to print the result with the values and the template. We have get and set methods, the vm template in html and the class to set the values and merge the template.

– Create the get and set customer class:

package test;
public class Customer {

    String customerNumber;
    String name;
    String address;
    String city;
    String state;
    String zip;
    String phone;

    public String getCustomerNumber() {return customerNumber;}
    public void setCustomerNumber(String s) {customerNumber = s;}
    public String getName() {return name;}
    public void setName(String s) {name = s;}
    public String getAddress() {return address;}
    public void setAddress(String s) {address = s;}
    public String getCity() {return city;}
    public void setCity(String s) {city = s;}
    public String getState() {return state;}
    public void setState(String s) {state = s;}
    public String getZip() {return zip;}
    public void setZip(String s) {zip = s;}
    public String getPhone() {return phone;}
    public void setPhone(String s) {phone = s;}
}

– Create a customer search class which will set the values and merge with the template:

package test;
import org.apache.velocity.Template;
import java.io.StringWriter;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;
import test.Customer;

public class CustomerSearch  {
    
    public static void main(String[] args) throws Exception { 

     CustomerSearch cs = new CustomerSearch(); 

     StringWriter writer = cs.getTemplate(); 
     System.out.println(writer.toString());
    }
    public StringWriter getTemplate()  {

        Template template = null;
        StringWriter writer = new StringWriter();
        Customer customer = getCustomer();
        
        VelocityContext context = new VelocityContext();
        try  {
            context.put("customer", customer);
            template = Velocity.getTemplate("src/customer.vm");
            template.merge(context, writer); 
        }  catch( Exception e )  {
          System.err.println("Exception caught: " + e.getMessage());
        }

        return writer;
    }

    private Customer getCustomer()  {
        Customer customer = new Customer();
        customer.setCustomerNumber("ABC123");
        customer.setName("Joe JavaRanch");
        customer.setAddress("123 Rancho Javo");
        customer.setCity("Bueno Ranch");
        customer.setState("CO");
        customer.setZip("63121");
        customer.setPhone("303-555-1212");
        return customer;
    }
}

– After, create the vm template html:

<html>
<head><title>Customer Search Results - $customer.customerNumber</title></head>
<body bgcolor="#faf7f1">
    <h1>Customer information for customer number $customer.customerNumber</h1>
    <b>Name:</b> $customer.name<br>
    <b>Address:</b> $customer.address<br>
    <b>City:</b> $customer.city<br>
    <b>State:</b> $customer.state<br>
    <b>Zip:</b> $customer.zip<br>
    <b>Phone:</b> $customer.phone<br>
</body>
<html>

Cheers guys !

Source:

http://velocity.apache.org/engine/devel/developer-guide.html

https://velocity.apache.org/engine/releases/velocity-1.5/webapps.html

http://www.javaranch.com/journal/2004/03/Velocity-AnIntroduction.html

http://www.javaworld.com/article/2075966/core-java/start-up-the-velocity-template-engine.html

%d bloggers like this: