Code Monkey home page Code Monkey logo

faltest's Introduction

FalTest

A different take on WebDriver browser testing

Requirements

Make sure Node.js 14.15+ is installed.

Setup

Run the following command to install FalTest globally.

npm install --global @faltest/cli

Usage

Here are a couple examples of using the FalTest CLI.

  • faltest --tag admin !smoke --filter "^Visit .*"
  • faltest --env dev --tag smoke --share-session --headless

Default Options

Options:
  --help                          Show help                            [boolean]
  --version                       Show version number                  [boolean]
  --browser                       Type of browser to run
             [string] [choices: "chrome", "firefox", "edge"] [default: "chrome"]
  --browsers                      Number of browsers to run         [default: 1]
  --port                          Port for WebDriver     [string] [default: "0"]
  --headless                      Run browser in headless mode
                                                      [boolean] [default: false]
  --retries                       When all else fails, try again!   [default: 0]
  --target                        Run against a different UI server/URL
                              [string] [choices: "default"] [default: "default"]
  --env, --environment            Run against a different data source
                              [string] [choices: "default"] [default: "default"]
  --share-webdriver               Keep the WebDriver process open between test
                                  runs                 [boolean] [default: true]
  --keep-browser-open             Keep the browser open between test runs (sets
                                  --share-webdriver)  [boolean] [default: false]
  --share-session                 Keep the session (login, etc.) between test
                                  runs (sets --share-webdriver and
                                  --keep-browser-open)[boolean] [default: false]
  --size                          Override the browser size. ex. "--size 1024
                                  768"
  --throttle-network              Slow down the network so you can see the
                                  loading states better
                                                      [boolean] [default: false]
  --tag                           Filter groups of tests using the #hash tagging
                                  system (hashes are optional). Prefix with ! to
                                  negate.      [array] [choices: ] [default: []]
  --filter                        Filter the tests by name using a pattern
                                                        [string] [default: ".*"]
  --duplicate                     Run the same test concurrently to simulate
                                  multiple users running tests at once
                                                                    [default: 0]
  --random                        Randomise test order[boolean] [default: false]
  --seed                          Set the random seed to reproduce test order
                                                                        [string]
  --timeouts-override             Override all Mocha timeouts for debugging
                                  purposes
  --disable-timeouts              Disable all Mocha timeouts for debugging
                                  purposes            [boolean] [default: false]
  --disable-cleanup               Disables all browser cleanup. Run
                                  `faltest-kill-orphans` to clean up manually.
                                                      [boolean] [default: false]
  --failure-artifacts             Save screenshots, html, and logs on test
                                  failure             [boolean] [default: false]
  --failure-artifacts-output-dir  Location to save failure artifacts    [string]
  --reporter                      Change the Mocha reporter             [string]
  --reporter-options              Supply Mocha reporter options         [string]
  --dry-run                       List the tests that would have run instead of
                                  actually running them
                                                      [boolean] [default: false]

Filtering

There are a couple ways to filter tests, --tag and --filter. Tags are predefined categories you can add to narrow down your test run. This includes filtering by roles. You can also prefix a ! to a tag (ex. --tag !smoke) if you want to exclude it. If you are using Bash, you may need to escape the exclamation mark (ex. --tag \!smoke). The filter is a regular expression that can match test names. You can combine both these options.

Filtering by tags is a little different between roles and other tags. Since a test only ever has one role at a time attached to it, --tag role1 role2 would never match any tests, since tags function as a logical AND and not an OR. On the other hand, tests can be attached to more than one tag. In this case, --tag tag1 tag2 would target those tests only, and exclude the tests focusing on either tag exclusively.

Duplicating

You can duplicate you test suite to run concurrently with --duplicate 1. This is a good way to ensure that your tests work when multiple people are running them at the same time. If you wanted to run three suites at once, you would use --duplicate 2 to run two copies of your original run.

Logging

Logging can be accomplished via the DEBUG environment variable (https://github.com/visionmedia/debug). Supported variables are:

  • @faltest/remote,@faltest/lifecycle,... - basic logging
  • @faltest/remote:verbose,... - verbose logging only
  • @faltest* - all logging

An example use would be DEBUG=@faltest* faltest --tag smoke.

Failure Artifacts

Using the options --failure-artifacts and --failure-artifacts-output-dir, you can get screenshots, html, and browser logs of test failures.

Browser Versions

To override the ChromeDriver and EdgeDriver version to match your Chrome and Edge version, follow the guide here or here or here. For example:

DETECT_CHROMEDRIVER_VERSION=true DETECT_EDGEDRIVER_VERSION=true npm install

Real-world Examples

Contributing

If you need to change FalTest, see Contributing Guide.

faltest's People

Contributors

dependabot[bot] avatar epfremmer avatar kellyselden avatar nathanjcbernhardt avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

faltest's Issues

Should --role be extracted from --tag?

The reason --env is separate from --tag is because you only ever run one env at a time. The same is true for roles. Perhaps this is a indicator that roles should be separate too?

Provide insight when exceptions happen

For example, on emberclear, I get the following output:

link: https://github.com/NullVoxPopuli/emberclear/pull/279/checks?check_run_id=641002972

 1) chat
       New users can add each other and then communicate
         fresh users can begin communicating with each other:
     waitForInsert: waitForInsert([data-clipboard-text]): waitUntil condition timed out after 30000ms
      at Browser.waitForExist [as waitForInsert] (node_modules/@faltest/browser/index.js:321:15)

