Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no-layout-selector #38

Open
codejedi365 opened this issue Nov 14, 2021 · 0 comments
Open

feat: no-layout-selector #38

codejedi365 opened this issue Nov 14, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@codejedi365
Copy link
Collaborator

Feature Request

If Selector() is used and a css property is used to locate the element, make sure it isn't related to page layout since page layouts change all the time.

Problem & Goal

If you use multiple selectors to narrow down and ensure the component is selected then it is likely heavily coupled to a particular page layout. Page layouts can change rapidly leading to brittle test cases or misinterpreted results.

Encourage use of more specific selectors for the page using only 1 css child selector. A child selector is a space ( ) or a > between selectors.

Expected behavior

// page.test.js - invalid example
await t.typeText('.topWindow .banner > [data-test="search"]', 'Batman')
await t.expect(Selector('.table .tableRows td [data-test="name"]').value).eql('Batman');
# Run Lint
eslint ./tests/page.test.js

Should return an warning on line 1 & 2, highlighting the 1st parameter string of typeText() & Selector(...). Recommend using more specific css selectors which do not rely on the page layout to find the element. It is recommended to use the testing-library and page model abstraction for the best durability of selecting elements on the page.

No Layout Selectors

// page.test.js - valid example
await t.typeText('[data-testid="user-search"]', 'Batman')
await t.expect(Selector('table [data-testid="name"]').value).eql('Batman');

RECOMMENDED: Page Model & Testing-Library

// tests/model/page.js
//import {} from "@testing-library"
//incomplete
// page.test.js - desired implementation
import { t } from "testcafe"
import { page } from "./models"

test('Search for a name and find valid result', async t => {
    await page.submitName('Batman');
    await t.expect(page.table.userName.innerText).eql('Batman');
});
@codejedi365 codejedi365 added the enhancement New feature or request label Nov 14, 2021
@codejedi365 codejedi365 self-assigned this Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant