Skip to content

Instantly share code, notes, and snippets.

View Xotabu4's full-sized avatar
🇺🇦

Oleksandr Khotemskyi Xotabu4

🇺🇦
View GitHub Profile
@Xotabu4
Xotabu4 / setAnnotation.ts
Created September 10, 2024 08:46
Helper methods for working with pw annotations
import { test } from '@playwright/test';
/**
* Updates exsiting annotation or creates new one for current test
*
* @throws {Error} if called outside of test or before/after hooks
*/
export function setAnnotation(annotation: {
type: string;
description: string;
@Xotabu4
Xotabu4 / .zshrc
Created August 26, 2024 09:43
Adds script on terminal load that switches nodejs version based on folder .nvmrc file
# nvm initialization
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# setting auto-switch node version based on .nvmrc
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
import { expect as baseExpect } from "@playwright/test";
import type { APIResponse } from "@playwright/test";
export const expect = baseExpect.extend({
async responseToHaveErrorStatusCode(
requestFunction: () => Promise<APIResponse>,
expected: number
) {
const assertionName = "responseToHaveErrorStatusCode";
@Xotabu4
Xotabu4 / step_decorator.ts
Created July 13, 2023 11:58
Playwright typescript 5.x @step decorator for pageobject methods
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
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 = [];
// name: Trigger tests for run
// description: Triggers automated tests for a test run
// author: Oleksandr Khotemskyi <xotabu4@github.io>
// version: 1.0
// includes: ^runs/view
// excludes:
// js:
$(document).ready( function () {
// TestRail project id -> gitlab pipeline
@Xotabu4
Xotabu4 / uploadfile.js
Created March 15, 2017 10:21
Using FileDetector with protractorjs
// Example of function that will upload file for you.
// Works with Selenium Grid, and transfers file to selenium node automatically.
uploadFile(absFilePath) {
// Importing file detector from selenium-webdriver dependency, this is sub-dependency of protractor
var FileDetector = require('selenium-webdriver/remote/index.js').FileDetector;
// Setting file detector before upload.
browser.setFileDetector(new FileDetector());
this.hiddenInputField.sendKeys(absFilePath).then(()=>{
@Xotabu4
Xotabu4 / index.d.ts
Last active February 4, 2022 01:07
Adding waits, scroll, and retries into webdriverio clicks
/** 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 / config.ts
Last active February 4, 2022 01:05
Describing how add automatic waits, scrolling and retries for wdio click function
import { declareClickCommand } from './customCommands';
export const baseConfig: WebdriverIO.Config = {
bail: 0,
automationProtocol: 'webdriver',
hostname: 'localhost',
protocol: 'http',
port: 4444,
path: '/wd/hub',
baseUrl: '',