I'm trying to use PageObject as described on the site.
I always get the error message "Object of type openhome is not defined in container"
Output:
alan@alan-hp:~/tests$ codeceptjs run --verbose
CodeceptJS v1.0.2
Using test root "/home/alan/tests"
Login --
[1] Starting recording promises
Emitted | suite.before ([object Object])
[1] Queued | hook WebDriverIO._beforeSuite()
Testa o Login com sucesso
Emitted | test.before
[1] Queued | hook WebDriverIO._before()
Emitted | test.start ([object Object])
[1] Queued | throw error Error: Object of type openhome is not defined in container
[1] Queued | fire test.passed
[1] Queued | finish test
[1] Error | Error: Object of type openhome is not defined in container
[1] Starting <teardown> session
Emitted | test.failed ([object Object])
[1] <teardown> Queued | hook WebDriverIO._failed()
[1] <teardown> Queued | () => done(err)
[1] <teardown> Stopping recording promises
> Screenshot has been saved to /home/alan/tests/output/Testa_o_Login_com_sucesso.failed.png
✖ FAILED in 93ms
[2] Starting recording promises
Emitted | test.after
[2] Queued | hook WebDriverIO._after()
Emitted | suite.after ([object Object])
[2] Queued | hook WebDriverIO._afterSuite()
-- FAILURES:
1) Login: Testa o Login com sucesso:
Object of type openhome is not defined in container
rror: Object of type openhome is not defined in container
at getInjectedArguments (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/scenario.js:176:13)
at Context.test.fn (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/scenario.js:64:36)
FAIL | 0 passed, 1 failed // 441ms
Emitted | global.result ([object Object])
[2] Queued | hook WebDriverIO._finishTest()
This is the test
Feature('Login');
Scenario('Testa o Login com sucesso', (I, openhome) => {
openhome.open();
I.fillField('itEmail', '[email protected]');
I.fillField('itPassword', 'pass');
I.click("//button[@type='submit']");
I.waitForElement({xpath:'/html/body/div/main/div[2]/div/md-content/div/div[2]/h3'}, 2);
I.see('Home');
});
This is the pageObject file
'use strict';
let I;
module.exports = {
_init() {
I = actor();
},
open(){
I.amOnPage('/');
}
}
This is the codecept,json file:
{
"output": "./output",
"helpers": {
"WebDriverIO": {
"url": "https://exemple.com",
"browser": "chrome"
}
},
"include": {
"loginpagePage": "./pages/openhome.js"
},
"mocha": {
"reporterOptions": {
"reportDir": "output"
}
},
"bootstrap": false,
"teardown": null,
"hooks": [],
"tests": "./*_test.js",
"timeout": 10000,
"name": "tests",
"translation": "pt-BR"
}
hi @Schveitzer
looks like you should change
"include": {
"loginpagePage": "./pages/openhome.js"
},
to
"include": {
"openhome": "./pages/openhome.js"
},
in codecept.json.
Or make simular changes in tests from Scenario('Testa o Login com sucesso', (I, openhome) to Scenario('Testa o Login com sucesso', (I, loginpagePage)
Thank you, that was the problem.
I am trying samething. it is working fine for me . BUt I have doubt why inject is not working for me .
As per codecept web link we can use
const {I} = inject(); but it not working it shows undefined .
when I am using let I ad then use _init(){
I = actor();
}
then it is working fine.
Most helpful comment
hi @Schveitzer
looks like you should change
to
in codecept.json.
Or make simular changes in tests from Scenario('Testa o Login com sucesso', (I, openhome) to Scenario('Testa o Login com sucesso', (I, loginpagePage)