selenidejs
Test-oriented Wrapper for Selenium Webdriver
Last updated 5 months ago by knowledgeexpert .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install selenidejs 
SYNC missed versions from official npm registry.

Build Status Coverage Status NPM Version NPM Downloads Per MonthJoin the chat at https://t.me/js_for_testing

SelenideJS

Wrapper for Selenium WebDriver, which provides testing user-oriented API for writing stable and readable UI tests in JavaScript/TypeScript.

Prerequisites

Nodejs 8+

Installing

Install selenidejs via npm to your project:

npm i --save-dev selenidejs

Usage

Set your webdriver instance:

import { Browser } from "selenidejs";
const webDriverInstance = ...;
const browser = Browser.drivedBy(webDriverInstance).build();

And you are ready to go!

Quick Start and Examples

Basic API

GIVEN

    import { Builder, Capabilities } from 'selenium-webdriver';
    const webdriver = new Builder().withCapabilities(Capabilities.chrome()).build()

WHEN


    import { Browser } from 'selenidejs';

    const browser = Browser.configuredWith()
        .driver(webdriver)
        .baseUrl('https://google.com')
        .timeout(4000)
        .build();

    // OR:
    // browser = Browser.drivedBy(webdriver).timeout(4000).baseUrl('https://google.com').build();

    // OR:
    // browser = Browser.chromeWith().timeout(4000).baseUrl('https://google.com').build();

    // OR:
    // browser = Browser.chrome(); //if you are ok with defaults for baseUrl and timeout

AND

    await browser.open('/ncr');

AND

    // await browser.element('[name=q]')).setValue('selenium');
    // OR:

    import { by } from 'selenidejs';

    const query = browser.element(by.name('q')); // actual search does not start here, the element is lazy
    await query.setValue('selenium')              // here the actual webelement is found
    await query.pressEnter();                    // here the actual webelement is found again

AND

    // in case we need to filter collection of items by some condition like visibility:

    import { be } from 'selenidejs';

    const results = browser.all('.srg .g').filteredBy(be.visible);


THEN
```typescript
    import { have } from 'selenidejs';

    await results.should(have.size(10));
    await results.first.should(have.text('Selenium automates browsers'));

FINALLY

    await browser.quit();

More advanced tricks

    // OR just in case you like the "flow"
    import { find, should } from 'selenidejs';

    await browser.all('.srg .g').should(have.size(10))
        .then(find.first)
        .then(should.match(have.text('Selenium automates browsers')));

    // OR:
    import { perform } from 'selenidejs';

        await browser.element(by.name('q')).setValue('selenium').then(perform.pressEnter);

    // instead of
    const query = browser.element(by.name('q'));
    await query.setValue('selenium')
    await query.pressEnter();

Not sure when you will need it, but just in case:) ...

    import { get } from 'selenidejs';

    const iWillRememberYourTextOnceReady =
        await browser.element('#i-change-my-text-on-hover').hover().then(get.someText)

You might think you need something like...

    import { its } from 'selenidejs';

    if (await browser.element('#i-might-say-yes-or-no').get(its.text) === 'yes') {
        // do something...
    }

Or...

    import { their } from 'selenidejs';

    if (await browser.all('.option').get(their.size) >= 2) {
        // do something...
    }

Maybe one day, you really find a use case:) But for above cases, probably easier would be:

    if (await browser.element('#i-might-say-yes-or-no').waitUntil(have.text('yes'))) {
        // do something...
    }
    ...
    if (await browser.all('.i-will-appear').waitUntil(have.sizeMoreThanOrEqual(2))) {
        // do something...
    }

Or, by using non-waiting versions, if "you are in a rush":)...

    if (await browser.element('#i-might-say-yes-or-no').matching(have.text('yes'))) {
        // do something...
    }
    ...
    if (await browser.all('.i-will-appear').matching(have.sizeMoreThanOrEqual(2))) {
        // do something...
    }

In case you want to be different) ...

   const browser = new Browser(Configuration.withDriver(driver).timeout(4000).build());

Tutorials

You can start with Typescript or Javascript tutorial to get familiar with basic and some advanced features of Selenidejs. Using Typescript is recommended when writing tests (it will enable IDE's autocompletion features, compile-time checks, etc. since Selenidejs itself written in Typescript), but you still can use Javascript.

Typescript tutorial can be found here.

Javascript tutorial can be found here.

API Documentation

Generated API documentation can be found here.

For Contributors

Guide

please read contributing for details on our code of conduct, and the process for submitting pull requests to us.

Running the tests

Prerequisites

  • google chrome is installed locally

run unit and integration tests:

npm test

run code style test

run ts linter:

npm run lint

Versioning

we use npm for versioning. for the versions available, see the npm or github releases.

Authors

see also the full list of current contributors who participated in this project.

License

this project is licensed under the Apache-2.0 License - see the LICENSE file for details

Current Tags

  • 1.2.0-beta.0                                ...           beta (3 months ago)
  • 1.1.0                                ...           latest (5 months ago)

15 Versions

  • 1.2.0-beta.0                                ...           3 months ago
  • 1.1.0                                ...           5 months ago
  • 1.0.0                                ...           5 months ago
  • 0.2.8                                ...           8 months ago
  • 0.2.7                                ...           8 months ago
  • 0.2.6                                ...           8 months ago
  • 0.2.5                                ...           8 months ago
  • 0.2.4                                ...           9 months ago
  • 0.2.3                                ...           9 months ago
  • 0.2.2                                ...           10 months ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 33
Dependencies (7)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |