Skip to content

Instantly share code, notes, and snippets.

View Xotabu4's full-sized avatar
🇺🇦

Oleksandr Khotemskyi Xotabu4

🇺🇦
View GitHub Profile
@Xotabu4
Xotabu4 / step_decorator.ts
Created July 13, 2023 11:58
Playwright typescript 5.x @step decorator for pageobject methods
View step_decorator.ts
import { test } from '@playwright/test';
/**
* Decorator that wraps a function with a Playwright test step.
* Used for reporting purposes.
*
* @example
```
import { step } from './step_decorator';
class MyTestClass {
@Xotabu4
Xotabu4 / slack_playwright_reporter.ts
Created June 5, 2023 08:27
Playwright reporter for slack
View slack_playwright_reporter.ts
import type {
FullResult, Reporter, TestCase, TestResult,
} from '@playwright/test/types/testReporter';
class PlaywrightSlackReporter implements Reporter {
allResults: Array<{ test: TestCase, result: TestResult }>;
constructor(private conf: { enabled: boolean, webhookUrl: string }) {
this.conf = conf;
this.allResults = [];
@Xotabu4
Xotabu4 / drawClickPointAttempt.ts
Created October 20, 2021 16:12
This function draws red square by coordinates provided from webdriver error. So screenshot will show what element is covered
View drawClickPointAttempt.ts
import { browser } from 'protractor';
/**
* This function tries to highlight 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
*/
export async function drawClickPointAttempt(error: Error) {
try {
View zip_and_send_to_allure_server.ts
import * as fs from 'fs';
import * as path from 'path';
import { URL } from 'url';
import got from 'got';
import FormData from 'form-data';
async function compress(srcFolder: string, zipFilePath: string) {
const archiver = require('archiver');
const targetBasePath = path.dirname(zipFilePath);
@Xotabu4
Xotabu4 / upload_results.js
Created March 31, 2021 11:51
Upload results to awesome https://github.com/kochetkov-ma/allure-server and generate report
View upload_results.js
/**
* @url https://github.com/kochetkov-ma/allure-server
*/
const got = require('got')
const fs = require('fs');
const FormData = require('form-data');
const baseUrl = new URL(`http://93.126.97.71:5001`)
View 4_lesson_homework.ts
// Use http://93.126.97.71:10082/mp3-players to simplify these tests. Mp3 players does not have custom params on details page.
// bonus points:
// - use preconditions
// - use dataprovider
describe('Items', function () {
// You must be logged in to use wishlist
it('can be added to wishlist', function () {
@Xotabu4
Xotabu4 / 10-js-ui-wdio.ts
Created February 25, 2021 20:16
Hometask after 2 lesson
View 10-js-ui-wdio.ts
/**
- Try to implement as much tests as you can
- Do not overload tests with logic, be simple
- browser.pause() allowed
- copy/paste is allowed
- prefer css selectors
- don't forget about assertions
*/
// this test gives you 20 points
@Xotabu4
Xotabu4 / shadow$.ts
Last active February 1, 2021 23:56
Searching inside shadow doms in protractor helper function
View shadow$.ts
import { element, By } from 'protractor';
/**
* Find element inside nested shadow doms:
* shadow1(shadowDOM -> shadow2(shadowDOM -> shadow3(shadowDOM -> button)))
*
* @example
* new SomeElement(shadow$(['shadow1', 'shadow2', 'shadow3'], 'button')).click()
*
* @param shadowDomCssSelectors
@Xotabu4
Xotabu4 / index.d.ts
Last active February 4, 2022 01:07
Adding waits, scroll, and retries into webdriverio clicks
View index.d.ts
/** Add custom browser and Element commands here */
export {};
declare global {
namespace WebdriverIO {
// interface Browser {
// browserCustomCommand: (arg: any) => Promise<void>
// }
// interface MultiRemoteBrowser {
// browserCustomCommand: (arg: any) => Promise<void>
@Xotabu4
Xotabu4 / Wait.ts
Last active November 30, 2020 18:14
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 }>,