Home

Awesome

WTicks

Regression Tests Tested with webdriver.io

WTicks enables you to convert the selenium recorded scripts to simple standalone webdriverio scripts.

To Get Started, you can simply upload the .side file here. Select the Test case / suite, and then WTicks will fetch all the locators used, name those locators and then you can have your generated script.

Please refer to the output structure and suggest if required.

Output structure

Parsing the Test Cases

Here we detect all the locators used by the user. it will assume the a particular command's comment as the name of the locator used in it.

Let's say if the script has:

It will assume the name of the locator: "#foo" as "fooButton" but not as "since we...." / "registeredButton". as it first appeared.

Test Cases are parsed in the order as arranged in recorder.

Requesting for user input

Parsing the commands

Now we map each command inside the script to a webdriverio command then finally we combine to generate the script.

Supported Mappings:

Selenium CommandWebdriverIO Command
click$(...).click()
type$(...).setValue()
echoconsole.log(...)
uncheckif $(...).isSelected() $(...).click()
checkif !$(...).isSelected() $(...).click()
openbrowser.url(...)
pausebrowser.pause(...)
sendKeysbrowser.sendKeys([Key....,...])
debuggerbrowser.debug()
setWindowSizebrowser.size(..., ...)
runScriptbrowser.script(...)
assertText or verifyTextexpect($(...)).toHaveText(...)
assertTitle or verifyTitleexpect(browser).toHaveTitle(...)
assertElementPresent or verifyElementPresentexpect($(...)).toBePresent()
assertEditable or verifyEditableexpect($(...)).toBeEnabled()
assertChecked or verifyCheckedexpect($(...)).toBeChecked()
assertValue or verifyValueexpect($(...)).toHaveValue(...)
assertNotText or verifyNotTextexpect($(...)).not.toHaveText(...)
assertNotTitle or verifyNotTitleexpect(browser).not.toHaveTitle(...)
assertElementNotPresent or verifyElementPresentexpect($(...)).not.toBePresent()
assertNotEditable or verifyNotEditableexpect($(...)).not.toBeEnabled()
assertNotChecked or verifyNotCheckedexpect($(...)).not.toBeChecked()
assertNotValue or verifyNotValueexpect($(...)).not .toHaveValue(...)
waitForElementEditable$(...).waitForEnabled({ timeout: ..., reverse: false })
waitForElementNotEditable$(...).waitForEnabled({ timeout: ..., reverse: true })
waitForElementPresent$(...).waitForExist({ timeout: ..., reverse: false})
waitForElementNotPresent$(...).waitForExist({ timeout: ..., reverse: true})
waitForElementVisible$(...).waitForDisplayed({ timeout: ..., reverse: false })
waitForElementNotVisible$(...).waitForDisplayed({ timeout: ..., reverse: true })

Example Output:

import { remote, Key } from "webdriverio"; // Key is for sendKeys command
import { expect } from "expect-webdriverio";
// above lines for the imports required for performing assertions and running a standalone runner

// if you are using browser runner to execute the scripts then you can ignore the below configuration for the browser
const browser = await remote({
	capabilities: {
		browserName: "chrome",
		"goog:chromeOptions": {
			args: process.env.CI ? ["headless", "disable-gpu"] : [],
		},
	},
});

class Locators {
	$(location) {
		return browser.$(location); // you can either have it like this or simply $(location)
	}
	get search_bar_location() {
		return this.$("#\\:Ril56\\:-label");
	}
	get youtube_search_bar() {
		return this.$("#\\:Ril56\\:");
	}
	get search_bar_icon() {
		return this.$(".MuiInputAdornment-root > span");
	}
	get tooltip() {
		return this.$(".MuiTooltip-tooltip"); // $(".MuiTooltip-tooltip"); would do if you are running in WDIO Test runner: https://webdriver.io/docs/setuptypes/#the-wdio-testrunner
	}
	get body() {
		// name of the function = name of the locator associated with it
		return this.$("#__next"); // locator
	}
}
//

const pageClass = new Locators();

// TEST CASE
async function validating_the_search_bar() {
	// name of the function = name of the test case
	await browser.url("https://yticks.vercel.app/video"); // mapped webdriverio commands
	await browser.setWindowSize(518, 480);
	await expect(pageClass.search_bar_location).toHaveText(
		"Paste a valid Youtube URL"
	);
	await expect(pageClass.youtube_search_bar).toBePresent();
	await pageClass.youtube_search_bar.click();
	await expect(pageClass.search_bar_icon).toBePresent();
	await pageClass.search_bar_icon.click();
	await browser.pause(600);
	await pageClass.search_bar_icon.click();
	await expect(pageClass.tooltip).toHaveText("Invalid Input");
	await pageClass.youtube_search_bar.click();
	await pageClass.body.click();
	await pageClass.youtube_search_bar.setValue("checking");
	await expect(pageClass.search_bar_location).toHaveText(
		"Paste a valid Youtube URL"
	);
	await pageClass.search_bar_icon.click();
	await expect(pageClass.tooltip).toBePresent();
	await pageClass.youtube_search_bar.click();
}

(async () => {
	// list of test cases to run in case of the suite, it will list all the names of the test cases to run here
	await validating_the_search_bar();

	await browser.deleteSession(); // deletes the session after executing the cases
	// not required if used in the WDIO Test Runner
})();

Setup

Missing Pieces

There are several commands I missed as mentioned here: https://www.selenium.dev/selenium-ide/docs/en/api/commands, part of the reason is because i am looking for the expected webdriverio command or else it is selenium specific, either way I might have missed too, Happy to take note some critical misses.