Last time we automated a hybrid AppBuilder application with Telerik Mobile Testing. Now it's time for Web. 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 sushi ordering application created with Telerik Kendo UI. The home screen displays menu items from the data source, which can be added to the cart and submitted..
Home screen | Shopping cart | My account |
The are three HTML element types I plan to interact with: link, span, and header. Most have a unique id attribute for easier element identification later. Those without can be located with className and index.
I configured the Web application to be testable based on these instructions. Next I ran the app locally with Node.js. If you're curious how this done, see the following file in our download bundle:
There are four 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, assigned each to a variable, and separated them by section.
var
queries = {
tabstrip: {
home: { id:
"home"
},
cart: { id:
"cart"
},
account: { id:
"account"
}
},
items: {
sashimiSalad: { className:
"details-link"
, index: 0 },
seaweedSalad: { className:
"km-button"
, index: 2 },
edamame: { className:
"km-button"
, index: 3 }
},
itemDetails: {
orderBtn: { id:
"add-to-cart"
},
addedSpan: { id:
"added"
}
},
cart: {
total: { id:
"total"
},
checkoutBtn: { id:
"checkout"
},
deleteBtn: { className:
"red-button km-button"
, index: 1 },
thanks: { id:
"thanks"
},
doneBtn: { id:
"done-button"
}
},
account: {
productsSwitch: { className:
"km-switch-label-on"
, index: 0 },
promosSwitch: { className:
"km-switch-label-off"
, index: 1 }
}
};
Here I defined a few static variables used later in the test steps.
var
CURR_DOMAIN =
"http://localhost:1234/"
;
var
PREP_DOMAIN =
"http://localhost:1234/agent/TelerikTestingPrepareDomain.html"
;
The bulk of the code comes next via the Step Repository. Each step is labeled with a friendly name, followed by platform-specific operations. This example only uses Web operations.
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, and verifying text.
var
stepRepository = {
"Redirect to site under test"
: {
web: [
web.prepareDomain(PREP_DOMAIN),
web.navigateToUrl(CURR_DOMAIN),
web.wait(500),
web.waitForUrl(CURR_DOMAIN, 5000)
]
},
"Get details for Sashi Salad"
: {
web: [
web.tap(queries.items.sashimiSalad)
]
},
"Add Seaweed Salad"
: {
web: [
web.wait(500),
web.tap(queries.items.seaweedSalad)
]
},
"Add Edamame"
: {
web: [
web.wait(500),
web.tap(queries.items.edamame)
]
},
"Tap Order button"
: {
web: [
web.wait(500),
web.tap(queries.itemDetails.orderBtn)
]
},
"Tap Menu button"
: {
web: [
web.tap(queries.tabstrip.menu)
]
},
"Tap Cart button"
: {
web: [
web.tap(queries.tabstrip.cart)
]
},
"Tap Account button"
: {
web: [
web.tap(queries.tabstrip.account)
]
},
"Tap Done button"
: {
web: [
web.wait(500),
web.tap(queries.cart.doneBtn)
]
},
"Tap Checkout button"
: {
web: [
web.wait(500),
web.tap(queries.cart.checkoutBtn)
]
},
"Tap Delete button"
: {
web: [
web.wait(500),
web.tap(queries.cart.deleteBtn)
]
},
"Tap Products switch"
: {
web: [
web.wait(500),
web.tap(queries.account.productsSwitch),
web.getTextContent(queries.account.productsSwitch,
function
(res){
assert(res).equals(
"on"
);
})
]
},
"Tap Promos switch"
: {
web: [
web.wait(500),
web.tap(queries.account.promosSwitch),
web.getTextContent(queries.account.promosSwitch,
function
(res){
assert(res).equals(
"off"
);
})
]
},
"Verify item added to cart"
: {
web: [
web.getTextContent(queries.itemDetails.addedSpan,
function
(res){
assert(res).equals(
"Item added to cart"
);
})
]
},
"Verify total is $12.00"
: {
web: [
web.getTextContent(queries.cart.total,
function
(res){
assert(res).equals(
"$12.00"
);
})
]
},
"Verify total is $4.00"
: {
web: [
web.getTextContent(queries.cart.total,
function
(res){
assert(res).equals(
"$4.00"
);
})
]
},
"Verify order processed"
: {
web: [
web.getTextContent(queries.cart.thanks,
function
(res){
assert(res).equals(
"Thanks for shopping!"
);
})
]
},
};
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(
"Sushi tests"
,
function
(){
test(
"Redirect to SUT"
,
function
() {
step(
"Redirect to site under test"
);
});
test(
"Change account settings"
,
function
(){
step(
"Tap Account button"
);
step(
"Tap Products switch"
);
step(
"Tap Promos switch"
);
});
test(
"Order first item and verify success"
,
function
(){
step(
"Get details for Sashi Salad"
);
step(
"Tap Order button"
);
step(
"Verify item added to cart"
);
step(
"Tap Cart button"
);
step(
"Verify total is $12.00"
);
step(
"Tap Checkout button"
);
step(
"Verify order processed"
);
step(
"Tap Done button"
);
});
test(
"Edit shopping cart"
,
function
(){
step(
"Add Seaweed Salad"
);
step(
"Add Edamame"
);
step(
"Tap Cart button"
);
step(
"Tap Delete button"
);
step(
"Verify total is $4.00"
);
});
}, stepRepository);
It's time to execute the tests via the Test Runner.
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.
Anthony Rinaldi 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.