From eb1ddbb1321d12fc71412f44e50f9ca766ec24b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljko=20Filipin?= Date: Thu, 21 Nov 2024 14:41:05 +0100 Subject: [PATCH] selenium: Replace Node.js Assert library with WebdriverIO Expect library Assertions from Expect library are more readable that assertions from Assert library. Bug: T325740 Change-Id: I9224c52975919a512ac3b0342bb3805edecec6b3 --- tests/selenium/pageobjects/popups.page.js | 21 ++++----------------- tests/selenium/specs/page_previews.js | 11 +++++------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/selenium/pageobjects/popups.page.js b/tests/selenium/pageobjects/popups.page.js index c20cef9ee..6c785da87 100644 --- a/tests/selenium/pageobjects/popups.page.js +++ b/tests/selenium/pageobjects/popups.page.js @@ -7,7 +7,6 @@ const Util = require( 'wdio-mediawiki/Util' ), TEST_PAGE_POPUPS_TITLE = 'Page popups test page', POPUPS_SELECTOR = '.mwe-popups', - PAGE_POPUPS_SELECTOR = '.mwe-popups-type-page', PAGE_POPUPS_LINK_SELECTOR = '.mw-body-content ul a', POPUPS_MODULE_NAME = 'ext.popups.main'; @@ -18,6 +17,10 @@ async function makePage( title, path ) { await bot.edit( title, content ); } class PopupsPage extends Page { + get pagePopupsSelector() { + return $( '.mwe-popups-type-page' ); + } + async setupPagePreviews() { return browser.call( async () => { const path = `${ __dirname }/../fixtures/`; @@ -55,22 +58,6 @@ class PopupsPage extends Page { await $( PAGE_POPUPS_LINK_SELECTOR ).moveTo(); } - async doNotSeePreview( selector ) { - return browser.waitUntil( async () => !( await $( selector ).isDisplayed() ) ); - } - - async doNotSeePagePreview() { - return this.doNotSeePreview( PAGE_POPUPS_SELECTOR ); - } - - async seePreview( selector ) { - return await $( selector ).isDisplayed(); - } - - async seePagePreview() { - return await this.seePreview( PAGE_POPUPS_SELECTOR ); - } - async openPagePopupsTest() { return super.openTitle( TEST_PAGE_POPUPS_TITLE ); } diff --git a/tests/selenium/specs/page_previews.js b/tests/selenium/specs/page_previews.js index c3cd382c6..0e2773a4f 100644 --- a/tests/selenium/specs/page_previews.js +++ b/tests/selenium/specs/page_previews.js @@ -1,7 +1,6 @@ 'use strict'; -const assert = require( 'assert' ), - page = require( '../pageobjects/popups.page' ); +const page = require( '../pageobjects/popups.page' ); describe( 'Dwelling on a valid page link', function () { before( async function () { @@ -15,24 +14,24 @@ describe( 'Dwelling on a valid page link', function () { it( 'I should see a page preview', async function () { await page.dwellPageLink(); - await assert( await page.seePagePreview(), 'Page preview is shown.' ); + await expect( await page.pagePopupsSelector ).toBeDisplayed( { message: 'Page preview is shown.' } ); } ); it( 'I should not see a page preview on hash fragment', async function () { await page.dwellPageFragment(); - assert( await page.doNotSeePagePreview(), 'Page preview is not shown.' ); + await expect( await page.pagePopupsSelector ).not.toBeDisplayed( { message: 'Page preview is not shown.' } ); } ); it( 'Abandoning link hides page preview', async function () { await page.dwellPageLink(); await page.abandonLink(); - assert( await page.doNotSeePagePreview(), 'Page preview is kept hidden.' ); + await expect( await page.pagePopupsSelector ).not.toBeDisplayed( { message: 'Page preview is kept hidden.' } ); } ); it( 'Quickly hovering, abandoning and re-hovering a link shows page preview', async function () { await page.hoverPageLink(); await page.abandonLink(); await page.dwellPageLink(); - assert( await page.seePagePreview(), 'Page preview is shown.' ); + await expect( await page.pagePopupsSelector ).toBeDisplayed( { message: 'Page preview is shown.' } ); } ); } );