Skip to content

Instantly share code, notes, and snippets.

@klamping
klamping / commands.js
Last active April 10, 2023 14:27
Adding custom WebdriverIO commands from a external file (note 'before' hook on line 168 of conf file)
module.exports = {
getUrlAndTitle: function (customVar) {
return {
url: this.getUrl(),
title: this.getTitle(),
customVar: customVar
};
},
otherCommand: function () {
// do something else
@flawyte
flawyte / Device.java
Last active April 7, 2024 15:28
How to get an Android device's serial number, visible to the user in "Settings > About phone/tablet/device > Status > Serial number".
import android.os.Build;
import java.lang.reflect.Method;
public class Device {
/**
* @return The device's serial number, visible to the user in {@code Settings > About phone/tablet/device > Status
* > Serial number}, or {@code null} if the serial number couldn't be found
*/
public static String getSerialNumber() {
@ChadKillingsworth
ChadKillingsworth / e2e-shadowdom.md
Last active July 6, 2023 06:54
Selenium Testing with Shadow DOM

End-to-end Testing with Shadow DOM

As the web component specs continue to be developed, there has been little information on how to test them. In particular the /deep/ combinator has been deprecated in Shadow DOM 1.0. This is particularly painful since most end-to-end testing frameworks rely on elements being discoverable by XPath or calls to querySelector. Elements in Shadow DOM are selectable by neither.

WebDriver.io

Webdriver.io has the standard actions by selectors, but also allows browser executable scripts to return an element

getTextNodesIn = (node) => {
var textNodes = [];
if (node.nodeType == 3) {
textNodes.push(node);
} else {
var children = node.childNodes;
for (var i = 0, len = children.length; i < len; ++i) {
textNodes.push.apply(textNodes, this.getTextNodesIn(children[i]));
}
}