This really doesn't tell me anything. It'd be great to know the current state of the browser / dom / screenshots or whatever so that the C.I. log is useful.

try supporting ^tag as well as !tag

because sometimes you need to escape the ! with --tag '!tag'. It may be useful in this case to alias the sigil with another, like –tag ^tag.

Is there a getting started guide?

I'm wanting to use all the bells and whistles, and I'm having a bunch of trouble.

  • how do I properly setup the chai plugin?
  • how do I integrate this with C.I.?
  • etc?

I'm learning these via lots of googling, but it'd be nice to have everything all in one place, maybe on a docs site or something.

Add base url option

Instead of adding a bunch of --envs to get different urls, we could also allow a base url option to target any number of urls.

writing-tests.md out of date?

I see :

const { setUpWebDriver } = require('@faltest/mocha');

but isn't that supposed to be from @faltest/lifecycle?

How do I add new targets / envs?

atm, I have this:

describe('smoke', function() {
  before(async function() {
    switch (process.env.WEBDRIVER_TARGET) {
      case 'pull-request': {
        console.info('---- DEPLOY PREVIEW ----');
        console.info(process.env.DEPLOY_URL);

        this.host = process.env.DEPLOY_URL;

        if (!this.host) {
          throw new Error(`host not set. Did you forget to set $DEPLOY_URL?`);
        }

        break;
      }
      case 'local': {
        let { server, port } = await startServer();

        this.server = server;

        this.host = `http://localhost:${port}`;

        break;
      }
      case 'ember': {
        this.host = `https://localhost:4201`;

        break;
      }
      default: {
        this.host = 'https://emberclear.io';

        break;
      }
    }
  });

and only pull-request, local, and default are allowed targets., so I actually need to comment/uncomment stuff to swap between local and ember.

I ran this command:

C:\Program Files\Volta\bin\node.exe --inspect-brk=49376 node_modules\@faltest\cli\bin\index.js --browsers 2 --timeouts-override 900000 --target ember 

Documentation on how to run / filter the internal test suite

S far my experiments concluded that adding .only after it in the internal test suite (e.g: packages/mocha/test/acceptance/index-test.js) does not filter the tests being run via yarn test. So I just trial-and-errored on:

npx mocha packages/mocha/test/acceptance/index-test.js
  • Is there a better way to run the internal test suite?
  • Should that be documented somewhere?
  • Shall that have an explicit term (I see "internal test suite" mentioned once in the source code)

getAttribute may not work?

I have this code in a page object:

  get inviteUrl() {
    let dataAttr = 'data-clipboard-text';
    let element = this._create(`[${dataAttr}]`);

    return element.getAttribute(dataAttr);
  }

and I placed a breakpoint on the return, and in the VS Code console, I did:

element.getAttribute('[data-clipboard-text]').then(console.log)
Promise { pending }
element.getAttribute('data-clipboard-text').then(console.log)
Promise { pending }
// results:
undefined
undefined

so, the element exists, and is selectable by attribute, but I can't get the attribute value? maybe?

anything look obviously wrong?
I have a WIP PR: here: NullVoxPopuli/emberclear#279

something unrelated, (if anyone tries to debug this), is that I have interactions that don't seem to finish before moving on to the next step, but also somehow don't fail?
I seem to only be able to get the test moving along by setting these breakpoints:
image

any help is much appreciated <3

yargs strict appears to not be working

I watched someone provide --disable-timeout instead of --disable-timeouts. Yargs should say unrecognised option because we set strict mode, but it didn't.

Expand the description

Thank you for all the hard work ⭐️. It would be nice if we could have the description be a bit longer. The current description reads:

A different take on WebDriver browser testing

As a complete novice I’m not entirely sure what this means. As a veteran WebDriver user I would like to know what the differences are. Could this perhaps be expanded upon?

README could use some more content

I am mostly curious if this project uses webdriver

In the readme it doesn't explain too much about this project, I don't know why I would use this project over others.

handle webdriver quiting mid-test

If you kill webdriver (chromedriver) while tests are running, the test errors don't help you figure out what's wrong. The first test will show:

connect ECONNREFUSED 127.0.0.1:45244

and the following tests will show something like

TypeError: Cannot read property '0' of null
    at Context.setUpWebDriverBeforeEach (/foo/node_modules/@faltest/lifecycle/src/index.js:175:32)

Solve headless "Chrome Safe Storage" issue.

When running headless locally, you often get the popup "Google Chrome wants to use your confidential information stored in ’Chrome Safe Storage’ in your keychain. Do you want to allow access to this item?".

You can ignore it and all tests will pass normally, but if you deny it, it fails the current and subsequent tests. I'm not sure clicking "Always allow" is the best solution since you can ignore and tests pass. We may be able to start chrome with a flag to disable?

I found more info at the bottom of https://docs.parasoft.com/display/SOA9103/Web+Functional+Testing+-+Overview.

Document purgeOld

Took me a bit to get through purgeOld method to implement it properly. There are few things that are not obvious:

  • When you add new record, you want to use name = Rows.encodeString('something')
  • When you call purgeOld, you don't want to use encodeString: await rules.table.rows.purgeOld(['something]);
  • Why is there timeout and what does it do? Why would I want to implement this method / What are the common use-cases?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.