Skip to content

Commit

Permalink
chore(appium): query state of app before trying to close
Browse files Browse the repository at this point in the history
  • Loading branch information
luisecm committed Mar 19, 2024
1 parent 67d44b3 commit d0ba280
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 33 deletions.
26 changes: 21 additions & 5 deletions config/wdio.mac.app.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,28 @@ export const config: WebdriverIO.Config = {
allureReporter.addAttachment(imageTitle, data, "image/png");

// Close application if still open
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_BUNDLE_ID,
},
]);
await terminateApplication(MACOS_BUNDLE_ID);
}
},
},
};

export async function terminateApplication(bundle: string) {
const appState = await queryAppStateMacOS(bundle);
if (appState !== 1) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: bundle,
},
]);
}
}

export async function queryAppStateMacOS(bundle: string) {
const queryAppState = await driver.executeScript("macos: queryAppState", [
{
bundleId: bundle,
},
]);
return queryAppState;
}
26 changes: 21 additions & 5 deletions config/wdio.mac.ci.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,28 @@ export const config: WebdriverIO.Config = {
allureReporter.addAttachment(imageTitle, dataImage, "image/png");

// Close application if still open
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_BUNDLE_ID,
},
]);
await terminateApplication(MACOS_BUNDLE_ID);
}
},
},
};

export async function terminateApplication(bundle: string) {
const appState = await queryAppStateMacOS(bundle);
if (appState !== 1) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: bundle,
},
]);
}
}

export async function queryAppStateMacOS(bundle: string) {
const queryAppState = await driver.executeScript("macos: queryAppState", [
{
bundleId: bundle,
},
]);
return queryAppState;
}
46 changes: 23 additions & 23 deletions config/wdio.mac.multiremote.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,36 @@ export const config: WebdriverIO.Config = {
allureReporter.addAttachment(imageTitle, data, "image/png");

// Close applications if open
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_USER_A_BUNDLE_ID,
},
]);
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_USER_B_BUNDLE_ID,
},
]);
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_USER_C_BUNDLE_ID,
},
]);
await terminateApplication(MACOS_USER_A_BUNDLE_ID);
await terminateApplication(MACOS_USER_B_BUNDLE_ID);
await terminateApplication(MACOS_USER_C_BUNDLE_ID);
}
},
},

afterSuite: async function (suite) {
// Close second and third applications if open
await terminateApplication(MACOS_USER_B_BUNDLE_ID);
await terminateApplication(MACOS_USER_C_BUNDLE_ID);
},
};

export async function terminateApplication(bundle: string) {
const appState = await queryAppStateMacOS(bundle);
if (appState !== 1) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_USER_B_BUNDLE_ID,
},
]);
await driver.executeScript("macos: terminateApp", [
{
bundleId: MACOS_USER_C_BUNDLE_ID,
bundleId: bundle,
},
]);
},
};
}
}

export async function queryAppStateMacOS(bundle: string) {
const queryAppState = await driver.executeScript("macos: queryAppState", [
{
bundleId: bundle,
},
]);
return queryAppState;
}

0 comments on commit d0ba280

Please sign in to comment.