Giter Club home page Giter Club logo

web-automation's Introduction

Web Automation Framework

CircleCI CI Build Status

Boilerplate project to write BDD tests with Cucumber and execute with docker selenium. Tests are written in an ordinary language that bridges the gap between business and technical people. The docker selenium simplifies the setup and avoids any local installation of browser specific dependencies.

Features

  • Simple setup, no need for local preinstalled Selenium Grid and browser drivers
  • Test with Chrome and Firefox with zero configuration
  • Integrated with WebdriverIO
  • BDD tests with Cucumber and over 150 predefined steps
  • Implement custom steps with TypeScript
  • Support for debugging tests
  • Possibility to visually see the execution in browser with VNC
  • Detailed report generation (example)
  • Integration with CI tools

Requirements

  • To run Firefox and Chrome browsers with docker selenium you need:

    • docker
    • docker-compose
  • Tests are executed with Node.js, requires:

    • Node.js version 10 or higher
    • npm version 6 or higher

Quick start

  1. Install dependencies required to run the tests:
npm install
  1. Start docker selenium containers with docker-compose:
# starts the selenium hub and browser nodes in docker containers
npm run selenium
  1. Run the tests and view the report:
# run tests and open the report
npm run test

To stop all the docker containers from step 2:

npm run selenium:stop

Note that selenium containers can be started once and then used across multiple sessions of running and debugging tests.

Test examples

File
./src/features/google.search.feature An example of testing the Google search
./src/features/sample.snippets.feature Samples of using the existing test snippets. Credits Christian Bromann

Adding tests

Tests are written using Gherkin syntax in a fashion that can be used as feature documentation:

# This is a single line comment
Feature: Performing a Google Search

    As a user on the Google search page
    I want to search for Selenium-Webdriver
    Because I want to learn more about it

    Background:
        Given I open the url "https://google.com"

    Scenario: Searching for Selenium Webdriver
        When I set "Selenium Webdriver" to the inputfield "[name=q]"
        And  I press "Enter"
        Then I expect that element "#search" becomes displayed

