Wednesday, October 28, 2020

React Native: Run automation tests by dynamically picking an apk ( or ipa )

It seems not a big deal when you are only develop working on a project and running your builds locally but it does count when working as team and your deployments are automated and running on some tool. In that case the paths to executable files will vary from system to system. In such a case its very important that your working directory is dynamic and after that we are selecting some file to apply may be some transformation or execute to what ever.

Following is an example of this, I wanted to run my react-native UI automation tests for android but pick the apk dynamically and it will work on any member's machine like a charm who is working on this project.

And this single line of code is the king:

var parentDir = path.resolve(process.cwd(), '../..');

The whole wdio local config is as follows:

const path = require('path');
const { config } = require('./wdio.shared.conf');
var parentDir = path.resolve(process.cwd(), '../..');
// ============
// Specs
// ============
config.specs = ['./tests/specs/app*.spec.js'];

config.capabilities = [
    maxInstances: 1,
    platformName: 'Android',
    platformVersion: '8',
    deviceName: 'Pixel_XL_API_27',
    app: `${parentDir}\\android\\app\\build\\outputs
    appWaitActivity: '*',
    noReset: true,
    'goog:chromeOptions': {
      w3c: true,
      args: [ '--no-first-run' ],

exports.config = config;

I hope that small piece of advice with practical code will help you to understand the importance of introducing element of dynamicity in your projects.

No comments:

Post a Comment

.NET 7 Minimal APIs Series - An Introduction

Introduction to .NET 7 Minimal APIs The release of .NET 6 brought about several exciting features and improvements, and one of the most exci...