Giter Club home page Giter Club logo

Comments (5)

benmonro avatar benmonro commented on June 15, 2024

from testcafe-testing-library.

Artikodin avatar Artikodin commented on June 15, 2024

Hey @benmonro thanks for your answer. But I've already include the addTestcafeTestingLibrary call in my test I just didn't notified it in my sample 😬.

// [...]

import { addTestcafeTestingLibrary } from 'testcafe-testing-library';
import LoginPage from './model';

fixture`The login page`.beforeEach(addTestcafeTestingLibrary).page`http://localhost:3000`;

// [...]

// Error
test('should correctly handle error when a wrong password is typed', async t => {
  await loginPage.login(login, 'WRONG PASSWORD');

  await t.expect(loginPage.errorWrongPassword).ok();
});

// Correct
test('should correctly handle error when a wrong password is typed ', async t => {
  await loginPage.login(login, 'WRONG PASSWORD');

  await t.expect(loginPage.errorWrongPassword2).ok();
});

But maybe I should include it in my model. If you have an idea how to do that cause I've tried without success 😅.

import { getByTestId, getByPlaceholderText, addTestcafeTestingLibrary } from 'testcafe-testing-library';
import { t, Selector } from 'testcafe';
// I've tried here
// addTestcafeTestingLibrary()
export default class LoginPage {
  constructor() {
    // ... here
    // addTestcafeTestingLibrary()
    this.usernameInput = getByPlaceholderText(/username/i);
    this.passwordInput = getByPlaceholderText(/password/i);
    this.submitButton = getByTestId('submit');
    this.errorIsEmpty = Selector('[data-testid="error-isEmpty"]');

    // Error
    this.errorWrongPassword = getByTestId('wrong-credentials');
    // Correct
    this.errorWrongPassword2 = Selector('[data-testid="wrong-credentials"]');
  }
  async login(username, password) {
     // ... and here
    // addTestcafeTestingLibrary()
    await t
      .typeText(this.usernameInput, username)
      .typeText(this.passwordInput, password)
      .click(this.submitButton);
  }
}

Thanks 👍

from testcafe-testing-library.

benmonro avatar benmonro commented on June 15, 2024

from testcafe-testing-library.

benmonro avatar benmonro commented on June 15, 2024

@Artikodin I think I found a solution to your problem. Instead of instantiating your loginPage outside the test, try doing it in the before each like this:

let loginPage;

// eslint-disable-next-line babel/no-unused-expressions
fixture`pom`.beforeEach(async t => {
    loginPage = new LoginPage();

    await addTestcafeTestingLibrary(t)
})
    .page`http://localhost:13370/pom.html`

let me know if that works for you.

from testcafe-testing-library.

benmonro avatar benmonro commented on June 15, 2024

closing due to inactivity @Artikodin feel free to reopen if it is still an issue

from testcafe-testing-library.

Related Issues (20)

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.