All tests should be located in ./src/features/* directory with extension .feature (configured in ./config/tests.config.ts).
For a list of predefined and supported steps see files:

  • ./src/steps/given.ts
  • ./src/steps/when.ts
  • ./src/steps/then.ts.

The steps are inspired from cucumber-boilerplate repository.

Implementing custom steps

There are over 150 predefined steps, but in case you need an extra step you can add it in one of the ./src/steps file.
The snippets are defined using regular expressions. It allows to implement powerful and complex sentences. Everything that's within "([^"]*)?" gets captured and appended to the callback.
To access browser functionality, reference the global variable browser which is a WebdriverIO browser instance. See the documentation for a list of supported methods.
Assertions are written using chai.

Browser specific tests

To run a test against a specific browser use predefined tags:

Feature: Performing a Google Search

    ...

    # This scenario will run only in Chrome browser
    @OnlyChrome
    Scenario: Searching in chrome browser
    ...

    # This scenario will run only in Firefox browser
    @OnlyFirefox
    Scenario: Searching in Firefox browser
    ...

Pending tests

To skip a test, use the @Pending tag:

Feature: Performing a Google Search

    ...

    # This scenario will be skipped
    @Pending
    Scenario: Searching for WebdriverIO
    ...

Verbose tests

Currently, a screenshot is attached only for a failing test. In case you want screenshots for a test regardless of its completion status, use the @Verbose tag:

Feature: Performing a Google Search

    ...

    # A screenshot and additional test details will be attached to the report
    @Verbose
    Scenario: Searching for WebdriverIO
    ...

Hooks

Hooks are blocks of code that can run at various points in the Cucumber execution cycle. It is possible to write conditional hooks.
See examples of scenario hooks in ./src/steps/hooks.ts. For a more advanced usage, configure hooks in ./config/hooks.config.ts.

You can customize existing hooks or implement your own. See the WebdriverIO documentation about hooks.

Configurations

Environment variables

The configurable options are set in the .env file.

Variable Usage
SELENIUM_VERSION Configure the version of selenium hub and nodes. Change this version if you want to run tests against a specific browser version. See the list of available selenium releases and browser versions.
SCREEN_WIDTH SCREEN_HEIGHT Configure browser window size.

WebdriverIO options

WebdriverIO specific options are all in ./config directory.
For example, to configure a default url change the baseUrl option in ./config/index.ts:

export const config = {
  runner: 'local',
  baseUrl: 'https://webdriver.io',
  ...

Debugging tests

There is a ./.vscode/launch.json file that has a debugger configuration for Visual Studio Code, but you can enable debugging in any other editor that supports integration with Node.js debugger.

To debug a single feature file:

  • Prerequisites: selenium containers are running (npm run selenium)

  • The .feature file to test is active in VS Code

  • From VS Code Run and Debug menu select the Debug current test option

The test will start and run only the current file. Once started you can navigate to any .ts file and place a breakpoint.

To debug all files follow the same steps but use the Debug all tests option.

VNC support

In some cases, you might need to visually see the execution in the browser. That is possible thanks to docker selenium debug images that have XVFB and VNC server installed. Note that debug images are slower and are intended only for development mode.

Prerequisites

Download on your machine the VNC viewer.

Selenium Debug containers

If you already have docker selenium containers running, stop them:

npm run selenium:stop

Start selenium debug containers that enable the VNC support:

# starts the selenium containers with VNC support
npm run selenium:vnc

VNC connection options

Browser Connection options
Chrome 127.0.0.1:5900
Firefox 127.0.0.1:5901

Now you can connect and enter the remote session.

Running tests

Tests by default run in headless mode so that a browser window is not visually created. To run the tests with enabled browser window:

# runs the tests without headless option
npm run test:vnc

Note that even if you started selenium with VNC support, you need to run the test:vnc command to see the browsers visually.

Debugging with VNC support is also possible. If you're using Visual Studio Code there are VNC Debug current test and VNC Debug all tests debugging configurations that work similar to configurations described in Debugging tests section.

To stop the debug containers use the same command:

npm run selenium:stop

CI integration

Integration with a CI tool is easy if it supports docker and docker-compose tools.
There is a Dockerfile to build an image that bundles Node.js, npm and tests. The docker-compose.ci.yml configures all the dependencies required to run the tests in containers:

docker-compose -f docker-compose.ci.yml up --abort-on-container-exit --exit-code-from node

There are npm scripts to avoid running long commands:

# only builds the Dockerfile image
npm run ci:build

# runs the tests in containers
npm run ci
CI Status Config Artifacts
CircleCI CircleCI ./.circleci/default.yml Report uploaded as artifacts that can be viewed directly in the browser.
Github Actions CI ./.github/workflows/main.yml Report files available as a downloadable zip in artifacts.
TravisCI Build Status ./.travis.yml You need to configure Amazon S3 account to enable artifacts.

License

MIT

web-automation's People

Contributors

asimionese avatar dimadeveatii 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  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  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  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  avatar  avatar  avatar  avatar  avatar

web-automation's Issues

cannot run it on saucelabs

Hi I was trying to run the code on sauce labs, i tried doing this:
created a sauce.config.ts

exports.config = {
  runner: 'local',
  user: process.env.SAUCE_USERNAME,
  key: process.env.SAUCE_ACCESS_KEY,
  sauceConnect: true,
  specs: ['./specs/steps/*.ts'],
  // Patterns to exclude.
  exclude: [
    // 'path/to/excluded/files'
  ],
  maxInstances: 10,
  capabilities: [
    { browserName: 'firefox', platform: 'Windows 10', version: '60.0' },
    { browserName: 'chrome', platform: 'OS X 10.13', version: '69.0' }
  ],
  bail: 0,
  baseUrl: 'http://localhost',
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  framework: 'mocha',
  mochaOpts: {
    ui: 'bdd',
    timeout: 60000
  }
}

tried to include in index.ts

export const config = {
  runner: 'local',
  baseUrl: 'http://localhost',

  framework: 'cucumber',

  maxInstances: process.env.DEBUG_TESTS === 'true' ? 1 : 2,
  capabilities: [
    capabilitiesChromeConfig,
    capabilitiesFirefoxConfig,
  ],

  services: [],

  ...serverConfig,
  ...testsConfig,
  ...loggingConfig,
  ...reportingConfig,
  ...hooksConfig,
  ...sauceConfig,
};

Then installed the sauce dependencies and tried to run it but gives error.

Error:
webdriver: Request failed due to Error: write EPROTO SSL routines:ssl3_get_record:wrong version number

browser.getUrl returns promise

This is really awesome. Helped me a lot.
Found the following,
I am trying to run the command "Then I expect that the url is "http://webdriverjs.christian-bromann.com/"
When I print currentUrl Object from src/support/check/checkUrl.ts i am getting promise.
[0-0] 2020-11-19T11:01:28.205Z INFO webdriver: COMMAND setWindowRect(null, null, 1280, 720)
[0-0] 2020-11-19T11:01:28.206Z INFO webdriver: [POST] http://localhost:4444/wd/hub/session/7ee35bdf5a2f9b270060479b5d2dfd7d/window/rect
[0-0] 2020-11-19T11:01:28.206Z INFO webdriver: DATA { x: null, y: null, width: 1280, height: 720 }
[0-0] 2020-11-19T11:01:28.266Z INFO webdriver: COMMAND navigateTo("http://webdriverjs.christian-bromann.com/")
[0-0] 2020-11-19T11:01:28.271Z INFO webdriver: [POST] http://localhost:4444/wd/hub/session/7ee35bdf5a2f9b270060479b5d2dfd7d/url
[0-0] 2020-11-19T11:01:28.272Z INFO webdriver: DATA { url: 'http://webdriverjs.christian-bromann.com/' }
[0-0] 2020-11-19T11:01:28.369Z INFO webdriver: RESULT { height: 720, width: 1280, x: 0, y: 0 }
[0-0] currentUrl = Promise { }
[0-0] Inside else case
[0-0] 2020-11-19T11:01:31.263Z INFO webdriver: COMMAND takeScreenshot()
[0-0] 2020-11-19T11:01:31.266Z INFO webdriver: [GET] http://localhost:4444/wd/hub/session/7ee35bdf5a2f9b270060479b5d2dfd7d/screenshot
[0-0] 2020-11-19T11:01:31.267Z INFO webdriver: COMMAND getUrl()
[0-0] 2020-11-19T11:01:31.270Z INFO webdriver: [GET] http://localhost:4444/wd/hub/session/7ee35bdf5a2f9b270060479b5d2dfd7d/url
[0-0] Error in "Tests for the campaign page.: open URL: Then I expect that the url is "http://webdriverjs.christian-bromann.com""
expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[0-0] 2020-11-19T11:01:31.380Z INFO webdriver: COMMAND deleteSession()
[0-0] 2020-11-19T11:01:31.388Z INFO webdriver: [DELETE] http://localhost:4444/wd/hub/session/7ee35bdf5a2f9b270060479b5d2dfd7d
[0-0] 2020-11-19T11:01:31.864Z INFO webdriver: RESULT http://webdriverjs.christian-bromann.com/
[0-0] 2020-11-19T11:01:32.085Z INFO webdriver: RESULT iVBORw0KGgoAAAANSUhEUgAABQAAAALQCAYAAADPfd1WAAAAAXNSR0IArs4c6...
2020-11-19T11:01:32.157Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
[0-0] FAILED in chrome - /src/features/volvotests.feature
[1-0] 2020-11-19T11:01:35.655Z INFO webdriver: COMMAND setWindowRect(null, null, 1280, 720)
[1-0] 2020-11-19T11:01:35.655Z INFO webdriver: [POST] http://localhost:4444/wd/hub/session/c7a53fa1-6709-4b7e-b4ab-0650e26262f1/window/rect
[1-0] 2020-11-19T11:01:35.656Z INFO webdriver: DATA { x: null, y: null, width: 1280, height: 720 }
[1-0] 2020-11-19T11:01:35.722Z INFO webdriver: COMMAND navigateTo("http://webdriverjs.christian-bromann.com/")
[1-0] 2020-11-19T11:01:35.737Z INFO webdriver: [POST] http://localhost:4444/wd/hub/session/c7a53fa1-6709-4b7e-b4ab-0650e26262f1/url
[1-0] 2020-11-19T11:01:35.739Z INFO webdriver: DATA { url: 'http://webdriverjs.christian-bromann.com/' }
[1-0] 2020-11-19T11:01:35.749Z INFO webdriver: RESULT { x: 0, y: 0, width: 1280, height: 720 }
[1-0] currentUrl = Promise { }
[1-0] Inside else case
[1-0] 2020-11-19T11:01:37.503Z INFO webdriver: COMMAND takeScreenshot()
[1-0] 2020-11-19T11:01:37.504Z INFO webdriver: [GET] http://localhost:4444/wd/hub/session/c7a53fa1-6709-4b7e-b4ab-0650e26262f1/screenshot
[1-0] 2020-11-19T11:01:37.505Z INFO webdriver: COMMAND getUrl()
[1-0] 2020-11-19T11:01:37.505Z INFO webdriver: [GET] http://localhost:4444/wd/hub/session/c7a53fa1-6709-4b7e-b4ab-0650e26262f1/url
[1-0] Error in "Tests for the campaign page.: open URL: Then I expect that the url is "http://webdriverjs.christian-bromann.com""
expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[1-0] 2020-11-19T11:01:37.572Z INFO webdriver: COMMAND deleteSession()
[1-0] 2020-11-19T11:01:37.574Z INFO webdriver: [DELETE] http://localhost:4444/wd/hub/session/c7a53fa1-6709-4b7e-b4ab-0650e26262f1
[1-0] 2020-11-19T11:01:37.760Z INFO webdriver: RESULT http://webdriverjs.christian-bromann.com/
[1-0] 2020-11-19T11:01:37.780Z INFO webdriver: RESULT iVBORw0KGgoAAAANSUhEUgAABQAAAAKGCAYAAAAVqja8AAAgAElEQVR4nOydd...
2020-11-19T11:01:40.154Z DEBUG @wdio/local-runner: Runner 1-0 finished with exit code 1
[1-0] FAILED in firefox - /src/features/volvotests.feature
2020-11-19T11:01:40.156Z INFO @wdio/cli:launcher: Run onComplete hook

"spec" Reporter:

[chrome 80.0.3987.106 linux #0-0] Spec: /home/ubuntu/tools/webautomation/web-automation/src/features/volvotests.feature
[chrome 80.0.3987.106 linux #0-0] Running: chrome (v80.0.3987.106) on linux
[chrome 80.0.3987.106 linux #0-0] Session ID: 7ee35bdf5a2f9b270060479b5d2dfd7d
[chrome 80.0.3987.106 linux #0-0]
[chrome 80.0.3987.106 linux #0-0] Tests for the campaign page.
[chrome 80.0.3987.106 linux #0-0] open URL
[chrome 80.0.3987.106 linux #0-0] ✓ Given I open the url "http://webdriverjs.christian-bromann.com"
[chrome 80.0.3987.106 linux #0-0] ✖ Then I expect that the url is "http://webdriverjs.christian-bromann.com"
[chrome 80.0.3987.106 linux #0-0]
[chrome 80.0.3987.106 linux #0-0] 1 passing (7.4s)
[chrome 80.0.3987.106 linux #0-0] 1 failing
[chrome 80.0.3987.106 linux #0-0]
[chrome 80.0.3987.106 linux #0-0] 1) open URL Then I expect that the url is "http://webdriverjs.christian-bromann.com"
[chrome 80.0.3987.106 linux #0-0] expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[chrome 80.0.3987.106 linux #0-0] AssertionError: expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[chrome 80.0.3987.106 linux #0-0] at World.checkUrl (/home/ubuntu/tools/webautomation/web-automation/src/support/check/checkUrl.ts:19:25)
[chrome 80.0.3987.106 linux #0-0] at World.executeAsync (/home/ubuntu/tools/webautomation/web-automation/node_modules/@wdio/utils/build/shim.js:123:21)
[chrome 80.0.3987.106 linux #0-0] at World.testFrameworkFnWrapper (/home/ubuntu/tools/webautomation/web-automation/node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:55:28)

[firefox 73.0 linux #1-0] Spec: /home/ubuntu/tools/webautomation/web-automation/src/features/volvotests.feature
[firefox 73.0 linux #1-0] Running: firefox (v73.0) on linux
[firefox 73.0 linux #1-0] Session ID: c7a53fa1-6709-4b7e-b4ab-0650e26262f1
[firefox 73.0 linux #1-0]
[firefox 73.0 linux #1-0] Tests for the campaign page.
[firefox 73.0 linux #1-0] open URL
[firefox 73.0 linux #1-0] ✓ Given I open the url "http://webdriverjs.christian-bromann.com"
[firefox 73.0 linux #1-0] ✖ Then I expect that the url is "http://webdriverjs.christian-bromann.com"
[firefox 73.0 linux #1-0]
[firefox 73.0 linux #1-0] 1 passing (6.5s)
[firefox 73.0 linux #1-0] 1 failing
[firefox 73.0 linux #1-0]
[firefox 73.0 linux #1-0] 1) open URL Then I expect that the url is "http://webdriverjs.christian-bromann.com"
[firefox 73.0 linux #1-0] expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[firefox 73.0 linux #1-0] AssertionError: expected url to be "http://webdriverjs.christian-bromann.com" but found "[object Promise]": expected {} to equal 'http://webdriverjs.christian-bromann.com'
[firefox 73.0 linux #1-0] at World.checkUrl (/home/ubuntu/tools/webautomation/web-automation/src/support/check/checkUrl.ts:19:25)
[firefox 73.0 linux #1-0] at World.executeAsync (/home/ubuntu/tools/webautomation/web-automation/node_modules/@wdio/utils/build/shim.js:123:21)
[firefox 73.0 linux #1-0] at World.testFrameworkFnWrapper (/home/ubuntu/tools/webautomation/web-automation/node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:55:28)

Spec Files: 0 passed, 2 failed, 2 total (100% completed) in 00:00:31

2020-11-19T11:01:40.162Z INFO @wdio/local-runner: Shutting down spawned worker
2020-11-19T11:01:40.416Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2020-11-19T11:01:40.418Z INFO @wdio/local-runner: shutting down
npm ERR! code 1
npm ERR! path /home/ubuntu/tools/webautomation/web-automation
npm ERR! command failed
npm ERR! command sh -c node ./node_modules/@wdio/cli/bin/wdio.js --spec

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2020-11-19T11_01_40_484Z-debug.log

[email protected] report
node ./cucumber.report.conf.js

=====================================================================================
Multiple Cucumber HTML report generated in:

/home/ubuntu/tools/webautomation/web-automation/report/cucumber/html/index.html

=====================================================================================

ubuntu@ubuntu-VirtualBox:~/tools/webautomation/web-automation$

After a few runs the app 'crashes'...

I am adding features to my feature files, after lets say 5 runs of npm run test, I get a lot of errors:
Multiple step definitions match:
/^I open the (url|site) "([^"]*)?"$/ - src/steps/given 3.ts:23

They all contain "Multiple step definitions match" the only way I have managed to get rid of them is to re-clone the repo and start from the beginning.

In the steps directory there are multiple steps files.
given.ts
given 3.ts
...

Help: executing tests on windows

Hi guys,
Have I chance to execute tests without docker? Directly on my PC? Or I should create a docker image for that? Sry about had to create issue for dump question.

App crashed...

Hard to write a title for this.
So I installed web-automation last Friday all was working perfectly then.
I thought I would run the tests again this morning.
First off it is this error that I have no clue why it appears with multiple step definitions appearing from nowhere.
Then I had an idea that it was the docker containers that were missing so I restarted them and ran the tests again then this was the error I got:
[0-0] 2020-03-16T08:48:25.354Z ERROR webdriver: Request failed due to unknown error: Error forwarding the new session Empty pool of VM for setup Capabilities {browserName: chrome, cjson:metadata: {device: 3.141.59-zirconium}, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-gpu]}}

To get it to work I need to reinstall everything. Or so I thought.
I tried to remove the web-automation directory and cloning it again, and running all the npm stuff. Still the same error as the one above.

In clickElement.ts - Chrome adds a = to a selector, Firefox doesnt

In my feature file I have the line:
Then I click on the link "Biografer"

Chrome can't find the link due to the selector is named "=Biografer", Firefox finds it perfectly since it uses the name on the link as "Biografer".

Does Firefox and Chrome interpit typescript diffrently?

pause for XXXXms - not working?

I need to use pauses in my test and glad to find pause, added:
And I pause for 3000ms

When I look at the test through VNC, there is no 3 sec pause what so ever.
That is why my test fails.

Not an issue really but how do I get the right xpath?

I know... bad of me using issues as support, but Ive been trying to use xpath to point at elements that the system otherwise refuses to find.

Then I expect that element "*" is displayed

But the ones from Chrome doesn't work:
//[@id="inpPointFrMobile"]
Expected element "//
[@id='inpPointFrMobile']" to be displayed: expected false to equal true
or /html/body/div[4]/div/div/div[2]/form/fieldset/div[1]/div[1]/input
Error: Expected element "/html/body/div[4]/div/div/div[2]/form/fieldset/div[1]/div[1]/input" to be displayed: expected false to equal true

Then I tried Firefox's and the same result there.
//[@id="inpPointFrMobile"]
Expected element "//
[@id='inpPointFrMobile']" to be displayed: expected false to equal true

So what shall I do to make it work? For sometimes xpath is the only solution.
In your example there is an possibility to test a positive with elements.

[question] Run multiple time

Hi there,

I have a 2 question today

  1. Can I run test multiple time due to N or due to they succeeded?
  2. Can I run test on several nodes?

Thanks, In advice

Using the selenium:vnc - nothing shows?

So in my attempt to understand why I am not reaching an element I thought I would look at what is happening.
So I stopped selenium and started selenium:vnc, used a VNCviewer to connect to 127.0.0.1:5900 / 5901.
I do see a Ubuntu logo and a taskbar but that it is, then I run the tests nothing happens on the VNC "screen"
What have I missed?

not working anymore

@types/cucumber is deprecated and some other libraries are outdates and causing errors when running npm run test. could you pleasee try to fix if its possible for you

How to add a custom command

First of all thanks for this awesome setup. Makes life a lot easier for me.

I am trying to add a custom command to make the page wait for a URL to change to a particular route.

I made the following changes but I'm not able to get the command to work.

Here is my feature -

Scenario: Checking the URL
Given I open the url "https://abcd.somedomain.com/route1/#/"
When I wait for URL to change to "https://abcd.somedomain.com/route1/#/subroute" for 10s

  • Add the code for custom command in a new file under /src/actions/waitForUrl.ts
 * @alias browser.waitForUrl
 * @param {string|RegExp|Function} value
 * @param {number} timeout — ms
 * @param {number} revert
 * @returns {boolean}
  */

