GithubHelp home page GithubHelp logo

labs42io / web-automation Goto Github PK

View Code? Open in Web Editor NEW
136.0 11.0 43.0 154 KB

BDD tests with Cucumber, WebdriverIO and Docker Selenium

Home Page: https://labs42io.github.io/web-automation

License: MIT License

JavaScript 4.32% Dockerfile 0.60% TypeScript 75.30% Shell 6.20% Gherkin 13.58%
automation-testing webdriverio cucumber docker-selenium typescript testing web-automation

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

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?

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.

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.

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

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
...

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?

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$

[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

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

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

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.

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

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.

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?

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.