Skip to main content
Fannie Mae Confidential and Proprietary
BDD With Selenide
Hima Bindu Peteti
Saucecon 2019
0
2
HIMA BINDU PETETI
Senior Software Engineer
Experienced in designing and developing large scale web
applications and designing complex test automation frameworks
using Java / JEE technologies.
Passionate about open-source automation frameworks
that provide application modeling, unit, integration, functional, and
visual testing.
Contact me at
linkedin.com/in/hima-bindu-peteti-378152a4
Agenda BDD in the context of test
automation
01
Selenium Vs Selenide02
Selenide deep dive
03
04
05
06
Additional Selenide benefits
Compare coding in Selenium and
Selenide
Design Patterns
Fannie Mae Confidential and Proprietary 3
Bridging the gap between Business and Technology
Fannie Mae Confidential and Proprietary 4
Business
Technology
BDD in the context of Test Automation
Features Examples
Executable
Specification’s
Low level
Specifications
Business
Goals
Automate Examples using
tools like
Cucumber
JBEHAVE
Specflow
You can use
Conventional UNIT
testing or dedicated
BDD for this
These specs are
generated using a
common language
Fannie Mae Confidential and Proprietary 5
Build The
Thing
Right
Build The
right
thing
BDD in the context of Test Automation
SCENARIO
Books can be added to the shopping cart
Given my shopping cart is empty
When I add the book ā€œHarry Potterā€ to my
shopping cart
Then my shopping cart should contain 1
copy
of ā€œHarry Potterā€
SCENARIO
Books can be removed from the shopping cart
SCENARIO
Shopping cart is initially empty
SCENARIO
The same book can be added multiple times to the
shopping cart
Manage books in shopping
cart
As a shop visitor…
I want to collect books in my
shopping cart…
So that I can purchase
multiple books at once…
Feature
Fannie Mae Confidential and Proprietary 6
Evolution of UI Automation
2004 2006 Since 2008 Since 2008
Protractor , Selenide,
ng webdriver,
Fluent Selenium
Protractor, Selenide
Simon Stewart at
ThoughtWorks
developed Selenium
WebDriver
Selenium WebDriver
Jason Huggins -
ThoughtWorks started
Selenium RC and IDE
Selenium RC
Many add on's have
been developed on top
of Selenium
WebDriver IO
1980’s
Record and Play
Automation tools
Fannie Mae Confidential and Proprietary 7
Basic needs of UI automation
Designed
for Test
automation
Executes
on multiple
operating
systems
Multi
browser
execution
Supports
Multiple
test
framework
s
CICD and
build tools
integration
Remote
execution
support
Fannie Mae Confidential and Proprietary 8
Fannie Mae Confidential and Proprietary 9
Selenide Test
Fannie Mae Confidential and Proprietary 10
Customization
Fannie Mae Confidential and Proprietary 11
BDD With Selenide
Fannie Mae Confidential and Proprietary 12
Writing
Test Code
that
matters
Selenide Additional Benefits
13
Solves the problem of
time out issues
No more Stale
Exceptions
Inbuilt evidence
capturing mechanism
Inbuilt validation
mechanism
Additional UI locators
Reduces the need of
adding lot of third party
libraries
Concise API
Reduces the need of
writing Boiler plate
code
Fannie Mae Confidential and Proprietary
open("https://saucecon.co
m/");
$(byText("AGENDA")).clic
k();
$(byText("ABOUT")).shou
ldBe(Condition.visible)
Additional Selectors
Fannie Mae Confidential and Proprietary 14
import static com.codeborne.selenide.Selectors.*;
Parent / Child Selectors
Fannie Mae Confidential and Proprietary 15
Find data in a table row by
content
jQuery Sizzle Selectors
$$(":input").shouldBe(CollectionCondition.sizeGreaterThan(3));
$("input:first").shouldBe(Condition.readonly);
$("input:nth(1)").shouldNotHave(Condition.enabled);
Fannie Mae Confidential and Proprietary 16
Angular libraries
Fannie Mae Confidential and Proprietary 17
Angular Support
Fannie Mae Confidential and Proprietary 18
$(ByAngular.buttonText("Customer Login")).click();
$(ByAngular.cssContainingText("#CSSSelector","ExpectedText")).
getSelectedOptions();
$(ByAngular.exactRepeater("ngrepeater")).data("RepeaterData").
contentEquals("Expected Data");
$(ByAngular.model(("ng-model")).cssSelector("CSS Selector").linkText("Select
Angular")).shouldNotBe(Condition.empty);
Custom Matchers
Fannie Mae Confidential and Proprietary 19
Radio Buttons
Traditional Style:
for(webElement radio: driver.findElement (By.name(ā€œAdmin Roleā€)))
{
if(ā€œAdmin Roleā€.equals(radio.getAttribute(ā€œvalueā€)))
{
radio.click();
}
}
throw new NoSuchElementException(ā€œRadio field has no value);
Selenide Way:
selectRadio(By.name(ā€œroleā€),ā€Admin Roleā€);
Fannie Mae Confidential and Proprietary 20
List Boxes
Traditional Style
List<WebElement> fields = previewPricePage.getAllTableFields();
for(int i = 0; i < fields.size(); i++)
{
if(fields.get(i).getText().matches("[0-9.]+")) break;
else{ if(fields.get(i).getText().equals(col1))
Assert.assertEquals(col2,fields.get(i+1).getText());
}
}
Selenide List Box:
$(ā€œBy.idā€).shouldHave(ā€œExpected Textā€);
Fannie Mae Confidential and Proprietary 21
Alert Boxes
Traditional Style:
try {
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
} catch (Exception e) {
e.printStackTrace();
}
Selenide:
confirm(ā€œAre you sure to delete your profileā€);
dismiss(ā€œText on the dismiss boxā€);
Fannie Mae Confidential and Proprietary 22
More Functions
Fannie Mae Confidential and Proprietary 23
Function Function
$(ā€œdivā€).scrollTo(); $(ā€œdivā€).innerText();
$(ā€œdivā€).innerHtml(); $(ā€œdivā€).exists();
$(ā€œselectā€).isImage(); $(ā€œselectā€).getSelectedText();
$(ā€œselectā€).getSelectedValue(); $(ā€œdivā€).doubleClick();
$(ā€œdivā€).contextClick(); $(ā€œdivā€).hover();
$(ā€œdivā€).dragAndDrop(); Zoom(2.5);
Selenide Collections
$$ returns collection of elements
$$(ā€œ.errorā€).shouldHave(size(3));
$$(":input").shouldBe(CollectionCondition.sizeGreaterThan(3));
$$(ā€œ#employees tbody trā€).shouldNotHave(texts (ā€œEmployeeā€ , ā€œID : 222ā€ ā€œAdmin_Roleā€));
$$(ā€œ#employees tbody trā€).filter(visible).shouldHave(size(4));
Fannie Mae Confidential and Proprietary 24
Selenide Collections
$$(By.xpath("XPATH")).shouldHaveSize(1); (Verifies size)
$$(By.xpath("")).shouldHave(CollectionCondition.texts("Expected
Text"));
$$(".element").shouldHave(sizeLessThan(13));
$$(".element").shouldHave(sizeGreaterThan(11));
$$(".element").shouldHave(sizeGreaterThanOrEqual(12));
$$(".element").shouldHave(sizeNotEqual(42));
Fannie Mae Confidential and Proprietary 25
File Downloads
Fannie Mae Confidential and Proprietary 26
Compare Files
Fannie Mae Confidential and Proprietary 27
File Operations
Fannie Mae Confidential and Proprietary 28
$(".btn#cv").download().compareTo(ExpectedFile);
ü loanDetails_PDF.getParentFile();
ü loanDetails_PDF.isDirectory();
ü loanDetails_PDF.length();
ü loanDetails_PDF.getPath();
ü loanDetails_PDF.canRead();
ü loanDetails_PDF.canWrite();
ü loanDetails_PDF.canExecute();
ü File.createTempFile("prefix", "suffix");
File Operations
Fannie Mae Confidential and Proprietary 29
sellerDetails = $(".btn#cv").uploadFile(uploadFile);
$(".btn#cv").uploadFile(new File("CV1.doc"),
new File("CV2.doc"),
new File("CV3.doc"));
$(".btn#cv").uploadFromClasspath(fileName);
Page Object Design Pattern
Actual Test Class
Fannie Mae Confidential and Proprietary 30
Classic Page Objects
Fannie Mae Confidential and Proprietary 31
Fannie Mae Confidential and Proprietary 32
Fannie Mae Confidential and Proprietary 33
Return On Investment
End to End Test
Integration Test
Unit Tests
Manual Checking
Exploratory
UI Based
Workflow Tests
API/ Service Layer
Business Rules/
Functional Tests
Unit Tests/ Component Tests
80-90%
5-15%
0-5%
5-10%
20-30%
80-85%
Traditional
TDD and BDD
Fannie Mae Confidential and Proprietary 34
Return On Investment
40%
Reduction in
coding effort
Concise API
With Selenide’s Concise API your coding effort is
reduced by 40% or more depending on the application
under test, thereby improves maintainability.
30%
Increase in script
reliability
As Selenide is built for the purpose of test automation, it
supports lot of additional application specific locators
which increases reliability of your executions.
Fannie Mae Confidential and Proprietary 35
Resources
Fannie Mae Confidential and Proprietary 36
Selenide Articles:
Selenide CheatSheet: https://gist.github.com/mkpythonanywhereblog/947633ba1bf0bc239639
Selenide Official site: https://selenide.org/quick-start.html
Selenide JavaDoc: https://selenide.org/javadoc/current/
https://zeroturnaround.com/rebellabs/if-you-use-selenium-for-browser-based-ui-acceptance-testing-you-might-like-
selenide/
Selenide Code reference:
Selenide Git Repo: https://github.com/selenide/selenide
Selenide Change Log: https://github.com/selenide/selenide/blob/master/CHANGELOG.md
Selenide Example projects: https://github.com/selenide-examples
Fannie Mae Confidential and Proprietary
BDD With Selenide is all about
Writing Software that not only works but matters.
Hima Bindu Peteti
linkedin.com/in/hima-bindu-peteti-378152a4