|
| 1 | +import { remote } from "webdriverio"; |
| 2 | +import { expect } from "chai"; |
| 3 | + |
| 4 | +// --- Helpers --- |
| 5 | +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 6 | + |
| 7 | +async function clickCss(driver, selector, delay = 1000) { |
| 8 | + const el = await driver.$(selector); |
| 9 | + expect(el).to.exist; |
| 10 | + await el.click(); |
| 11 | + await sleep(delay); |
| 12 | +} |
| 13 | + |
| 14 | +async function clickXPath(driver, xpath, delay = 1000) { |
| 15 | + const el = await driver.$(xpath); |
| 16 | + expect(el).to.exist; |
| 17 | + await el.click(); |
| 18 | + await sleep(delay); |
| 19 | +} |
| 20 | + |
| 21 | +async function typeInInput(driver, selector, text, delay = 1000) { |
| 22 | + const el = await driver.$(selector); |
| 23 | + expect(el).to.exist; |
| 24 | + await el.clearValue(); |
| 25 | + await el.setValue(text); |
| 26 | + await sleep(delay); |
| 27 | +} |
| 28 | + |
| 29 | +async function selectOptionByText(driver, text, delay = 1000) { |
| 30 | + const el = await driver.$(`//*[contains(text(),'${text}')]`); |
| 31 | + expect(el).to.exist; |
| 32 | + await el.click(); |
| 33 | + await sleep(delay); |
| 34 | +} |
| 35 | + |
| 36 | +// --- Test --- |
| 37 | +describe("BitBoxApp Base Test", function () { |
| 38 | + this.timeout(180000); |
| 39 | + |
| 40 | + let driver; |
| 41 | + before(async () => { |
| 42 | + |
| 43 | + const opts = { |
| 44 | + path: '/', |
| 45 | + port: 4723, |
| 46 | + capabilities: { |
| 47 | + platformName: 'Android', |
| 48 | + 'appium:deviceName': 'Android Emulator', |
| 49 | + 'appium:automationName': 'UiAutomator2', |
| 50 | + 'appium:app': `./apk/app-debug.apk`, |
| 51 | + 'appium:noReset': true, |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + driver = await remote(opts); |
| 56 | + |
| 57 | + // Switch to WebView if present |
| 58 | + const contexts = await driver.getContexts(); |
| 59 | + const webview = contexts.find((c) => c.startsWith("WEBVIEW_")); |
| 60 | + if (webview) await driver.switchContext(webview); |
| 61 | + }); |
| 62 | + |
| 63 | + after(async () => { |
| 64 | + if (driver) await driver.deleteSession(); |
| 65 | + }); |
| 66 | + |
| 67 | + it("should navigate and select Italian language", async () => { |
| 68 | + await clickCss(driver, "button._transparent_1s0sp_84._button_1s0sp_1._button_1fz28_1", 2000); |
| 69 | + await clickXPath(driver, "//*[contains(text(),'General')]", 2000); |
| 70 | + await clickXPath(driver, "//*[contains(text(),'Language')]", 2000); |
| 71 | + |
| 72 | + // Search and select |
| 73 | + await typeInInput(driver, "input", "Italian", 2000); |
| 74 | + await selectOptionByText(driver, "Italiano", 2000); |
| 75 | + }); |
| 76 | +}); |
0 commit comments