$ npm test -- --spec=usingPageObjectTest.js does not run the test

Asked

Viewed 23 times

-2

Can someone tell me a solution?

Running $ npm test -- -spec=usingPageObjectTest.js does not work:

[email protected] test C:\wagner.galvao\node\webdriverioframework
wdio wdio.conf.js "--spec=usingPageObjectTest.js"

Execution of 1 spec files started at 2020-10-13T14:26:40.109Z

[0-0] RUNNING in chrome - C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js
[0-0] PASSED in chrome - C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js

Spec Files:      1 passed, 1 total (100% completed) in 00:00:14

[0-0] beforeEach
[0-0] it => Deve enviar mensagem com sucesso
[0-0] PASSED in chrome - C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js

Running without contactUsPage lines works:

//const { default: contactUsPage } = require("../../pages/contactUs.page");

beforeEach(() => {
  console.log('beforeEach');
  browser.url('/Contact-Us/contactus.html');
  //contactUsPage.openPage();
})

describe('Testar o formulário de contato', () => {
  it('Deve enviar mensagem com sucesso', () => {
    console.log('it => Deve enviar mensagem com sucesso');
  });

});

$ npm test -- --spec=usingPageObjectTest.js

[email protected] test C:\wagner.galvao\node\webdriverioframework
wdio wdio.conf.js "--spec=usingPageObjectTest.js"


Execution of 1 spec files started at 2020-10-13T14:43:38.687Z

[0-0] RUNNING in chrome - C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js
[0-0] beforeEach
[0-0] it => Deve enviar mensagem com sucesso
[0-0] PASSED in chrome - C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js

 "spec" Reporter:
------------------------------------------------------------------
[chrome 86.0.4240.75 windows #0-0] Spec: C:\wagner.galvao\node\webdriverioframework\test\specs\usingPageObjectTest.js 
[chrome 86.0.4240.75 windows #0-0] Running: chrome (v86.0.4240.75) on windows
[chrome 86.0.4240.75 windows #0-0] Session ID: fd8f361cf51492de470e10a05ef04f7e
[chrome 86.0.4240.75 windows #0-0]
[chrome 86.0.4240.75 windows #0-0] Testar o formulário de contato
[chrome 86.0.4240.75 windows #0-0]    ✓ Deve enviar mensagem com sucesso
[chrome 86.0.4240.75 windows #0-0]
[chrome 86.0.4240.75 windows #0-0] 1 passing (2.6s)


Spec Files:      1 passed, 1 total (100% completed) in 00:00:16

My files:

//test\specs\usingPageObjectTest.js
const { default: contactUsPage } = require("../../pages/contactUs.page");

beforeEach(() => {
  console.log('beforeEach');
  //  browser.url('/Contact-Us/contactus.html');
  contactUsPage.openPage();
})

describe('Testar o formulário de contato', () => {
  it('Deve enviar mensagem com sucesso', () => {
    console.log('it => Deve enviar mensagem com sucesso');
  });

});

//pages\contactUs.page.js
const { default: contactUsConfig } = require("../config/contactUs.config");
const { default: elementActions } = require("../utils/elementActions");

class ContactUsPage {
  openPage() {
    elementActions.doGoToPage(contactUsConfig.pageUri());
  }
}
export default new ContactUsPage();
 
//utils\elementActions.js
class ElementActions {
  doGoToPage(text) {
    browser.Url(text)
  }
}
export default new ElementActions();

//config\contactUs.config.js
class ContactUsConfig {
  //  Page Elements
  get pageTitle() { return 'WebDriver | Contact Us'; }
  get pageUri() { return '/Contact-Us/contactus.html'; }
  get pageUrl() { return 'http://www.webdriveruniversity.com'; }
}
export default new ContactUsConfig();

1 answer

0

I solved the problem with another approach:

// utils\waitForDisplayed.js
exports.waitForDisplayed = (element, timeout) => {
  timeout = timeout ? timeout : 3000;
  browser.$(element).waitForDisplayed({ timeout: timeout });
};
// utils\switchToWindow.js
exports.switchToWindow = (handle) => {
  handle = handle ? handle : 0;
  browser.switchToWindow(browser.getWindowHandles()[handle]);
};
// pages\contactUs.page.js
const { switchToWindow } = require("../utils/switchToWindow");
const { waitForDisplayed } = require("../utils/waitForDisplayed");

//  Page Elements
const contactUsPage = {
  title: 'WebDriver | Contact Us',
  homeUri: '/',
  homeButton: '#contact-us',
  uri: '/Contact-Us/contactus.html',
  url: 'http://www.webdriveruniversity.com'
};
const contactUsHeader = {
  locator: '#contact_me [name="contactme',
  tag: 'h2',
  text: 'CONTACT-US'
};
exports.accessContactUsPage = () => {
  browser.maximizeWindow();
  browser.url(contactUsPage.homeUri);
  waitForDisplayed(contactUsPage.homeButton);
  browser.$(contactUsPage.homeButton).click();
  switchToWindow(1);
};
exports.openContactUsPage = () => {
  browser.maximizeWindow();
  browser.url(contactUsPage.uri);
};
// test\specs\usingPageObjectTest.js
const { accessContactUsPage } = require("../../pages/contactUs.page");

beforeEach(() => {
  console.log('beforeEach');
  accessContactUsPage();
})

describe('Testar o formulário de contato', () => {
  it('Deve enviar mensagem com sucesso', () => {
    console.log('it => Deve enviar mensagem com sucesso');
  });

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.