Skip to content

Instantly share code, notes, and snippets.

Avatar
🌚

Oleksandr Khotemskyi Xotabu4

🌚
View GitHub Profile
@Xotabu4
Xotabu4 / Wait.ts
Last active Nov 30, 2020
Implementation of wait with return of last condition result
View Wait.ts
type OptionsPart = {
timeoutMs?: number,
poolIntervalMs?: number,
errorMessage?: string,
falsyError?: boolean
}
export async function waitForResult<T>(options: {
predicate: () => Promise<{ bool: boolean, lastResult: T }>,
@Xotabu4
Xotabu4 / config.ts
Last active Nov 26, 2020
Describing how add automatic waits, scrolling and retries for wdio click function
View config.ts
import { declareClickCommand } from './customCommands';
export const baseConfig: WebdriverIO.Config = {
bail: 0,
automationProtocol: 'webdriver',
hostname: 'localhost',
protocol: 'http',
port: 4444,
path: '/wd/hub',
baseUrl: '',
View config.ts
// Somewhere in protractor onPrepare:
onPrepare: function () {
patchProtractorWait()
afterEach(async function () {
// Wait fix needs to be re-applied after browser restart, checking if function was patched already:
const waitFunctionSymbols = Object.getOwnPropertySymbols(browser.wait);
if (!waitFunctionSymbols.includes(WAIT_FIX)) {
patchProtractorWait();
@Xotabu4
Xotabu4 / process_end_listener.ts
Created Feb 13, 2020
Trying to close protractor browser on process exit
View process_end_listener.ts
import { browser } from 'protractor';
/**
* @experimental
*/
export function registerCloseBrowserOnProcessEndListener() {
async function exitHandler(options, exitCode) {
console.log('[registerCloseBrowserOnProcessEndListener] called!');
try {
await browser.close();
View drawRedSquare.ts
/**
* @experimental
* This function tries to highligh exact point at webpage where click was failed,
* by placing special red square into failed coordinate.
* So allure screenshots will show exact failing location
* @param error exception object
*/
async function drawClickPointAttempt(error: Error) {
try {
const text = error.message;
View promise.ts
const sendCommand = (target, method, params) => {
return new Promise((resolve, reject) => {
chrome.debugger.sendCommand(target, method, params, result => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(result);
console.log(method, result);
}
});
@Xotabu4
Xotabu4 / index.ts
Created Jan 10, 2020
Test files management module. TestResources
View index.ts
import * as path from 'path'
import * as fs from 'fs'
const resFolderImages = './resources/images/'
const resFolderAudio = './resources/audio/'
const resFolderOffice = './resources/office/'
const resFolderVideos = './resources/videos/'
const resFolderOther = './resources/other/'
export interface FileStats {
@Xotabu4
Xotabu4 / LoginForm.ts
Last active Jul 16, 2019
Protractor Page Object with ShadowDOM example. Uses Protractor By.js - http://www.protractortest.org/#/api?view=webdriver.By.js
View LoginForm.ts
import { browser, By, element, ElementFinder, ExpectedConditions as EC } from 'protractor';
class LoginModal {
private get shadowDOM() {
return element(By.js(function () {
// returned value must be array
return [document.querySelector('CSSselectorForShadowDomContainingElement').shadowRoot];
}));
}
You can’t perform that action at this time.