A GUNet puppeteer Docker image
Important: This is a work in progress
- Puppeteer Documentation
- Puppeteer Docker documentation
- Reference Dockerfile
- Reference
#id
: Selects the element with id="<id>"
div p
: Selects all<p>
elements inside<div>
elements- Easy way to find the selector: Inspect an element (in firefox), right click and select
Copy->CSS Selector
- File:
gunet.js
- Usually common code:
const puppeteer = require('puppeteer');
const gunet = require('./gunet.js');
const url = process.argv.slice(2);
console.log(url[0]);
(async () => {
const browser = await puppeteer.launch(gunet.browserOptions());
const page = await gunet.newPage(browser);
await page.goto(url[0]);
await page.waitForTimeout(1000)
-- Do staff --
await browser.close();
})();
click
- Click a button
- Arguments
page
elementselector
- Example:
await cas.click(page, "#login")
assertVisibility
- Check that an element is actually visible
- Arguments
page
elementselector
- Example:
await cas.assertVisibility(page, '#token')
waitForVisible
- Wait until an element is visible instead of naively waiting for specified time hopping for the page to have loaded
- Arguments
page
elementselector
- Example:
await this.waitForVisible(page, '#username')
assertInnerText
- Check that a certain text is present (with equality check)
- Arguments
page
elementselector
value
to search for
- Example:
await gunet.assertInnerText(page, '#content div h2', "Επιτυχής Σύνδεση");
assertInnerTextContains
- Check that a certain text is present in the selector
- Arguments
page
elementselector
value
to search for
assertTextInSource
- Check that a certain text is present in page source (for instance when handling text/json/xml pages)
- Arguments
page
value
to search for
- Example:
await gunet.assertTextInSource(page,'OAuth2Token');
assertPageTitle
- Check the page title
- Arguments
page
elementvalue
to search for
- Example:
await gunet.assertPageTitle(page, 'SimpleSAMLphp installation page');
type
- Type value in text field
- Arguments
page
elementselector
value
typed
- Example:
await gunet.type(page, "#token",'999666');
submitForm
- Submit Form
- Arguments
page
elementselector
loginWith
- Login with specific username and password
- Arguments
page
elementuser
password
- Example:
await gunet.loginWith(page, process.env.CAS_USER, process.env.CAS_PASSWORD);
assertTicketGrantingCookie
- Check that we received a TickerGrantingCookie (TGT). Only in the CAS login page, not in applications
- Argument:
page
element - Example:
await gunet.assertTicketGrantingCookie(page);
casLogin
- Perform all necessary elements of checking for successful SSO login utilizing a provided web page element.
- Arguments:
page
elementuser
to usepassword
to usecas_type
to use. Can be one ofsimple-cas
for typical CAS (default) orgunet-cas
(for GUNet CAS)cas_lang
to use. Can be one ofen
(default) orel
- Example:
await gunet.casLogin(page, process.env.CAS_USER, process.env.CAS_PASSWORD,process.env.CAS_LANG);
run_test.sh <scenario> <server URL>
: Run a specific specified scenario against the<server URL>
. For example:run_test.sh cas https://host.docker.internal:8443/cas
. Thescenario
is a folder underscenarios/
containing a filescript.js
- Build:
docker compose -f docker-compose.build.yaml build
- If you just want to use
docker run
you can volume mount thescenarios
folder as-v <your scenarios folder>:/home/puppeteer/scenarios
- Your JS script will have to include a
const gunet = require('../gunet.js');
in order to use the GUNet libraries
- Your JS script will have to include a
- You can also extend the base image as (your scenarios are assumed to be in the folder
scenarios
):
FROM gunet/puppeteer:latest
COPY scenarios/ ${PUPPETEER_ROOT}/scenarios/
- Environment variables
CAS_USER
: Username (defaultgunetdemo
)CAS_PASSWORD
: Password (defaultgunetdemo
)CAS_LANG
: The language to assume in the CAS login page. Can been
(default) orel
CAS_TYPE
: The CAS type. Can be one ofsimple-cas
for typical CAS (default) orgunet-cas
(for GUNet CAS)
- Show module version:
docker run --rm ghcr.io/gunet/puppeteer npm list
- General Run:
docker run -it --cap-add=SYS_ADMIN --rm ghcr.io/gunet/puppeteer node --unhandled-rejections=strict <scenario + args>
- Specific scenarios:
cas
:./login.js <SSO BASE URL>
- Using the
run_test.sh
(scenarios ):docker run -it --cap-add=SYS_ADMIN --rm ghcr.io/gunet/puppeteer bash run_test.sh <scenario> <url>
- Arguments
<SSO BASE URL>
: An example might behttps://sso.uoi.gr
orhttps://worker-01.dev.gunet.gr:8443/cas
(in the case ofsimple-cas
)
- Automatic testig with docker compose stack:
docker compose -f <your docker compose stack yaml file> up --exit-code-from <puppeteer service> --attach <puppeteer service
- This will attach only on the puppeteer service output and return the container exit code as the exit code for the whole stack.
- The puppeteer service image might include a script that runs scenarios and returns
exit 1
if one of them fails orexit 0
if all return correctly.
- Disk size:
1.17 GB