Download presentation
Presentation is loading. Please wait.
Published byRalph Gordon Modified over 8 years ago
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
3
Michael Suzuki @suzukimichael github.com/michaelsuzukisagi
4
Why Testing Makes Sense It builds Confidence that the systems is behaving as it should. Validates no regression bugs have been introduced Pins the functionality Helps find problems early Detecting difference
5
Test Types Unit Tests Integration Tests Functional Tests
6
The Right Balance
7
Testing Your Alfresco Add-ons Automation Tools
8
WebDriver An open source browser automation API. Supports different OS, languages and browsers.
9
WebDriver Code { //Start fire fox WebDriver driver = new FireFoxDriver(); //Navigate to share driver.navigate(http://localhost:8080/share); }
10
Locator Strategies Id Name Tag name Class name CSS selector Xpath Link Text Partial Link Text
11
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)); }
12
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(); }
13
Testing Your Alfresco Add-ons Best Practice
14
Always Use Page Object Pattern Render Pattern
15
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
16
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(); }
17
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
18
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.
19
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; }
20
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.
21
WebDrone Project A Selenium WebDriver wrapper with added functionality. Provides additional tools: Selenium grid Image recognition Language support
22
Things To Avoid WebDriver code in test code Assertions in page objects Thread sleep
23
Testing Your Alfresco Add-ons Demo
24
Build Add-ons with Maven mvn install -Pamp-to-war mvn archetype:generate - DarchetypeCatalog=https://artifacts.alfresco.com/nexus/content/gr oups/public/archetype-catalog.xml - Dfilter=org.alfresco.maven.archetype: export MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx1024m” Setup Maven options Create project from archetype Run AMP with Maven Run test mvn install –Pfunctional
25
Thank you
26
Additional Info Share Page Object https://github.com/Alfresco/community-edition/tree/master/projects/share-po WebDrone https://svn.alfresco.com/repos/alfresco-enterprise/benchmark/webdrone Demo https://github.com/michaelsuzukisagi/summit2014.git Selenium WebDriver http://docs.seleniumhq.org/docs/03_webdriver.jsp https://code.google.com/p/selenium/wiki/PageObjects Alfresco Maven http://ecmarchitect.com/alfresco-developer-series-tutorials/maven-sdk/tutorial/tutorial.html http://www.youtube.com/watch?v=Tu641nRGbtQ Spring Loaded https://github.com/spring-projects/spring-loaded
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.