8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 1/42
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 2/42
About Us
Richard Olrichs
MN
www.olrichs.nl
@richardolrichs
Wilfred van der D
The Future Group
www.redheap.com
@wilfreddeijl
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 3/42
Agenda
Demo: Selenium
Plain Selenium Examples
Page Objects
Demo: ADF Selenium
ADF Selenium Tools
Demo: Testing Your Bounded Taskflows
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 4/42
Selenium 101 Demo
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 5/42
Selenium 101
public void simpleTest() { WebDriver driver = new FirefoxDriver(
driver.get("http://google.com/?hl=en"
WebElement searchBox =
driver.findElement(name("q")); searchBox.sendKeys("adf selenium");
searchBox.submit();
}
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 6/42
Selenium History
Selenium v1
● Uses JavaScript injection to emulate user interaction
Very flaky with modern apps
● Used in OTN Article (don’t do that)
Selenium v2 (aka WebDriver)
● Native events to drive browser
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 7/42
Page Objects
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 8/42
Page Objects
Martin Fowler:
“It should provide an interface that's easy to
program to and hides the underlying
widgetry in the window”Source: martinfowler.com/bliki/PageOb ject.html
Also advocated by Selenium team
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 9/42
ADF Selenium Tools
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 10/42
ADF Selenium Tools
github.com/wvanderdeijl/adf-selenium
Two JDev 12c Projects:
● SeleniumTools - Library JAR
● RichClientDemoTest - Sample JUnit tests against ADF 12c com
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 11/42
ADF Selenium Demo
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 12/42
Basic JUnit Example
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 13/42
Basic JUnit Example
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
Page Object
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 14/42
Basic JUnit Example
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
ADF Component Object
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 15/42
Basic JUnit Example
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
Interact with
ADF Component
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 16/42
Basic JUnit Example
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
Test Assertion
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 17/42
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 18/42
public class CalendarTest {
@ClassRule
public static WebDriverResource driver = new FirefoxDriv
WebDriverResource starts (and stops) a web browser to run the tests
@ClassRule: invoke JUnit rule once per test class
@Rule: invoke JUnit rule for each test method
Acquiring ADF Page Object
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 19/42
public class CalendarTest {
@ClassRule public static WebDriverResource driver = new FirefoxDriv
@Rule
public PageProvider<CalendarDemoPage> pages =
new PageProvider(CalendarDemoPage.class, PAGE_URL, driver.getDriver());
PageProvider takes a WebDriver (browser) and knows how to naviga
and instantiate a Page Object
@Rule triggers provider for each test so we start fresh
Acquiring ADF Page Object
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 20/42
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 21/42
import com.redheap.selenium.component.AdfCalendar;
import com.redheap.selenium.page.Page;
public class CalendarDemoPage extends Page {
public AdfCalendar findCalendar() {
return findAdfComponent("dmoTpl:cal");
}
com.redheap.selenium.page.Page base class offers protected utility
findAdfComponent uses (relative) JSF selectors
Acquiring ADF Component
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 22/42
Interacting with ADF Components
@Test
public void testHover() { CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
How did we implement
component methods?
I t ti ith ADF C t
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 23/42
Interacting with ADF Componentsimport com.redheap.selenium.component.AdfComponent;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
public class AdfCalendar extends AdfComponent {
public void hoverActivityInView(int index) {
WebElement element = findAllActivitiesInView().get(index);
// move mouse to element and wait for ADF to detect hover
new Actions(getDriver()).moveToElement(element).pause(1000).perform
waitForPpr();
}}
Component class encapsulates interaction with HTML elements
Selenium Actions can interact with browser and mouse
AdfComponent.waitForPpr waits for any PPR and complete javascrip
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 24/42
Interacting with ADF Components
@Test
public void testHover() {
CalendarDemoPage page = pages.goHome();
AdfCalendar calendar = page.findCalendar();
calendar.hoverActivityInView(0);
assertEquals("NOTE: This popup is for demo purposes only;...",
page.findPopupNote().getValue());
}
How did we implement
component methods?
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 25/42
import com.redheap.selenium.component.AdfComponent;
public class AdfOutputText extends AdfComponent {
public Object getValue() {
return executeScript("var cmp=AdfPage.PAGE.findComponentByAbsoluteI
+ "return cmp.getValue()",
getClientId());
}
}
CalendarDemoPage.findPopupNote returns AdfOutputText compone
Component classes frequently use javascript to interact with compon
AdfComponent base class offers protected executeScript method
Every component becomes a client component with
oracle.adf.view.rich.automation.ENABLED=true in web.xml
Interacting with ADF Components
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 26/42
Selenium Tools Component Classes
● Re-use a lot of logic that would otherwise live in Page Objects
● Rely heavily on ADF JavaScript API● All extend from AdfComponent
○ click(), contextClick(), doubleClick()
○ dragAndDropTo(AdfComponent target)
○ findAdfComponent(String childId)
○ isDisabled(), isDisplayed()
○ scrollIntoView()○ and a few more
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 27/42
Component Class Example: AdfTable
long getRowCount()
findAdfComponent(String child, int row)scrollToRowIndex(int row)
discloseRowDetail(int row)
List<Integer> getDisclosedRows()
selectRow(int row)
selectToRow(int row)selectAdditionalRow(int row)
... and all AdfComponent methods
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 28/42
Testing Your Bounded Taskflo
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 29/42
Bounded Taskflow Recap
JUnit Test your taskflows
Use TaskFlow Tester for isolated tests - java.net/projects/adf-task-flo
PerceptualDiffMatcher - bit.ly/pdiff
or look at more powerful Depicted at github.com/bslatkin/dpxdt
JaCoCo Code CoverageJUnit Rule to dump execution data - bit.ly/jacoco-rule
Optional reporter to write html report - bit.ly/jacoco-report
Browser of choice: Firefox, PhantomJS or any other...
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 30/42
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 31/42
Resources
github.com/wvanderdeijl/adf-seleniumwww.seleniumhq.org - mostly v1 docs
seleniumhq.github.io/docs/ - new v2 docs
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 32/42
Demo shots(reference material)
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 33/42
Example Test Start test in Taskflow Tester
Ba
Compare screenshot
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 34/42
Taskflow r
Taskflow T
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 35/42
Validation Erro
triggered by tes
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 36/42
JUnit Test Runner in JDeveloper
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 37/42
JaCoCo Code Coverage Report
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 38/42
JaCoCo Co
shows this m
covere
Not all paths tested
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 39/42
Screenshot Diff Assertion Violation
Tested application looks different
during test compared to “known
good reference”
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 40/42
“Known good
reference”
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 41/42
Actual screen
during test
8/17/2019 CON2866_van Der Deijl-Automated Testing
http://slidepdf.com/reader/full/con2866van-der-deijl-automated-testing 42/42
Diffs indicated
Top Related