Adjust the config like this
import { longPress } from "./longPress";
export const config: WebdriverIO.Config = {
//...
before: function (capabilities, specs) {
browser.addCommand("longPress", longPress, true);
},
//...
};
And use it like this
import { driver } from "@wdio/globals";
describe("Custom longPress", () => {
if (driver.isAndroid) {
it("should close the Android settings do a longPress on the Photos app", async () => {
await driver.back();
const photosApp = await $(
'//android.widget.TextView[@content-desc="Photos"]'
);
await photosApp.waitForDisplayed();
await photosApp.longPress();
const widget = await $(
'//android.widget.LinearLayout[@resource-id="com.google.android.apps.nexuslauncher:id/popup_container"]'
);
widget.waitForDisplayed();
});
}
if (driver.isIOS) {
it("should closs the iOS settings and do a longPress on the Settings App", async () => {
await driver.terminateApp("com.apple.Preferences");
const filesApp = await $('-ios predicate string:name == "Files"');
await filesApp.waitForDisplayed();
await filesApp.longPress();
await $(
'-ios predicate string:label == "Edit Home Screen"'
).waitForDisplayed();
});
}
});