export const waitForUrl = {

    waitForUrl: function (value, timeout, revert) {
        let url, actual;

        try {
            return this.waitUntil(() => {
                url = this.getUrl();
                actual = value === url;

                if (typeof value === 'string' && !value.endsWith('/')) {
                    url = url.replace(/\/$/, '');
                }

                if (typeof value === 'function') {
                    actual = value(url);
                } else if (value[Symbol.match]) {
                    actual = value.test(url);
                }

                return value && actual && !revert;
            }, timeout, '');
        } catch (error) {
            let message = 'Could not wait for the required url:';
            message += `\n\tActual: ${url}`;
            message += `\n\tExpected: ${actual}`;

            throw new Error(message);
        }
    }
}
  • Call this under the config/index.ts file
export const config = {

  before: function name(capabilities: any, specs) {
    Object.keys(waitForUrl.waitForUrl).forEach((key) => {
      browser.addCommand(key, waitForUrl.waitForUrl[key])
    })
  },
  runner: 'local',
.....
  • Try to get this to work in the when steps
When(/^ I wait for URL to change to "([^"]*)?" for "([^"]*)?"s$/,
  waitForUrl.waitForUrl();

However this shows error stating the there are 3 arguments expected but 0 was provided, which I'm failing to understand. Surely there is something that I am missing. Can you please take a look and let me know where the issue lies.

TY

Trying to reach an input field

On a site (Wordpress) I have an input field, no matter what I set in the feature file:
When I add "something" to the inputfield "input#inpDesktop"
or
When I add "something" to the inputfield "//*[@id="inpDesktop"]"

It cannot be found, css, xpath, full xpath.

Please advice how I should reach an input field.

Dockerfile unused?

Hi, thanks for your great work.
Is it possible that the Dockerfile is currently unused?
As far as I can tell the docker-compose files don't use it in any way, right?

How to run using local browsers using 'selenium-standalone' service.

Hi,

Please help to run the setup on locally installed browsers using 'selenium-standalone' service. Currently I am getting below error:
ERROR @wdio/utils:initialiseServices: TypeError: Cannot read property 'outputDir' of undefined

Also, getting the below error along with the above one:
ERROR webdriver: Request failed due to Error: connect ECONNREFUSED 127.0.0.1:4444
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)

Thanks,
Ankit Ranjan

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.