UI Testing with Selenium and Node
​Keir Bowden
​CTO, BrightGen
​keirbowden@brightgen.com
​@bob_buzzard
​
Selenium
​Automates Browsers
• That's it!
​Primary use case is testing
• Typically brittle and non-comprehensive
• Covers a lot of bases
WebDriver
Remote control interface
Introspection and control of user agent
Platform and language neutral
Test framework agnostic
Local or remote server
selenium-webdriver
​Node module
Official Selenium implementation
• 4.0.0-alpha.1
Other implementations are available - e.g. webdriver.io
Demo
Login to Salesforce
Promise Manager
Looks synchronous :
Promise Manager
Is not synchronous
Promise Manager
Resolve promises
Key Functions
WebDriver.get(<url>)
• Opens URL in remote control browser
WebDriver.wait(until.<condition>, <timeout>)
• waits for something, for <timeout> millseconds
WebDriver.findElement(By.<mechanism>)
• Locates element on page
• By - name, className, id, css, xpath
Key Functions
WebElement.sendKeys(<key sequence>)
• Types key sequence in DOM element
• Modifier keys are supported (SHIFT, CONTROL, ALT, META)
WebElement.click()
• Clicks on a DOM element
WebElement.findElement(By.<mechanism>)
• Locates descendant element
Demo
Create an opportunity
https://medium.com/rate-engineering/a-guide-to-working-with-shadow-dom-using-selenium-b124992559f
Web Components - Shadow DOM
Not accessible via
webdriver.findElement()
Shadow Host
shadowHost = driver.findElement(...);
driver.executeScript("return arguments[0].shadowRoot",
shadowHost);
Lightning Web Components
Nothing!
Does not use native shadow DOM - yet!
Tests will break after switch
Demo
Lightning Web Component
Search Contacts
Key Takeaways (1)
Add one item at a time
Test after each item
Keep scenarios short
Use modules
Baby Steps!
Key Takeaways (2)
Use XPath
//label/span[contains(text(), "Opportunity Name")]/../../input
//label - any descendant node containing a label
/span - containing a span
[contains(text() - whose text contains
/../.. - whose grandparent node
"Opportunity Name"] - this string literal
/input - contains an input element
XPath
<div ... >
<label ...>
<span ...>Opportunity Name</span>
<span ...>*</span>
</label>
<input ...>
</div>
XPath
Test in Browser
Useful Links
bobbuzz.me.uk/selenium - Selenium HQ
bobbuzz.me.uk/2GPuDVS - selenium-webdriver node package
bobbuzz.me.uk/LC2019Repo - Example repo from this talk
bobbuzz.me.uk/2SIISTP - Selenium and the Shadow DOM
Q & A
Thank You
​Keir Bowden
​CTO, BrightGen
​keirbowden@brightgen.com
​@bob_buzzard
​
Remember to tell us what you think in the event survey
www.LondonsCalling.net/survey/

UI Testing with Selenium and Node - London's Calling 2019