Giter Site home page Giter Site logo

nightwatch-testing-library's Introduction

nightwatch-testing-library

ox

nightwatch selectors and utilities that encourage good testing practices laid down by dom-testing-library.

Read the docs | Edit the docs


Build Status version downloads MIT License semantic-release

Dependabot Status All Contributors PRs Welcome Code of Conduct Discord

Watch on GitHub Star on GitHub Tweet

The problem

You want to use dom-testing-library methods in your nightwatch tests.

This solution

This allows you to use all the useful dom-testing-library methods in your tests.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev @testing-library/nightwatch

Usage

Usage Docs

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors

Thanks goes to these wonderful people (emoji key):

Ben Monro
Ben Monro

📖 💻 ⚠️ 🚇 🤔
Kent C. Dodds
Kent C. Dodds

🚇 🤔 💻
Kevin Brewer
Kevin Brewer

🤔 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

nightwatch-testing-library's People

Contributors

allcontributors[bot] avatar benmonro avatar dependabot-preview[bot] avatar imgbotapp avatar michaeldeboey avatar nickmccurdy 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

Watchers

 avatar  avatar  avatar  avatar

nightwatch-testing-library's Issues

UserEvents and the nightwatch-testing-library

Is nightwatch-testing-library intended to work with the testing-library's userEvent system?

I have many unit tests written with the userEvent system and I'd like to continue using the same system with nightwatch to eliminate code duplication, along with the other benefits of user-event testing.

To be more clear with code, I would like to do something like:

const input = await getByTestId('select-state')
userEvent.type(input, 'C{arrowdown}{enter}')

But type requires an Element and input above is the following object:

{
  selector: "[id='downshift-0-input']",
  nth: [Function: nth],
  browser: [Function: browser]
}

window.TestingLibraryDom is undefined

Environment:
node v12.10.0
Package.json:

"react": "^16.8.6",
"react-dom": "^16.8.6",
"@testing-library/jest-dom": "^4.2.3",
"@testing-library/nightwatch": "^1.1.0",
"geckodriver": "^1.19.1",
"nightwatch": "^1.2.4"

Error:

[E2e/Auth/Login Test] Test Suite ================================ Running: loginButtonIsVisible
 window.TestingLibraryDom is undefined
 Error: 
{"selector":"getByText","value":["Log In"],"locatorStrategy":"getByText","name":""
at processTicksAndRejections (internal/process/task_queues.js:93:5)  FAILED: 1 errors (5.117s)

Using chrome is fine but in firefox I got this error above.

Test code:

const { getQueriesFrom } = require('@testing-library/nightwatch');

module.exports = {
  beforeEach(browser, done) {
    browser.url('http://localhost:3000');
    done();
  },

  // Smoke test
  async loginButtonIsVisible(browser) {
    const { getByText } = getQueriesFrom(browser);
    browser.pause(5000);
    const input = await getByText('Log In');
    browser.waitForElementVisible(input, 5000);
    browser.assert.visible(input);
  },
};

Error: [object Object]

Hello, I'm trying to set up a project with nightwatch & nightwatch-testing-library but I can't get it to work and just returns object-object for any tests.

I've followed this stackover flow article but it still results in the same issue.

Even though there is a example of a test this is against a localhost page which we can't inspect it would be good if this example was against an actual site such as Ecosia in the nightwatch example.

Could I get some help and apologies if I've posted in the wrong place.

Call for maintainers

I created this when my company was using night watch but we have since moved on to testcafe. If you are interested in taking over this project let me know and I will make you admin

Can't fire a submit event using Nightwatch.js + Testing Library

"@testing-library/dom": "^7.26.7",
"@testing-library/nightwatch": "^2.0.0",
"@testing-library/user-event": "^12.2.2",
"chromedriver": "^87.0.0",
"nightwatch": "^1.5.1"

Node 12.19.0

Relevant code or config

const { getQueriesFrom } = require('@testing-library/nightwatch')
const { fireEvent } = require('@testing-library/dom')

module.exports = {

  async 'Demo test ecosia.org'(browser) {
    await browser.url('https://www.ecosia.org/')

    const { getByPlaceholderText } = getQueriesFrom(browser)

    const searchBox = await getByPlaceholderText(/search the web to plant trees.../i)

    await browser.setValue(searchBox, 'nightwatch')
    await fireEvent.submit(searchBox);

    await browser.end()
  }
}

What you did:
npm t -- tests/ecosiaSearchWithTL.js
What happened:

[Ecosia Search With TL] Test Suite
==================================
ℹ Connected to localhost on port 9515 (1061ms).
  Using: chrome (87.0.4280.66) on Mac OS X platform.

Running:  Demo test ecosia.org


FAILED: 1 errors (913ms)
   Error: Unable to find the "window" object for the given node. Please file an issue with the code that's causing you to see this error: https://github.com/testing-library/dom-testing-library/issues/new
       at Object.Demo test ecosia.org (/Users/lsr7759/projects/e2e/tests/ecosiaSearchWithTL.js:14:21)
       at processTicksAndRejections (internal/process/task_queues.js:97:5)
_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (2.642s)

Repo:
https://github.com/lsoares/e2e-nightwatchjs-testinglibrary

Above, I tried firing an event to submit the form. It failed... but I also tried using getByRole but it also failed for other reason. I think getByRole would be better though.

findBy* resolving immediately

I'm trying to get it running with nightwatch and followed the examples, though I cannot get findByLabelText to return a promise and wait for the element.

I tried it like this:

const { getQueriesFrom } = require("@testing-library/nightwatch")

describe("test", function() {
  test("other", async function(browser) {
    const { findByLabelText } = getQueriesFrom(browser)

    browser.url("http://localhost:8080")

    const input = await findByLabelText("Not Existent", { exact: false })
  
    console.log(input)
    // =>  
    // {
    //   selector: '.NWTL_findByLabelText-Not-Existent',
    //   nth: [Function: nth],
    //   browser: [Function: browser]
    // }

    browser.setValue(input, "[email protected]")
    browser.expect.element(input).value.to.equal("[email protected]")
  })
})

The problem is that awaiting findByLabelText returns immediately and is an object with those keys selector, nth and browser. It does not matter if I try with a not existent label or a label that should exist.

Then the next lines of course do not work and I get this error:

Expected element <.NWTL_findByLabelText-Not-Existent> to have value equal: "[email protected]" - element was not found - expected "equal '[email protected]'" but got: "not present" (5073ms)

and

NoSuchElementError: An error occurred while running .setValue() command on <.NWTL_findByLabelText-Not-Existent>: undefined; undefined

Shouldn't findByLabelText wait until it either finds an input or raise an error if it cannot?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/testing-library/nightwatch-testing-library.git.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot 📦🚀

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository with URL https://[secure]@github.com/testing-library/nightwatch-testing-library.git.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment and make sure the repositoryUrl is configured with a valid Git URL.


Good luck with your project ✨

Your semantic-release bot 📦🚀

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.