Transportador: elemento.getText () devuelve un objeto y no una cadena


Tengo un elemento definido como

this.clientRowName = element(by.id('CLIENT_NAME')); //page object file

Quiero leer el texto en este elemento que es "ABC", pero haciendo: var client = page.Nombre del cliente.getText ();

Devuelve un objeto en lugar de una cadena. ¿Hay alguna otra manera de que pueda obtener el texto para el elemento

Author: Roopali Bansal, 2015-04-06

3 answers

getText() devuelve una promesa, deberá resolver es:

page.clientRowName.getText().then(function (text) {
    console.log(text);
});

O, si solo quieres afirmar el texto, deja expect() resolver la promesa para ti:

expect(page.clientRowName.getText()).toEqual("ABC");

Las promesas y la página de documentación de Control Flow deberían aclarar las cosas.

 93
Author: alecxe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-29 13:31:42

Otra solución puede ser usar async/await.

class Page {
  constructor() {
    this.clientRowName = $('#CLIENT_NAME');
  }
}

/****************/

it('should console.log client name', async () => {
  const client = await Page.clientRowName.getText();
  console.log(client);
});
 3
Author: robdonn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-30 09:17:32

Normalmente usé element.getAttribute('value')

 0
Author: ji-ruh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-01 08:17:12