testcafe

propósito

  • Para probar testcafe como ayuda para testear aplicaciones web.
  • la ventaja es que se puede lanzar en más navegadores que cypress que prácticamente sólo se puede usar en chrome (y firefox y electron )

instalación

# para instalar testcafe
npm install -g testcafe
# para lanzar el tes
testcafe chrome test-inicio.js
  • resultado
 Running tests in:
 - Chrome 80.0.3987.163 / Windows 10

 Getting Started
  My first test

 1 passed (4s)
  • interesante la opción all que lanza el test con todos los navegadores que tengas instalados
C:\proyectos\testcafe\inicio>testcafe all test-inicio.js
 Running tests in:
 - Chrome 80.0.3987.163 / Windows 10
 - Internet Explorer 11.0 / Windows 10
 - Opera 67.0.3575.137 / Windows 10
 - Microsoft Edge 18.18363 / Windows 10
 - Microsoft Edge 18.18363 / Windows 10

 Getting Started
 √ My first test


 1 passed (35s)
  • para saber que browsers tienes instalados
C:\proyectos\testcafe\inicio>testcafe --list-browsers
chrome
ie
opera
edge-legacy
edge

C:\proyectos\testcafe\inicio>testcafe ie test-inicio.js
Running tests in:
- Internet Explorer 11.0 / Windows 10

Getting Started
√ My first test


1 passed (2s)
  • se puede lanzar el navegador sin entorno gráfico testcafe "chrome:headless" test.js

INICIO

  • en el directorio C:\proyectos\testcafe\inicio tengo la prueba inicial
import { Selector } from 'testcafe'; // first import testcafe selectors

fixture `Getting Started`// declare the fixture
    .page `https://devexpress.github.io/testcafe/example`;  // specify the start page


//then create a test and place your code there
test('My first test', async t => {
    await t
        .typeText('#developer-name', 'John Smith')
        .click('#submit-button')

        // Use the assertion to check if the actual header text is equal to the expected one
        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
});

CARACTERÍSTICAS

  • no necesita estructura de proyecto
  • pero si quieres usar la extensión testLatte de visual studio code si que tiene que hacer npm init y
  • se ejecuta en pantalla completa
  • la escritura es más compleja que cypress

PLUGIN

  • para usar la extensión testLatte de visual studio code
    • importante crear el directorio test y poner allí las pruebas
npm init
npm install --save-dev testcafe

CONFIGURACIÓN

  • en el archivo .testcaferc.json en el raíz del proyecto
  • se puede configurar con que navegadores se lanza
{
  "browsers": ["chrome", "firefox", "opera", "ie"]
}
  • al lanzar testcafe se lanza con los indicados en el archivo de configuración

PROBLEMAS

  • ERROR The specified glob pattern does not match any file or the default test directories are empty.

  • faltaba poner el directorio test en la ruta testcafe all test/test-AplicacionPMora.js

TUTORIALES