0

I am using webdriver.io and Appium to test my apps on Android. I am hitting an issue regarding sessions in Chrome. When I login to a website and close Chrome and re-open it, I can see my session. When I do the same with Appium, it cleans all the sessions between app starts. I tried different options but none of them worked.

Here is the example workflow to login to a website and to open Chrome again.

const driver = await remote(
  {
    capabilities: {
    'appium:waitForIdleTimeout': 100,
    'appium:appPackage': 'com.android.chrome',
    'appium:appActivity': 'com.google.android.apps.chrome.Main',
    'appium:noReset': true,
    'appium:fullReset': false,
    'appium:allowTestPackages': true,
    'appium:automationName': 'UiAutomator2',
    'appium:deviceName': 'Android',
    'appium:newCommandTimeout': 3600,
    platformName: 'Android',
    },
    hostname: "localhost",
    logLevel: "info",
    port: 4723,
  })

await driver.url('https://news.ycombinator.com/login');

await driver.$(`//*[@resource-id='com.android.chrome:id/signin_fre_dismiss_button']`).click();

await driver.switchContext("WEBVIEW_chrome")

const username =  driver.$(`//*[@name='acct']`)
await username.waitForDisplayed({timeout: 10 * 1000})
await username.click()
await username.setValue("myuser")

const password =  driver.$(`//*[@name='pw']`)
await password.click()
await password.setValue("mypassword")

const loginButton = driver.$(`/html/body/form[1]/input`)
await loginButton.click()

const me = driver.$(`//*[@id='me']`)
await me.waitForDisplayed({timeout: 10 * 1000})

// so that we can see the UI
await driver.pause(5 * 1000)

// Open Chrome again and check if the session stays or not
const driver2 = await remote(
  {
    capabilities: {
    'appium:waitForIdleTimeout': 100,
    'appium:appPackage': 'com.android.chrome',
    'appium:appActivity': 'com.google.android.apps.chrome.Main',
    'appium:noReset': true,
    'appium:fullReset': false,
    'appium:allowTestPackages': true,
    'appium:automationName': 'UiAutomator2',
    'appium:deviceName': 'Android',
    'appium:newCommandTimeout': 3600,
    platformName: 'Android',
    },
    hostname: "localhost",
    logLevel: "info",
    port: 4723,
  })


await driver2.url('https://news.ycombinator.com/login');

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.