Bitbar Cloud Appium Server Side test package content for JavaScript

704 views Asked by At

Does anybody know what the contents of the zip file used for server side test running should be when using Javascript as the language? I've looked at the python and ruby examples on the github page (GitHub bitbar-samples repository), but there is nothing for Javascript, and the same is true in the documentation - just java and python. but there is nothing for Javascript.

1

There are 1 answers

0
marverix On BEST ANSWER

From documentation:

All needed files for testing need to be uploaded to cloud as zip package. This package must contain test files, data files and needs to have a Shell script to launch test execution at the root level of the package.

And:

For the cloud side execution to work properly, it is important to have the test suite zip outfitted with the right files. Here we will go through the files and also the correct makeup of the test zip. The most important is the run-tests.sh file, it is responsible for starting the test execution in the cloud and also installing requirements.

So, in theory, you can have in ZIP package only run-tests.sh file. And because this is a simple bash script, you are free what this script will do. Looking at Python and Ruby examples this is how my ZIP structure looks like:

.
├── package.json
├── package-lock.json
├── run-tests.sh
├── test
│   └── specs
│       └── main.js
└── wdio.conf.js

I have used Webdriver.io Testrunner - This is why I have wdio.conf.js and test/specs/main.js.

This is how my run-tests.sh looks like:

#!/usr/bin/env bash

echo "Preparing..."

# Make sure there's no pre-existing `screenshots` file blocking symbolic link creation
rm -rf screenshots

# Recreate screenshots dir
mkdir screenshots

echo "Extracting tests.zip..."
unzip tests.zip

echo "Installing dependencies..."
npm install

echo "Running tests..."
./node_modules/.bin/wdio wdio.conf.js

My main.js (I have used bitbar-sample-app.apk and test method first from the top) :

describe('Bitbar Sample App', () => {
    it('Should radio button should be visible ', async () => {
        let el = await $('//android.widget.RadioButton[@text="Buy 101 devices"]');
        let visible = await el.isDisplayed();
        visible.should.be.true;
    });

    it('Should show failure page', async () => {
        let el;

        console.log("view1: Clicking button - 'Buy 101 devices'");
        el = await $('//android.widget.RadioButton[@text="Buy 101 devices"]');
        el.click();

        console.log("view1: Typing in textfield[0]: Bitbar user");
        el = await $('//android.widget.EditText[@resource-id="com.bitbar.testdroid:id/editText1"]');
        el.setValue('Bitbar user');

        driver.hideKeyboard();
        console.log("view1: Taking screenshot screenshot1.png");
        await takeScreenshot('screenshot1');

        console.log("view1: Clicking button Answer");
        el = await $('//android.widget.Button[@text="Answer"]');
        el.click();

        console.log("view2: Taking screenshot screenshot2.png");
        await takeScreenshot('screenshot2');

        el = await $('//android.widget.TextView[@text="Wrong Answer!"]');
        let txt = await el.getText();
        txt.should.be.equal('Wrong Answer!');
    });

});

And the wdio.conf.js (take a look at before hook):

const path = require('path');

exports.config = {
    runner: 'local',

    framework: 'mocha',
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    },

    logLevel: 'silent',
    deprecationWarnings: true,

    bail: 0,
    waitforTimeout: 10000,
    connectionRetryTimeout: 90000,
    connectionRetryCount: 3,

    reporters: [
        'spec',
        [
            'junit', {
                outputDir: './',
                outputFileFormat: () => {
                    return 'TEST-all.xml';
                }
            }
        ]
    ],

    host: '127.0.0.1',
    port: 4723,
    path:  '/wd/hub',

    services: ['appium'],
    appium: {
        command: 'appium',
        logPath : './',
    },

    specs: [
        './test/specs/**/*.js'
    ],

    capabilities: [{
        platformName: 'Android',
        maxInstances: 1,

        'appium:deviceName': 'Android device',
        'appium:automationName': 'UiAutomator2',
        'appium:app': path.resolve('application.apk'),
        'appium:appActivity': '.BitbarSampleApplicationActivity',
        'appium:appPackage': 'com.bitbar.testdroid',
        'appium:newCommandTimeout': 240
    }],

    before: function() {
        const chai = require('chai');
        global.expect = chai.expect;
        chai.should();

        const fs = require('fs');

        global.takeScreenshot = async (fileName) => {
            let screenshot = await driver.takeScreenshot();
            screenshot = screenshot.replace(/^data:image\/png;base64,/, "")
            let filePath = path.resolve(`./screenshots/${fileName}.png`);
            fs.writeFileSync(filePath, screenshot, 'base64');
        };

    }
}

Last, but not least package.json:

{
  "name": "appium-server-side-example",
  "version": "1.0.0",
  "description": "Bitbar Cloud Appium Server Side Test Example",
  "author": "Marek Sierociński <[email protected]>",
  "license": "ISC",
  "dependencies": {
    "@wdio/appium-service": "^5.16.5",
    "@wdio/cli": "^5.16.7",
    "@wdio/junit-reporter": "^5.15.5",
    "@wdio/local-runner": "^5.16.7",
    "@wdio/mocha-framework": "^5.16.5",
    "@wdio/spec-reporter": "^5.16.5",
    "@wdio/sync": "^5.16.5",
    "chai": "^4.2.0"
  }
}

As you can see I used chai (because I wanted to use the BDD approach) and junit-reporter (because Bitbar devs are Java freaks and you can guess from samples that Cloud is reading JUnit files to read test methods).

It's working for me:

enter image description here