Last time we automated a native Android application with Telerik Mobile Testing. Now it's time for AppBuilder. Once again I will make it testable, develop a test plan, write and execute tests, and publish results to the Telerik Platform.
This case study uses a simple application called Comments, created with Telerik AppBuilder and Backend Services. The main screen displays existing comments from the data source, and new comments are added on the second screen.
Main screen | Add comment | Comment entered |
Main screen | Add comment | Comment entered |
There are four HTML element types I plan to interact with: link, unordered list, textarea, and div. I applied a unique id attribute to each element for easier element identification later.
I configured the AppBuilder application to be testable based on these instructions. Next I deployed the Android and iOS builds to a Samsung Galaxy S III and an iPhone 5, respectively.
I need the Mobile Testing companion app to test a hybrid app. I downloaded it from Google Play on the Android device, and from the App Store on the iOS device.
There are five functional scenarios I want to test through automation:
I started by creating a new JavaScript file. Code may be written to that file using any IDE or text editor. I prefer Sublime Text.
Start with the main spec method:
spec(
function
(){
});
Next comes the Query Repository. I defined the queries for all the elements here and assigned each to a variable.
var
queries = {
deleteBtn: { id:
'deleteBtn'
},
addBtn: { id:
'addBtn'
},
cancelBtn: { id:
'cancelBtn'
},
saveBtn: { id:
'saveBtn'
},
commentText: { id:
'commentText'
},
textRequired: { id:
'textRequired'
},
listview: { id:
'listview'
}
};
Here I defined a few static variables used later in the test steps.
var
d =
new
Date();
var
h = d.getHours();
var
m = d.getMinutes();
var
s = d.getSeconds();
var
time = h.toString() + m.toString() + s.toString();
The bulk of the code comes next via the Step Repository. Each step is labeled with a friendly name, followed by platform-specific operations. Use default for steps that apply to both platforms.
These steps perform the actions and verifications against the application's elements, which are referenced via the query repository. You'll see things like launching the app, tapping links, setting text, and verifying text.
var
stepRepository = {
"Launch app"
: {
'ios'
: [
ios.launch(
'Comments://'
)
],
'android'
: [
android.launch(
'com.telerik.Comments'
)
]
},
"Tap Delete"
: {
'default'
: [
web.wait(1000),
web.tap(queries.deleteBtn)
]
},
"Tap Add"
: {
'default'
: [
web.tap(queries.addBtn),
web.wait(1000)
]
},
"Tap Cancel"
: {
'default'
: [
web.tap(queries.cancelBtn)
]
},
"Tap Save"
: {
'default'
: [
web.tap(queries.saveBtn)
]
},
"Enter comment"
: {
'default'
: [
web.setValue(queries.commentText, time)
]
},
"Verify text is required"
: {
'default'
: [
web.getTextContent(queries.textRequired,
function
(res){
assert(res).equals(
"Required field."
);
})
]
},
"Verify textarea is blank"
: {
'default'
: [
web.getTextContent(queries.commentText,
function
(res){
assert(res).equals(
""
);
})
]
},
"Verify new comment in list"
: {
'default'
: [
web.getTextContent(queries.listview,
function
(res){
assert(res).contains(time);
})
]
},
"Verify new comment not in list"
: {
'default'
: [
web.getTextContent(queries.listview,
function
(res){
assert(res).not.contains(time);
})
]
}
};
Finally comes the Test Suite. A suite is a group of tests, labeled with a friendly name, that calls the step repository. Each test is also labeled and contains steps, referenced by their friendly names from the step repository.
Based on the test plan I created earlier, I simply mix and match steps to create each test.
describe(
"Comments"
,
function
(){
test(
"Add a new comment and verify it is in the list"
,
function
(){
step(
"Launch app"
);
step(
"Tap Add"
);
step(
"Enter comment"
);
step(
"Tap Save"
);
step(
"Verify new comment in list"
);
});
test(
"Delete new comment and verify it is not in the list"
,
function
(){
step(
"Launch app"
);
step(
"Tap Delete"
);
step(
"Verify new comment not in list"
);
});
test(
"Cancel comment"
,
function
(){
step(
"Launch app"
);
step(
"Tap Add"
);
step(
"Enter comment"
);
step(
"Tap Cancel"
);
step(
"Verify new comment not in list"
);
})
test(
"Ensure text area requires input"
,
function
(){
step(
"Launch app"
);
step(
"Tap Add"
);
step(
"Tap Save"
);
step(
"Verify text is required"
);
step(
"Tap Cancel"
);
});
test(
"Ensure text area clears on cancel"
,
function
(){
step(
"Launch app"
);
step(
"Tap Add"
);
step(
"Enter comment"
);
step(
"Tap Cancel"
);
step(
"Tap Add"
);
step(
"Verify textarea is blank"
);
step(
"Tap Cancel"
);
});
}, stepRepository);
It's time to execute the tests via the Test Runner.
In this case, I executed the agents separately to avoid conflicts with data deletion.
The Results tab loads when execution finishes. All tests passed!
I can additionally publish results to the Telerik Platform for storage and to share with colleagues, managers, and stakeholders.
That's it! The handy query and step repository method makes it easy to add new queries and tests when I add new elements and features to my application.
Stay tuned for the next case study on a mobile Web app.
Anthony Rinaldi is the Product Manager of Telerik Mobile Testing. He combines his experience in test automation and quality assurance with his passion for mobile devices and platforms. He is an avid CrossFitter, soccer player, and music fan.