Technical Project Lead @ Huawei Technologies

My photo
Bangalore/Hyderabad, Karnataka/Andhra Pradesh, India
Have an overall 13 + yrs of experience Currently working as an Senior Architect.Expertise in design,implementation of Automation frameworks for Opensource automation tools like Selenium,Jmeter, Webdriver,Appium, Robotium Expertise in integrating Test & ALM Management tools like Rally,Qmetry,JIRA-Zephyr with Automation frameworks Expertise in design and developmenet Mobile Automation frameworks for tools like Appium, Robotium Remote Control,Cucumber BDD,Manual Testing

Followers

Saturday, March 15, 2014

How to add attachements to Rally test cases

//This Snippet will Update Test Case Result and add Attachment to a Test Case


// Create and configure a new instance of RallyRestApi
// Connection parameters
String rallyURL = "https://rally1.rallydev.com";
String wsapiVersion = "v2.0";
String applicationName = "RestExample_CreateTestCaseResultAddAttachment";

// Credentials
String userName = "user@company.com";
String userPassword = "topsecret";

RallyRestApi restApi = new RallyRestApi(new URI(rallyURL), userName,
userPassword);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);

// Workspace and Project Settings
String myWorkspace = "/workspace/12345678910";
String myProject = "/project/12345678911";

// Test Case to which we want to add a result
String testCaseFormattedID = "TC40";

// User name of tester
String testerRallyID = "tester@testit.com";

// Reference to created TestCaseResult
String testCaseResultRef = "";

// File handle for image to attach
RandomAccessFile myImageFileHandle;
String imageFilePath = "/home/username/Pictures/";
String imageFileName = "image1.txt";
String fullImageFile = imageFilePath + imageFileName;
String imageBase64String;
long attachmentSize;

// Open file
myImageFileHandle = new RandomAccessFile(fullImageFile, "r");

// Read User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription",
"DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=",
testerRallyID));
QueryResponse userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonObject userQueryObject = userQueryResults.get(0).getAsJsonObject();
String userRef = userQueryObject.get("_ref").getAsString();

// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID", "Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
testCaseFormattedID));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults()
.get(0).getAsJsonObject();
String testCaseRef = testCaseQueryResponse.getResults().get(0)
.getAsJsonObject().get("_ref").getAsString();

// Query for Test Set to which we want to add Test Case
QueryRequest testSetQuery = new QueryRequest("TestSet");
testSetQuery.setFetch(new Fetch("FormattedID", "Name", "TestCases"));
testSetQuery.setWorkspace(myWorkspace);
testSetQuery.setProject(myProject);
testSetQuery.setQueryFilter(new QueryFilter("FormattedID", "=", "TS5"));
QueryResponse testSetQueryResponse = restApi.query(testSetQuery);
JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(0)
.getAsJsonObject();
String testSetRef = testSetJsonObject.get("_ref").getAsString();
System.out.println("Test Set Ref: " + testSetRef);

