Skip to content

Latest commit

 

History

History
252 lines (216 loc) · 10.5 KB

utils-testing.md

File metadata and controls

252 lines (216 loc) · 10.5 KB

TESTING

LIST

BROWSER

API

COMPARATIVE

  • Selenium released in 2004 (opensource; requires java - WebDriver, complex installation because different dependencies version must match: java, selenium, webdriver, protractor; chrome, complex dom manipulation, flaky tests) ~28k stars on Github.

  • Cypress released in 2017 (partially opensource, simple installation, simple dom manipulation, stable tests, but dashboard is closed source, alternative called sorrycypress) ~45k stars on Github.

  • Playwright released in 2020 (opensource, simple installation, simple dom manipulation, stable tests, powerfull tooling) ~57k stars on Github.

  • Others solutions are: WebdriverIO, Puppeteer, Nightwatch, Protractor (NES)

  • The main arguments to use Cypress and Playwright is they are supported by Angular and Nx, that it manages tests directly with the browser; via Chrome DevTools Protocol (CDP) or directly run on it (Cypress) compared to Selenium that uses an intermeriary tool called WebDriver to communicate with the differents browser that makes tests flaky.

  • https://www.rainerhahnekamp.com/en/angular-e2e-testing-protractor-is-dead-long-live-cypress/

  • https://www.lambdatest.com/blog/playwright-vs-selenium-vs-cypress/

GUIDE

TOOLS: ALL

TOOLS: AI

TOOLS: WEB

TOOLS: MOBILE

TOOLS: CLOSED

TOOLS: OSS: ALL

TOOLS: OSS: JS

UTILS: MOCK

UTILS: ALL

UTILS: AI

UTILS: HTTP

UTILS: CYPRESS

UTILS: PLAYWRIGHT LIST

UTILS: PLAYWRIGHT TOOLS

UTILS: PLAYWRIGHT LINKS

CYPRESS: LEARN

PLAYWRIGHT: NOTES

for (const row of rows) {
  const time = await row.locator('.time').innerText();
  const heading = await row.getByText('some common heading').innerText();

  console.log(`${time} ${heading}`);
}

const items = page.locator('ul > li'); 
const count = await items.count(); 
for (let i = 0; i < count; ++i) { 
    console.log(await items.nth(i).textContent()); 
}
// Return true if the page emits 'Hello, World!' to the console info level
async function waitForMessageAsync(): Promise<boolean> {
  return new Promise(function (resolve) {
    page.on('console', (msg) => {
      if (msg.type() === 'log' && msg.text() === 'Hello, World!') {
        resolve(true);
      }
    });
  });
}

await expect(await waitForMessageAsync).toBeTruthy();

CYPRESS: NOTES

  • the difference between the then() and the within(). then() allows you to do imperative/js on the get element itself while the within() is in the elements inside the get
  • the difference between the within() and find(): within() allows you to do imperative/js and the find is classic chaining

note: you can also use then then() to trigger a function that use the cypress chaining, similar to a command but inside a function