2

I'm currently trying to write some automated tests for our cordova app written in Angular. My current setup is the following:

Versions:

appium: 1.7.2
wdio-appium-service: 0.2.3
webdriverio: 4.11.0

wdio.conf.js

exports.config = {
  port: 4723,
  logLevel: 'error',
  capabilities: [{
    platformName: 'Android',
    platformVersion: '8.1',
    deviceName: 'any',
    app: '../cordova_app/platforms/android/app/build/outputs/apk/debug/app-debug.apk',
    autoWebview: true,
    autoGrantPermissions: true
  }],
  // specs: ['./tests/spec/**/*.js'],
  specs: ['./tests/spec/login.js'],
  services: ['appium'],
  reporters: ['spec'],
  framework: 'jasmine',
  jasmineNodeOpts: {
    defaultTimeoutInterval: 90000
  }
}

tests/spec/login.js


describe('Language and market choosing process', () => {
    beforeEach(() => {
        browser.timeouts('implicit', 2000);
    });
    afterEach(() => {
        browser.reload();
    });

    it('should go through login process', () => {

        const selectCountryBtn = $('.fsr-login__market-chooser');
        selectCountryBtn.click();
        // everything works so far

        browser.localStorage('POST', {key: 'test', value: 'test123'}); 
        // Failed: unknown error: call function result missing 'value'
    });
});

When I run this test on my Android 8.1 emulator, the test crashes as soon as it reaches the localstorage part with the error:

Failed: unknown error: call function result missing "value"
Error: An unknown server-side error occurred while processing the command.
at localStorage("POST", [object Object]) - index.js:316:3

The localStorage API of WebdriverIO is described here

What am I doing wrong?

4

2 回答 2

3

我同意localStorage操纵是一项棘手的工作,尤其是跨浏览器、跨平台等。在处理应用程序 cookie 或本地存储时,我默认使用纯 JS 命令来实现我的目标。

因此,我建议您尝试使用browser.execute()命令来操作浏览器的本地存储

browser.execute("localStorage.setItem('socialMediaRuinsTheWorld', true)");

或者

browser.execute((keyName, keyValue) => { 
  localStorage.setItem(keyName, keyValue); 
}, "testing", "theLocalStorage");

结果:

在此处输入图像描述

于 2019-11-19T09:08:04.040 回答
1

Appium API不提供功能localStorage

我认为这是你的问题。此外,如果您使用 3.4 版本,请检查 Appium 部分,而不仅仅是协议。本机应用程序没有与浏览器相同的 localStorage,您无法轻松访问它。

于 2019-11-18T23:18:04.160 回答