Skip to content

Instantly share code, notes, and snippets.

View pmicko's full-sized avatar
🧪

Petr Míčko pmicko

🧪
View GitHub Profile
@pmicko
pmicko / api.commands.js
Created October 3, 2022 10:38
Cypress - Send test results to elastic server
export const sendDataToElastic = currentTest => {
if (Cypress.env('ELASTIC_URL')) {
const timestampElasticData = new Date().toISOString()
const timestampIndex = format(new Date(),'yyyy.MM.dd')
const index = `qa-test-report-${timestampIndex}`
const elasticData = {
'@timestamp': timestampElasticData,
project: 'project-name-here',
environment: Cypress.env('GITHUB_RUN_ID') ? 'github' : 'local',
testTitle: currentTest.title,
@pmicko
pmicko / login.commands.ts
Last active February 22, 2024 14:02
Cypress 10+ & Identity Server 4 - Programmatic login using API (authorization code flow + PKCE) & UI login
import { LOGIN_SELECTORS as selectors} from "./login.selectors"
import { authenticationData as authData } from "../../fixtures/authData"
const identityServerUrl = Cypress.env("IDENTITY_SERVER_URL")
Cypress.Commands.add('loginAPI', (username, password) => {
const authEndpoint = `${identityServerUrl}/connect/authorize`
const loginPageEndpoint = `${identityServerUrl}/Account/Login`
cy.session(['loginAPI', username], () => {
cy.request({
@pmicko
pmicko / elasticReporter.ts
Created February 15, 2024 19:27
Playwright - Send metadata about test results from every test to ElasticSearch for further analysis (e.g. trends)
import type { Reporter, TestCase, TestResult } from '@playwright/test/reporter';
import axios, { AxiosResponse } from 'axios';
class ElasticReporter implements Reporter {
testResultsPromises: Array<Promise<AxiosResponse>> = [];
elasticUrl = process.env.ELASTIC_URL || undefined;
elasticDataBase = {
project: 'your-project',
team: 'your-team',
repo: 'repo',