codeceptjs / codeceptjs/CodeceptJS

Using `I.see` inside of a `within` call

Abierto
#1,856 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
4.2k
Forks
757
Merge medio
2 d 9 h
PR fusionados (30 d)
16

Descripción

#### What are you trying to achieve?

I would like to use `I.see` inside of a `within` call, using webdriverio

#### What do you get instead?

I get the following error: `Element ".//*" was not found by text|CSS|XPath`.

It would appear that the scope of the `within`-constrained element is not being considered. Digging into the code a bit, this function appears to govern the context used to validate against: https://github.com/Codeception/CodeceptJS/blob/master/lib/helper/WebDriverIO.js#L1843-L1871

Is this intended behavior or a bug?

> Provide console output if related. Use `--verbose` mode for more details.

```bash

> codeceptjs run --steps

CodeceptJS v2.3.0
Using test root "/"

Person Page --
Test that all the expected attributes appear on the page | {}
I am on page ""
I see element "div.personHeroRight"
I see element "div.personHeroRight > h1.name"
Within "div.personHeroRight > h1.name"
I see "Francis"
✖ FAILED in 2514ms

-- FAILURES:

1) Person Page
Test that all the expected attributes appear on the page | {}:
Element ".//*" was not found by text|CSS|XPath

Scenario Steps:

- I.see("Francis") at tests/person-page/testAttributes.js:16:9
- I.seeElement("div.personHeroRight > h1.name") at Test. (tests/person-page/testAttributes.js:14:7)
- I.seeElement("div.personHeroRight") at Test. (tests/person-page/testAttributes.js:13:7)
- I.amOnPage("...") at Test. (tests/person-page/testAttributes.js:12:7)



Run with --verbose flag to see NodeJS stacktrace

FAIL | 0 passed, 1 failed // 5s
2019-08-20T20:24:57.270Z INFO @wdio/selenium-standalone-service: shutting down all browsers
npm ERR! Test failed. See above for more details.
make: *** [test] Error 1

```

> Provide test source code if related

```js

********** TEST CODE **********

Feature('Person Page');

const personPage = require('../../pages/personPage.js');

Data(personPage.people).Scenario(
'Test that all the expected attributes appear on the page',
(I, current) => {
I.amOnPage(current.url);
I.seeElement(personPage.attributesModule);
I.seeElement(personPage.Name);
within(personPage.Name, () => {
I.see(current.firstName);
I.see(current.middleInitial, personPage.Name);
I.see(current.lastName, personPage.Name);
});
I.seeElement(personPage.Dates);
I.see(current.dob, personPage.Dates);
I.see(current.dod, personPage.Dates);
},
);

********** PAGE OBJECT **********

const {I} = inject();

let people = new DataTable([
'firstName',
'middleInitial',
'lastName',
'url',
'dob',
'dod',
'location',
]);

people.add([
'Francis',
'',
'',
'',
'',
'',
'',
]);

module.exports = {
attributesModule: 'div.personHeroRight',
Name: 'div.personHeroRight h1.name',
Dates: 'div.personHeroRight p.date',
people: people,
};

```

### Details

* CodeceptJS version: 2.3.0
* NodeJS Version: 12.4.0
* Operating System: macOS Mojave (10.14.6 (18G87)
* WebDriverIO version (if related): 5.12.1
* Configuration file:

```js
exports.config = {
tests: './tests/*/*.js',
output: './output',
helpers: {
WebDriver: {
url: 'https://www..com',
browser: 'chrome'
}
},
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
}
},
include: {
I: './custom_steps/*.js',
personPage: './pages/personPage.js'
},
bootstrap: null,
mocha: {},
name: 'codeceptjs_tests'
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.