Skip to content

Instantly share code, notes, and snippets.

@erdemkiiliic
erdemkiiliic / jsXMLHTTPListener.js
Last active September 10, 2023 09:39
xml/http listener with js
if (typeof window.jsXMLHTTPListener === 'undefined') {
let jsXMLHTTPListener = {
isCallFinishedStatus: 1,
pointerSize: 0,
pointerFinishSize: 0,
isCallFinished: function() {
return 1 === this.isCallFinishedStatus;
},
setCallFinished: function(i = 0) {
this.isCallFinishedStatus = i;
@erdemkiiliic
erdemkiiliic / getAvailableTestIds.tsx
Last active September 6, 2023 11:05 — forked from sibelius/getAvailableTestIds.tsx
get all data-testid from your DOM, useful when working in testing-library tests
// thanks to http://twitter.com/@KrComet
export const getAvailableTestIds = () => {
// eslint-disable-next-line
console.log(new Set([...document.querySelectorAll('[data-testid]')].map((el) => el.dataset.testid)));
};
export const getAvailableIds = () => {
console.log(new Set([...document.querySelectorAll('[id]')].map((el) => el.id)));
};
@erdemkiiliic
erdemkiiliic / BaseTest.java
Last active November 20, 2023 13:02
custom screen recorder for UI tests
private final CustomScreenRecorder screenRecorder;
public BaseTest() throws IOException, AWTException {
this.screenRecorder = new CustomScreenRecorder(new File(System.getProperty("user.dir") + "/target/screen-records"));;
}
@AfterScenario
public void tearDown(ExecutionContext context) {
if(WebDriverManager.getInstance().getWebDriver() != null){
WebDriverManager.getInstance().killDriver();
@erdemkiiliic
erdemkiiliic / CustomScreenshotGrabber.java
Last active June 29, 2023 21:12
Attaching custom screenshot to gauge report
public class CustomScreenshotGrabber implements CustomScreenshotWriter {
@Override
public synchronized String takeScreenshot() {
if (WebDriverManager.getInstance().getWebDriver() != null) {
TakesScreenshot driver = (TakesScreenshot) WebDriverManager.getInstance().getWebDriver();
String screenshotFileName = String.format("screenshot-%s.png", UUID.randomUUID());
try {
Files.write(Paths.get((".gauge/screenshots"), screenshotFileName),
driver.getScreenshotAs(OutputType.BYTES));
} catch (IOException e) {
@erdemkiiliic
erdemkiiliic / BaseTest.java
Last active June 27, 2023 21:05
Capturing a screenshot after each step in Gauge that doesn't contain "VI" and "verify" in the step name.
@AfterStep
public void saveScreenshot(ExecutionContext context) {
if (WebDriverManager.getInstance().getWebDriver() != null) {
if(!(context.getCurrentStep().getDynamicText().contains("VI")) && !(context.getCurrentStep().getDynamicText().contains("verify"))) {
waitHelper.waitUntilPageIsReady();
Gauge.captureScreenshot();
log.warn("Screenshot captured!");
}
}
}
@erdemkiiliic
erdemkiiliic / WebDriverManager.java
Last active June 14, 2023 18:07
DriverService usage - Selenium
private static DriverService service;
private ThreadLocal<WebDriver> webDriver;
public void startTest(String browserName){
webDriver = new ThreadLocal<>();
switch(browserName.toLowerCase()){
case "chrome":
io.github.bonigarcia.wdm.WebDriverManager.chromedriver().setup();
if (service == null || !service.isRunning()) {
@erdemkiiliic
erdemkiiliic / jmeter-help
Last active April 11, 2022 14:54
Jmeter cli mode - useful commands
on mac: sh jmeter
example:
jmeter -n -t my_test.jmx -l log.csv -H my.proxy.server -P 8000
jmeter -n -t /path/to/your/test_plan.jmx -l /path/to/results_file.jtl
_____users and rampup overrided from cli
_____For this, the thread properties should be defined as follows: ${__P(Users, 1)} ${__P(RampUp, 1)}
@erdemkiiliic
erdemkiiliic / MatcherExtensions.kt
Last active March 2, 2023 12:45
Clean waiting in Espresso (Kotlin)
fun Matcher<View>.doOnView(vararg actions: ViewAction) {
doOnView_Method(matcher = this, actions = *actions)
}
fun Matcher<View>.assertOnView(vararg assertions: ViewAssertion) {
assertOnView_Method(matcher = this, assertions = *assertions)
}
fun Matcher<View>.waitForView(millis: Int = 5000, millisPerTry: Long = 200): ViewInteraction {
return waitForView_Method(viewMatcher = this, waitMillis = millis, waitMillisPerTry = millisPerTry)
@erdemkiiliic
erdemkiiliic / XCUIElement+Wait.swift
Last active March 6, 2022 18:19 — forked from ryanpato/XCUIElement+Wait.swift
Clean waiting in XCUITest
//
// XCUIElement+Wait.swift
//
// Created by Ryan Paterson on 12/12/2020.
//
import XCTest
extension XCUIElement {
@erdemkiiliic
erdemkiiliic / ios15_native_bundle_ids
Created February 17, 2022 21:05
iOS 15 - Bundle IDs for native iOS and iPadOS apps
App Name | Bundle ID
---------------------------------
Activity | com.apple.Fitness
App Store | com.apple.AppStore
Apple Store | com.apple.store.Jolly
Books | com.apple.iBooks
Calculator | com.apple.calculator
Calendar | com.apple.mobilecal
Camera | com.apple.camera
Clips | com.apple.clips