Download presentation
Presentation is loading. Please wait.
1
Testing Your Alfresco Add-ons
Michael Suzuki Software Engineer
2
Testing Your Alfresco Add-ons
Introduction Automation Tools Best Practice Setting Up With Maven Demo Were going to cover testing: The tools that are available The patterns And how to do it.
3
Michael Suzuki @suzukimichael github.com/michaelsuzukisagi
4
Testing your add-on’s gives you the confidence that they are behaving correctly.
What is this talk about.
5
Why Testing Makes Sense
It builds Confidence that the systems is behaving as it should. Validates no regression bugs have been introduced Helps find problems early Shorter feedback loops when refactoring We don’t wait till the qa phase to find problems.
6
Test Types Unit Tests Integration Tests Functional Tests
Unit tests,tests the unit. Integration test ensures services are talking to each other. Functional that the software meets the requirements.
7
The Right Balance
8
Value Of Automation Detecting difference Pins the functionality
Avoid wasted effort Less duplication
9
Testing Your Alfresco Add-ons
Automation Tools
10
WebDriver An open source browser automation API.
Supports different OS, languages and browsers.
11
WebDriver Code { //Start fire fox
WebDriver driver = new FireFoxDriver(); //Navigate to share driver.navigate( }
12
Locator Strategies Id Name Tag name Class name CSS selector Xpath
Link Text Partial Link Text Talk about locators: By id,css,xpath, tag name.
13
Locator Strategies In Action
{ //By Id WebElement username = driver.findElement(By.id(“iusername”)); //By Name WebElement password = driver.findElement(By.name(“password”)); //By Tag Name WebElement btn= driver.findElement(By.tagName(“button”)); //By CSS selector username = driver.findElement(By.cssSelector(“input#iusername”)); //By class name WebElement btn =driver.findElement(By.className(“button”)); //By xpath btn = driver.findElement(By.cssSelector(“//button)); }
14
Interacting With Elements
{ //Find Element By Id WebElement element = driver.findElement(By.id(“foo”)); //check if visible element.isDisplayed(); //type in admin element.sendKeys(“admin”); //clear input field element.clear(); //click action element.click(); //get text element.getText(); }
15
Testing Your Alfresco Add-ons
Best Practice
16
Always Use Page Object Pattern Render Pattern
Why cause it makes hard to maintain test code
17
Page Object “A page object wraps an HTML page, or fragment, with an application-specific API, allowing you to manipulate page elements without digging around in the HTML” Martin Fowler
18
Login Page Object public class LoginPage {
private static By USERNAME_INPUT = By.id(“username"); private static By PASSWORD_INPUT = By.id(“password"); private static By SUBMIT_BUTTON = By.id(“submit"); public LoginPage(WebDriver driver) {} public void login(String username, String password) // Find By Id WebElement username = driver.findElement(USERNAME_INPUT); username.sendKeys(username); WebElement password = driver.findElement(PASSWORD_INPUT); password.sendKeys(password); driver.findElement(SUBMIT_BUTTON).click(); }
19
Why You Should Use Page Objects
Encourages re-use of the code Makes tests more readable Encapsulates mechanical details of the page Easier to maintain Less duplication
20
Render Pattern The logic which determines if a page has rendered, by checking that all the required web elements of the page, are visible before it can be used.
21
Render Method In Action
public LoginPage render(RenderTime timer) { while (true) timer.start(); try if(driver.find(USERNAME_INPUT).isDisplayed() && driver.find(PASSWORD_INPUT).isDisplayed() && driver.find(SUBMIT_BUTTON).isDisplayed() break; } catch (NoSuchElementException nse){} finally timer.end(); return this; Addresses intermitted test failures and Thread Sleep. Loops to find input fields and submit button, if not found the timer eventually throws a PageRenderTimeException
22
Share PO Project Aims to mimic user interaction on Alfresco Share.
A library that is simple, reliable and reusable. The project started in 2012 and is now part of Alfresco core. Currently used by Functional test (aka QA share) and Benchmark
23
WebDrone Project A Selenium WebDriver wrapper with added functionality. Provides additional tools: Selenium grid Image recognition Language support Currently used by Functional test (aka QA share) and Benchmark
24
Things To Avoid WebDriver code in test code Assertions in page objects
Thread sleep Why cause it makes hard to maintain test code
25
Testing Your Alfresco Add-ons
Demo
26
Build Add-ons with Maven
Setup Spring Loaded export SPRING_LOADER=/usr/local/lib/spring-loaded/springloaded RELEASE.jar Setup Maven options with Spring Loaded export MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx1024m -javaagent:$SPRING_LOADER -noverify" Run AMP with Maven Create a directory mvn archetype:generate -DarchetypeCatalog= -Dfilter=org.alfresco.maven.archetype: Type 1 to build amp Type option 5 to get latest archtype Type a groupid org.alfresco.summit Type aritfact id, the project name: demo If out of memory type MAVEN_OPTS='-Xms256m -XX:MaxPermSize=1024m -Xmx1024m’ Run alfresco mvn integration-test -Pamp-to-war To run share, cd into directory and type mvn integration-test -Pamp-to-war -Dmaven.tomcat.port=8081 mvn integration-test -Pamp-to-war
27
Thank you
28
Additional Info Share Page Object WebDrone Demo Selenium WebDriver
WebDrone Demo Selenium WebDriver Alfresco Maven Spring Loaded
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.