mastering ui automation at scale: key lessons and best practices (by fernando martin)

42
UI Automation at Scale Augmented Driver [email protected]

Upload: applitools

Post on 14-Apr-2017

384 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

UI Automation at ScaleAugmented Driver

[email protected]

Page 2: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● Started working @Google in late 2006.

Page 3: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● Started working @Google in late 2006. ● Selenium/Webdriver started becoming a “thing” sometime in 2007.

Page 4: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● In 2010 I joined Medallia.

Page 5: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● In 2010 I joined Medallia.● Super excited about building UI automation from scratch.

Page 6: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● In 2014 moved to RelateIQ (Now SalesforceIQ)

Page 7: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● In 2014 moved to RelateIQ (Now SalesforceIQ)● Again a Start Up, being part of a small team that wanted to have a big

impact in the company.

Page 8: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● Finally a couple of months ago I joined Split.IO.

Page 9: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

A little bit about me● Finally a couple of months ago I joined Split.IO● Being one of the first Software Engineers, again with the role of shipping

code as fast as we can with the best Customer Experience as we can.

Page 10: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IWebDriver tests are inherently slow. If you want throughput, you need to focus on parallelism, leading us to the first lesson in this saga.

Page 11: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode I: Data Independent TestsIf each test creates its own data that is not shared with anyone else, then all of your tests can run in parallel.

Page 12: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!@Path(“/test”)public class TestResource {

@Post@Path(“create”)public Response create(String uniqueUser) {

If (isProd()) { throw new NotAllowedException(“NOT ALLOWED”); }//… create unique user, organization, etc...//...

}@Post@Path(“clean”)public Response clean(String uniqueUser) {

If (isProd()) { throw new NotAllowedException(“NOT ALLOWED”);}//…clean unique user, organization, etc...//...

}}

Page 13: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!public class DataCreatorRule implements TestRule {

public Statement apply(Statement statement, Description description) {return new Statement() {

@Overridepublic void evaluate() throws Throwable {

String uniqueUser = "uniqueuser";client

.test()

.create(uniqueUser);statement.evaluate();client

.test()

.clean(uniqueUser);}

}}

}

Page 14: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!public abstract class BaseTestCase {

@Rulepublic DataCreatorRule dataCreatorRule = new DataCreatorRule();

}

Page 15: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Alternatives● @BeforeMethod and @AfterMethod in TestNG.● @Before and @After in JUnit < 4.● beforeEach() and afterEach() in Jasmine JS.● setUp(self) and tearDown(self) in Python.

Page 16: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode I Code Example

Page 17: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IIThroughput is achieved with Parallelism. With that in mind, you need to build reliable tests in all possible Environments.

Local != Staging != SauceLabs.

This leads to the second lesson...

Page 18: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode II: Slow and Steady Wins the RaceFailures are caused by elements not showing up in time. In general, when the element has an unexpected transient state when the action is being performed.

Page 19: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!private final Webdriver driver;

public void ohWhy(By identifier) {

Thread.sleep(3000);

WebElement element = driver.findElement(identifier);

element.click();

}

Page 20: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!private final Webdriver driver;

public void better(By identifier) {

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(identifier);

element.click();

}

Page 21: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!private final AugmentedWebDriver driver;

public void augmentedWay(By identifier) {

driver

.augmented()

.findElementClickable(identifier)

.click();

}

Page 22: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

More...driver.augmented().findElementVisible(id);

driver.augmented().findElementsVisible(id).get(0)

.augmented().findElementClickable(id2).click();

driver().augmented().clickAndSendKeys(id, “text”);

driver().augmented().swipeDown(id);

Page 23: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode II Code Example

Page 24: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode III.● Your tests can run in parallel...● You can wait until elements are on a desired state...

Time to encapsulate you tests in business logic to maximize reusability and maintainability.

This leads to the third lesson...

Page 25: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode III: Follow the Page Object ModelNeed to encapsulate the logic of the UI areas that your tests performs actions, for maintainability and for many other reasons.

Page 26: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the code!public class MainPage extends WebPageObject {

@Override

public Optional<By> visibleBy() {

return Optional.of(Bys.INPUT);

}

public static class Bys {

public static class By INPUT = By.id("searchInput");

}

}

Page 27: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the Code!public class BaseCase extends AugmentedWebTestCase {

public MainPage mainPage() {

driver().get(“https://www.wikipedia.org”);

Return get(MainPage.class);

}

}

Page 28: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode III Code Example

Page 29: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IV● Your tests can run in parallel...● You can wait until elements are on a desired state...● You have your framework encapsulated on business logic…

The next level is to wait and expect certain business logic to take place when actions are performed.

That leads to…

Page 30: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IV: Wait and Expect for business logicThis is an extension of the Episode 2 but at a much higher level that each app defines.

Page 31: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IV: Wait and Expect for business logicSince now we have Page Objects that encapsulate business logic, we can perform “waiters” that will wait until certain condition is fulfilled.

Page 32: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the Code!public class MainPage extends WebPageObject {

public int numberOfSuggestions() {

return driver()

.augmented()

.findElementSSSSVisible(Bys.SUGGESTION)

.size();

}

public static class Bys {

public static final By SUGGESTION = By.className("suggestion-link");

}

}

Page 33: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

To the Code! @Test

public void test() {

mainPage

.search("WebDriver");

waiter().waitUntil(mainPage, page -> page.numberOfSuggestions() > 3);

}

Page 34: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode IV Code Example

Page 35: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode V● Your tests can run in parallel...● You can wait until elements are on a desired state...● Your business logic is encapsulated...● You can wait for business logic to be fulfilled…

Now each test has maintainability and reliability in mind. It’s time to consolidate each individual piece into something that the rest of the team can easily digest it.

Page 36: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode V: Reporting Reporting ReportingThis has one basic lesson learned:

Page 37: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode V

DON’T

Page 38: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode V Code Example

Page 39: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode VI● Your tests can run in parallel...● You can wait until elements are on a desired state...● Your business logic is encapsulated...● You can wait for business logic to be fulfilled…● You have a way to have visibility and transparency

Finally the last step is to provide easy configuration and integrations so it can be plugged into CI systems

Page 40: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode VI: Integrations and Easy ConfigurationIt should be easy and straightforward to integrate into different tools.

Page 41: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Episode VI Code Example

Page 42: Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando Martin)

Thanks!Augmented Driver: https://github.com/relateiq/AugmentedDriver

Split.IO: http://www.split.io/

Special offer by Applitools:

50-page guidebook to visual testing (including tips, tricks and code examples), written by Selenium expert Dave Haeffner.

Claim your free copy by sending an email to [email protected]