try {

// Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Inconclusive");
newTestCaseResult.addProperty("Date", "2013-09-04T18:00:00.000Z");
newTestCaseResult.addProperty("Notes",
"Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "2013.09.04.0020101");
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);
newTestCaseResult.addProperty("TestSet", testSetRef);

CreateRequest createRequest = new CreateRequest("testcaseresult",
newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);

if (createResponse.wasSuccessful()) {

System.out.println(String.format("Created %s", createResponse
.getObject().get("_ref").getAsString()));

// Read Test Case Result
testCaseResultRef = Ref.getRelativeRef(createResponse
.getObject().get("_ref").getAsString());
System.out.println(String.format(
"\nReading Test Case Result %s...", testCaseResultRef));
GetRequest getRequest = new GetRequest(testCaseResultRef);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format(
"Read Test Case Result. Date = %s, Verdict = %s", obj
.get("Date").getAsString(), obj.get("Verdict")
.getAsString()));

try {
// Get and check length
long longLength = myImageFileHandle.length();
long maxLength = 5000000;
if (longLength >= maxLength)
throw new IOException(
"File size >= 5 MB Upper limit for Rally.");
int fileLength = (int) longLength;

// Read file and return data
byte[] fileBytes = new byte[fileLength];
myImageFileHandle.readFully(fileBytes);
imageBase64String = Base64.encodeBase64String(fileBytes);
attachmentSize = fileLength;

// First create AttachmentContent from image string
JsonObject myAttachmentContent = new JsonObject();
myAttachmentContent.addProperty("Content",
imageBase64String);
CreateRequest attachmentContentCreateRequest = new CreateRequest(
"AttachmentContent", myAttachmentContent);
CreateResponse attachmentContentResponse = restApi
.create(attachmentContentCreateRequest);
String myAttachmentContentRef = attachmentContentResponse
.getObject().get("_ref").getAsString();
System.out.println("Attachment Content created: "
+ myAttachmentContentRef);

// Now create the Attachment itself
JsonObject myAttachment = new JsonObject();
myAttachment.addProperty("TestCaseResult",
testCaseResultRef);
myAttachment.addProperty("Content", myAttachmentContentRef);
myAttachment.addProperty("Name", "AttachmentFromREST.jpg");
myAttachment.addProperty("Description",
"Attachment From REST");
myAttachment.addProperty("ContentType", "image/jpg");
myAttachment.addProperty("Size", attachmentSize);
myAttachment.addProperty("User", userRef);

CreateRequest attachmentCreateRequest = new CreateRequest(
"Attachment", myAttachment);
CreateResponse attachmentResponse = restApi
.create(attachmentCreateRequest);
String myAttachmentRef = attachmentResponse.getObject()
.get("_ref").getAsString();
System.out.println("Attachment  created: "
+ myAttachmentRef);

if (attachmentResponse.wasSuccessful()) {
System.out.println("Successfully created Attachment");
} else {
String[] attachmentContentErrors;
attachmentContentErrors = attachmentResponse
.getErrors();
System.out
.println("Error occurred creating Attachment: ");
for (int i = 0; i < attachmentContentErrors.length; i++) {
System.out.println(attachmentContentErrors[i]);
}
}
} catch (Exception e) {
System.out
.println("Exception occurred while attempting to create Content and/or Attachment: ");
e.printStackTrace();
}

} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out
.println("Error occurred creating Test Case Result: ");
for (int j = 0; j < createErrors.length; j++) {
System.out.println(createErrors[j]);
}
}

} finally {
// Release all resources
restApi.close();
myImageFileHandle.close();
}
}

How to add test steps to an Exiting test cases in Rally


Friday, January 31, 2014

Inspecting IOS elements and recording tests using Appium on Simulator

1.Download & Install the GUI version of Appium server(check appium.io)
2.Open the Appium server. You should see some thing like below




















3. We would be inspecting the IOS element using this GUI version of appium
4. Check the flag AppPath an provide the path to your .app(you can find the path from Xcode)
Ex: The path I provided here is '/Users/kiran/Library/Developer/Xcode/DerivedData/UICatalog-fqsvdhmisheuvqbsuomezsujnqgi/Build/Products/Debug-iphonesimulator/UICatalog.app'
5.Ensure you pick the .app path which is in 'Debug-iphonesimulator' folder and not 'Debug-iphoneos folder (when you run the UICatalog code on a real device from Xcode, the .app will be created in 'Debug-iphoneos).
6.Now click on 'Launch' button to start the appium server.
7.Click on 'i' button to launch the IOS inspector
8.Check the below video to see how to inspect elements on IOS simulator and record the tests

You can even play back  the tests with in the appium recorder
Check the following video link to have a glance on how to inspect and record
https://www.youtube.com/watch?v=BNgFixhS_AM&feature=youtu.be

You can run your tests either starting the appium from GUI mode or from terminal mode.
Now lets c how to run the tests when appium is launched from terminal
Stop the GUI mode appium server
open the terminal and type the command appium &. This will launch the appium server on default port 4723


Tuesday, January 28, 2014

Rally API integration with Java

Recently I worked on Rally API integration with our Java Automation framework .Rally is the ALM (Application Life Management tool) . In this blog I would be posting my experiences in Integrating Rally API and the context would be more on Test Management

Rally exposes some webservices typically REST services that allows user to Manage the Test Management. To access the webservices Rally does not provide any API. How ever there are many open source Rest Clients for Java,C#,python.....

I used Java Rest Client to access the Rally REST services you can download the libraries from the link
https://github.com/RallyTools/RallyRestToolkitForJava

How to update the test cases in rally with our Automation Test case results

Will soon post the BLOG...

How to create a Test Case using Rally Rest API

Will soon post the BLOG

How to Query for list of Test Cases using Query Filter

Will soon post the BLOG