Skip to content

Instantly share code, notes, and snippets.

View kneczaj's full-sized avatar

Kamil Neczaj kneczaj

View GitHub Profile
@kneczaj
kneczaj / selenium_page_pattern_factory.ts
Last active September 27, 2020 23:23
selenium_page_pattern_factory
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
// a way to customise Selenium WebElementPromise
export class ElementPromise extends WebElementPromise {
constructor(driver: AugmentedThenableWebDriver, el: Promise<WebElement>) {
super(driver, el);
}
getDriver(): AugmentedThenableWebDriver {
@kneczaj
kneczaj / selenium_find_with_wait.ts
Created September 25, 2020 07:41
Selenium find
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
function findWithWait(locator: Locator, timeout: number = defaultTimeout): WebElementPromise {
return driver.wait(until.elementLocated(locator), timeout)
}
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/1.0/"
function findChildElement(parent: WebElement, locator: Locator, timeout?: number): Promise<WebElement> {
return driver.wait<WebElement>(async function (driver) {
try {
return await parent.findElement(locator);
} catch (e) {
return false;
}
@kneczaj
kneczaj / merge_request_states.ts
Created September 10, 2020 15:29
maerge_request_states
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
type ItemRequestStateBeforeMerge<T> = { [K in keyof T]: ItemRequestState<T[K]> }
type ItemRequestStateAfterMerge<T> = ItemRequestState<{ [K in keyof T]: T[K] }>
export function mergeStates<T>(
input: ItemRequestStateBeforeMerge<T>
): ItemRequestStateAfterMerge<T> {
@kneczaj
kneczaj / index.sass
Created September 2, 2020 10:36
Styles
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
.flex-1
flex: 1
min-height: 0
min-width: 0
flex-basis: 0
@kneczaj
kneczaj / confirm-dialog.tsx
Created September 1, 2020 09:54
Material UI dialog with hooks
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
import React from 'react';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
@kneczaj
kneczaj / confirm-dialog.tsx
Created August 12, 2020 23:11
Confirm dialog
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
import React from 'react';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
@kneczaj
kneczaj / placeholder.tsx
Created August 12, 2020 23:09
Placeholder component
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
import React, {useContext, useState} from "react";
import {isUndefined} from "../util";
export interface Props {
children: JSX.Element | React.ReactNode;
}
@kneczaj
kneczaj / click.ts
Created July 16, 2020 14:22
Selenium click on element anyway
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
driver.executeScript(() => arguments[0].click(), element /* WebElementPromise */);
@kneczaj
kneczaj / test-base.ts
Last active February 29, 2020 02:04
E2E base test runner
// To the extent possible under law, Kamil Neczaj has waived all copyright and related or neighboring rights to this code,
// which is published here under license CC0, full text of the license here: http://creativecommons.org/publicdomain/zero/
import { AugmentedThenableWebDriver, getAugmentedDriver } from "./driver";
import { logging } from "selenium-webdriver";
export function e2eTest(label: string, testFn: (driver: () => AugmentedThenableWebDriver) => void) {
describe(label, async () => {
let driver: AugmentedThenableWebDriver;