https://github.com/simple-automation-testing/promod
Library for browser manipulation
https://github.com/simple-automation-testing/promod
aqa automated-testing automation-selenium js nodejs testing
Last synced: 17 days ago
JSON representation
Library for browser manipulation
- Host: GitHub
- URL: https://github.com/simple-automation-testing/promod
- Owner: Simple-Automation-Testing
- License: mit
- Created: 2021-08-13T05:40:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-18T07:59:26.000Z (about 1 year ago)
- Last Synced: 2025-02-01T15:11:27.234Z (about 1 year ago)
- Topics: aqa, automated-testing, automation-selenium, js, nodejs, testing
- Language: TypeScript
- Homepage:
- Size: 1.34 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# promod
Browser automation library with a unified API over [Playwright](https://playwright.dev/) and [Selenium WebDriver](https://www.selenium.dev/documentation/webdriver/).
Promod provides a **protractor-like** lazy element interface — elements are not resolved until an action is performed on them.
## Installation
```bash
npm install promod
```
Promod requires a browser engine as a peer dependency:
```bash
# For Playwright
npm install playwright
# For Selenium WebDriver
npm install selenium-webdriver chromedriver
```
## Quick start
### Playwright
```js
const { chromium } = require('playwright');
const { playwrightWD } = require('promod');
const { browser, $, $$ } = playwrightWD;
async function main() {
const launched = await chromium.launch({ headless: false });
browser.setClient({ driver: launched });
await browser.get('https://example.com');
const heading = $('h1');
console.log(await heading.getText());
await browser.quitAll();
}
main();
```
### Selenium WebDriver
```js
const { Browser, Builder } = require('selenium-webdriver');
require('chromedriver');
const { seleniumWD } = require('promod');
const { browser, $, $$ } = seleniumWD;
async function main() {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
browser.setClient({
driver,
lauchNewInstance: () => new Builder().forBrowser(Browser.CHROME).build(),
});
await browser.get('https://example.com');
const heading = $('h1');
console.log(await heading.getText());
await browser.quit();
}
main();
```
## ESM / CommonJS
Promod ships dual builds. Bundlers and Node `import` will use ESM; `require()` will use CommonJS.
```js
// ESM
import { playwrightWD, seleniumWD } from 'promod';
// CommonJS
const { playwrightWD, seleniumWD } = require('promod');
```
## Selector strategies
All examples work identically with both `playwrightWD` and `seleniumWD`.
```js
// CSS (default)
const el = $('.my-class #id a[href*="link"]');
// XPath
const el = $('xpath=.//div[@data-test="id"]/span');
// JavaScript function
const el = $(() => document.querySelector('div > span'));
// Custom selector (query + text filter)
const el = $({ query: 'button', text: 'Submit' });
const el = $({ query: 'button', rg: 'Sub.*' }); // regex filter
```
## API
| Topic | Link |
| --- | --- |
| Engine setup | [docs/init.md](./docs/init.md) |
| Browser (client) | [docs/client.md](./docs/client.md) |
| Element (`$`) | [docs/element.md](./docs/element.md) |
| Elements (`$$`) | [docs/elements.md](./docs/elements.md) |
## License
MIT