1.0.0 • Published 4 years ago

waf-sqtest v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

WAF Test Tool

Web Application Automation Testing Tool

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Installing

Install waf-test package

yarn add waf-test

Create tsconfig.json file

{
  "compilerOptions": {
    "target": "ES5",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "allowJs": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "declaration": true,
    "sourceMap": true,
    "declarationDir": "types",
    "downlevelIteration": true
  }
}

Create testcase files

Create entry point index.ts

import { WafTest } from "waf-test";

(async () => {
  let wafTest = new WafTest();
  await wafTest.run();
})();

Create testcases folder and add testcase files. Ex: testcases/polarisec.ts

import { SequenceTest, TestCase } from "../cmd/sequence";

export default class PolariSec extends SequenceTest {
  async run() {
    await super.run();
    await this.setFilterDomain("polarisec.dev");

    await this.login();

    // change site in security center
    await this.chooseSite("tinhte.vn");
    await this.chooseSite("all sites");
  }

  @TestCase("Login to polaris")
  async login() {
    await this.chrome.goTo("https://polarisec.dev/auth/login");
    await this.page.waitForSelector(
      '#app > div.application--wrap img[alt="Polaris"]'
    );
    let emailInput = await this.page.$("input[type=text]");
    let passwordInput = await this.page.$("input[type=password]");
    let loginButton = await this.page.$(
      "#app > div.application--wrap div.layout.align-center.justify-center.column > button"
    );
    await emailInput.type("user@gmail.com");
    await passwordInput.type("password");
    await loginButton.click();
    await this.page.waitForNavigation({ waitUntil: "networkidle0" });
    await this.chrome.takeScreenshot("login.png");
  }

  @TestCase("Change site to")
  async chooseSite(site: string) {
    let chooseButton = (
      await this.chrome.$$(
        "#app > div.application--wrap > nav > div > button > div.v-btn__content"
      )
    )[1];
    await chooseButton.click();
    await this.page.waitForSelector(
      "#app > div.v-menu__content.theme--light.v-menu__content--fixed.menuable__content__active > div"
    );
    let siteButton = await this.chrome.findElementContainText(
      "#app > div.v-menu__content.theme--light.v-menu__content--fixed.menuable__content__active > div > div[role='listitem']",
      site
    );

    await siteButton.click();
  }
}

Get Help

> ts-node index.ts --help

Output

index.ts

Sequence testing

Options:
  --version      Show version number                                   [boolean]
  --output, -o   output directory                [string] [default: "./outputs"]
  --help, -h     Show help                                             [boolean]
  --headless     run headless mode or not             [boolean] [default: false]
  --test, -t     location of test file                                  [string]
  -v, --verbose  verbose                                                 [count]

Running test

> ts-node index.ts -t ./testcases/*.ts

After running tests, you can see output at ./outputs folder

Built With

Authors