- Notifications
You must be signed in to change notification settings - Fork12
Jest environment for running Selenium WebDriver tests
License
applitools/jest-environment-selenium
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Jest environment for running Selenium WebDriver tests
I like usingyarn for installations.
yarn add -D jest-environment-seleniumBut npm works too!
npm install --save-dev jest-environment-seleniumAdd this to thepackage.json:
"jest":{"testEnvironment":"jest-environment-selenium","setupTestFrameworkScriptFile":"jest-environment-selenium/dist/setup.js"}
By default tests will run against a localchromedriver, but you can easily specify something else.
"jest":{"testEnvironmentOptions":{"capabilities":{"browserName":"firefox"},"server":"http://localhost:4444/wd/hub","proxyType":"manual","proxyOptions":{"https":"http://127.0.0.1:3218"}}}
Tests will be initialized with adriver according to the options (or a default chrome one)
test('load wikipedia',()=>{driver.get('https://en.wikipedia.org/wiki/Base64');});
Kills the used session and starts a new one.
afterEach(async()=>(cleanup()));
Failing to callcleanup will result in non "idempotent" tests, which reuse the same WebDriver session (which can lead to difficult to debug errors in your tests).
Since the tests areasync make sure you return aPromise so thatjest won't bail early
test('load wikipedia',()=>{driver.get('https://en.wikipedia.org/wiki/Base64');returndriver.getTitle().then(title=>{expect(title).toBeDefined();});});
Custom WebDriver matchers designed for ease of use with jest
toBePresent checks that an element appears on a page, it expects to receive aWebElementPromise
test('link appears in the page',()=>{driver.get('https://en.wikipedia.org/wiki/Base64');returnexpect(driver.findElements(By.linkText("binary-to-text encoding"))).resolves.toBePresent();});
toBeChecked checks that a checkbox is checked (many checks wow! 😱), it expects to receive aWebElementPromise
test('a checkbox is checked',()=>{driver.get('somewhere');returnexpect(driver.findElements(By.css('input[type="checkbox"]'))).resolves.toBeChecked();});
toBeEditable checks that an input is editable (enabled and not readonly), it expects to receive aWebElementPromise
test('an input is editable',()=>{driver.get('somewhere');returnexpect(driver.findElements(By.css('input'))).resolves.toBeEditable();});
toHaveValue checks that an input value is what you expect, it expects to receive aWebElementPromise
test('an input has the value',()=>{driver.get('somewhere');returnexpect(driver.findElements(By.css('input'))).resolves.toHaveValue('test');});
toHaveValue checks that a select value is what you expect (will fail on other inputs), it expects to receive aWebElementPromise
test('a select has the right value',()=>{driver.get('somewhere');returnexpect(driver.findElements(By.css('select'))).resolves.toHaveSelectedValue('test');});
toHaveValue checks that an elementinnetText is what you expect, it expects to receive aWebElementPromise
test('the paragraph has the correct text',()=>{driver.get('somewhere');returnexpect(driver.findElements(By.css('p'))).resolves.toHaveText('some nice text, maybe lorem ipsum');});
About
Jest environment for running Selenium WebDriver tests
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.