В данном докладе мы на реальном примере рассмотрим, как можно организовать автоматизацию тестирования вебсервисов с помощью до боли знакомого всем паттерна Page Object. Казалось бы, причем тут он?..
3. What should you know before (or should have heard about)
- Test automation
- Basic TA framework layers
- Page object pattern/approach
- Web services (SOAP/REST)
- XML
- XPath
- BDD approach and Gherkin language (Cucumber, JBehave)
4. The goals
After this presentation you will have one more (of first one) practical example
of implementing test automation framework for testing web services, that:
- is easy to implement
- is easy to understand by newcomers
- was implemented on practice and have shown good results
5. Starting conditions
- No test automation on a stream (sub-project)
- Need to test SOAP services, air travel domain
- A LOT of business objects and entities
- Customer wants Cucumber
- Junior newcomers are planned
6. The questions will TA Engineers have
- How to automate SOAP services testing?
- Let’s google it! Em… SoapUI?.. Is it something else?
- How to operate requests/responses?
- Object model?
- Write all the objects?
- Generate them?
8. ’Classic’ test framework structure in UI test automation
Test scripts
Services/steps
Page-objects
WebDriver
Utils
Loggers
Stuff
9. ’Classic’ page-object example
public class LoginPage extends Page {
private static final By INPUT_LOGIN_LOCATOR = By.xpath("//input[@name='login']");
private static final By INPUT_PASSWORD_LOCATOR = By.xpath("//input[@name='passwd']");
private static final By BUTTON_SUBMIT_LOCATOR = By.xpath("//span/button[@type='submit']");
public void open() {
driver.get(URL);
}
public void typeUserName(String userName) {
driver.findElement(INPUT_LOGIN_LOCATOR).sendKeys(userName);
}
public void typePassword(String password) {
driver.findElement(INPUT_PASSWORD_LOCATOR).sendKeys(password);
}
public void clickSubmit() {
driver.findElement(BUTTON_SUBMIT_LOCATOR).click();
}
}
10. Our test framework layers
Test scripts
Step definitions
Rx-objects
Xml Modifier
Utils
Loggers
Stuff
25. XmlHelper
public class XmlHelper {
private static final String NODE_NAME_REGEX =
"(?<!['"][w/-]{1,255})(?<=[(/[:]|(and|or)s)[a-z_]+b(?![(':-])";
private static final String FORMATTING_PATTERN = "*[local-name()='%s']";
private static String makeXpathLocatorNameSpaceIgnoring(String xpathLocator) {…}
private static NodeList getNodeListByXpath(Document doc, String locator) {…}
private static Node getNodeByXpath(Document doc, String locator) {…}
public static boolean isNodePresent(Document doc, String locator) {…}
public static String getNodeText(Document doc, String locator) {…}
public static void changeNodeInDocument(Document doc, String locator, String value) {…}
public static int countNodesInDocument(Document doc, String locator) {…}
public static void removeNodeFromDocument(Document doc, String locator) {…}
public static void duplicateNodeInDocument(Document doc, String locator) {…}
...
...
...
26. Benefits of this approach
- very simple to understand, read and write tests (pure KISS principle)
- has lower entrance level
- friendly for automation engineers without experience in web services testing
- can be good option when you have a lot of business objects and entities
- was successfully implemented on real project and shows good results
27. Can we use RxObject for testing REST services?
In theory – yes.
public class RxObject {
private String type;
private Something body;
private String format;
private String responseFormat;
private String httpMethod;
...
...
...
}
But this will be more complicated.
Also you can take Rest Assured or other rest-automating framework.