git clone https://github.com/aaronchen/lutkar.git
cd lutkar
npm install
Lutkar is based on puppeteer
, and uses puppeteer-extra
and puppeteer-extra-plugin
to enhance its automation features.
It overrides Page and Frame objects to add additional methods, bring in implicit wait, and minimizes the need to use explicit wait.
It also overrides ElementHandle to add more Element methods.
mocha
and chai
are the libraries used to manage test suites/cases, and mochawesome
for test reports.
helpers/
:- chromium.js: Chromium browser with Lutkar plugin
- mocha.js: Mocha Hook and global variables for test suites
- Utils.js: Utilities
- YML.js: Read YAML
pages/
: Page objectsplugins/
:- lutkar.js: Lutkar plugin (puppeteer-extra-plugin)
lutkar/
- LutkarBrowser.js: Extend
Browser
functionality - LutkarElement.js: Extend
ElementHandle
functionality - LutkarFrame.js: Extend
Frame
functionality - LutkarHelper.js: Helper
- LutkarPage.js: Extend
Page
functionality - LutkarPageFrame.js: Extend common
Page
andFrame
functionality - LutkarTarget.js: Extend
Target
functionality - Storage.js: Add
localStorage
andsessionStorage
methods toPage
- LutkarBrowser.js: Extend
test/
: Test suites (*.spec.js)- .mocharc.yml:
mocha
configuration
.mocharc.yml
and helpers/mocha.js
are configured for easy test suite creation.
// Create the following test suite in test/google.spec.js,
// and execute `npm test` to run automation test and generate the report.
describe('Google', function () {
it('can search puppeteer and mark its page navigation', async function () {
await page.goto('https://www.google.com')
await page.type('[name="q"]', 'puppeteer')
await page.keyboard.press('Enter')
await page.scrollIntoView('#footcnt')
await page.drawRectangle('[role="navigation"] table')
await page.screenshot('./screens/google.png')
})
})
// sample.js: Just use chromium.js for automation.
// To run: `node sample.js`
import chromium from './helpers/chromium.js'
const browser = await chromium()
const page = await browser.newPage()
await page.goto('https://www.google.com')
await page.type('[name="q"]', 'puppeteer')
await page.keyboard.press('Enter')
// Navigating to a new page (No explicit wait required)
await page.click('[role="navigation"] .fl:eq(3)') // Go to page 5 of navigation
// Navigating to a new page (No explicit wait required)
const navigation = await page.$('[role="navigation"] table')
await navigation.scrollIntoView()
await navigation.drawRectangle()
await page.screenshot('./screens/google.png') // Screenshot of page 5 navigation
await browser.close()