Skip to content

Instantly share code, notes, and snippets.

View Xotabu4's full-sized avatar
🇺🇦

Oleksandr Khotemskyi Xotabu4

🇺🇦
View GitHub Profile
@Xotabu4
Xotabu4 / .zshrc
Created October 7, 2024 18:31
auto switch node version using nvm and .nvmrc
# 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)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
@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 = [];
@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
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 {
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
/**
* @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`)
// 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 () {