Branching

Branching, in revision control and software configuration management, is the duplication of an object under revision control (such as a source code file, or a directory tree) so that modifications can happen in parallel along both branches.

The originating branch is sometimes called the parent branch, the upstream branch (or simply upstream, especially if the branches are maintained by different organisations or individuals), or the backing stream. Child branches are branches that have a parent; a branch without a parent is referred to as the trunk or the mainline.[1]

In some distributed revision control systems, such as Darcs, there is no distinction made between repositories and branches; in these systems, fetching a copy of a repository is equivalent to branching.

Branching also generally implies the ability to later merge or integrate changes back onto the parent branch. Often the changes are merged back to the trunk, even if this is not the parent branch. A branch not intended to be merged (e.g. because it has been relicensed under an incompatible license by a third party, or it attempts to serve a different purpose) is usually called a fork.

Setting up .gitignore to ignore unwanted contents at cloud

.gitignore file should be at root of the project with following pattern,

  • Add the file name like project.settings to ignore it
  • If we need to ignore multiple files with same extensions we can use *.settings
  • If we need to ignore multiple files in a directory with same extensions we can use /src/*.xml
  • If we needs to ignore a directory with its all contents, we can use /bin/*

my .gitignore:

/bin/*
/gen/*
/results/*
*.class
*.log
*.png
.project
.classpath
.hg
.settings

Appium Android – How to handle ‘Install via USB’ pop ups on Xiaomi devices

During Appium Android automation on Xiaomi devices there comes ‘Install Via USB’ popup every time execution is triggered. It can be handled using following steps,

  1. Signup with MI account on device if not already signed up
  2. Settings Screen > Additional Settings > Developer options > Turn off ‘Miui Optimizations’ option > Restart device
  3. Settings Screen > Security > Permissions > Icon at top right corner > Turn On “Install via USB” option
  4. Settings Screen > Additional Settings > Developer options > Turn On/Off “USB Debugging” > Turn On “Install vis USB” option

Trigger execution and pop-up will not come again.

Communicate and Debug apps on iOS Real Devices

Communicating iOS apps on real devices was never a straight thing earlier. In this article we’ll collect available open source tools to communicate and debug with app on iOS Real Devices.

ios-deploy

Install and debug iOS apps from the command line. Designed to work on un-jailbroken devices. It can be installed from brew or npm and come up with following list of useful options,

Usage: ios-deploy [OPTION]...
-d, --debug launch the app in lldb after installation
-i, --id <device_id> the id of the device to connect to
-c, --detect only detect if the device is connected
-b, --bundle <bundle.app> the path to the app bundle to be installed
-a, --args <args> command line arguments to pass to the app when launching it
-s, --envs <envs> environment variables, space separated key-value pairs, to pass to the app when launching it
-t, --timeout <timeout> number of seconds to wait for a device to be connected
-u, --unbuffered don't buffer stdout
-n, --nostart do not start the app when debugging
-N, --nolldb start debugserver only. do not run lldb. Can not be used with args or envs options
-I, --noninteractive start in non interactive mode (quit when app crashes or exits)
-L, --justlaunch just launch the app and exit lldb
-v, --verbose enable verbose output
-m, --noinstall directly start debugging without app install (-d not required)
-A, --app_deltas incremental install. must specify a directory to store app deltas to determine what needs to be installed
-p, --port <number> port used for device, default: dynamic
-r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared) 
-9, --uninstall_only uninstall the app ONLY. Use only with -1 <bundle_id> 
-1, --bundle_id <bundle id> specify bundle id for list and upload
-l, --list[=<dir>] list all app files or the specified directory
-o, --upload <file> upload file
-w, --download[=<path>] download app tree or the specified file/directory
-2, --to <target pathname> use together with up/download file/tree. specify target
-D, --mkdir <dir> make directory on device
-R, --rm <path> remove file or directory on device (directories must be empty)
-X, --rmtree <path> remove directory and all contained files recursively on device
-V, --version print the executable version 
-e, --exists check if the app with given bundle_id is installed or not 
-B, --list_bundle_id list bundle_id 
-W, --no-wifi ignore wifi devices
-C, --get_battery_level get battery current capacity 
-O, --output <file> write stdout to this file
-E, --error_output <file> write stderr to this file
--detect_deadlocks <sec> start printing backtraces for all threads periodically after specific amount of seconds
-f, --file_system specify file system for mkdir / list / upload / download / rm
-k, --key keys for the properties of the bundle. Joined by ',' and used only with -B <list_bundle_id> and -j <json>
-F, --non-recursively specify non-recursively walk directory
-j, --json format output as JSON

Repo link – https://github.com/ios-control/ios-deploy

libimobiledevice

A cross-platform protocol library to access iOS devices, it is one the oldest best available tool which comes up with a bunch of libraries and command-line utilities to control iOS devices.

Some popular libraries are,

idevicerestore Restore/upgrade firmware of iOS devices

ideviceinstaller Manage apps of iOS devices

libideviceactivation A library to handle the activation process of iOS devices

libusbmuxd A client library to multiplex connections from and to iOS devices

Repo link – https://github.com/libimobiledevice

idb – iOS Development Bridge

The “iOS Development Bridge” or idb, is a command line interface for automating iOS Simulators and Devices by Facebook.

idb is made up of 2 major components, each of which needs to be installed separately.

idb companion

Each target (simulator/device) will have a companion process attached allowing idb to communicate remotely.

The idb companion can be installed via brew or built from source

brew tap facebook/fb

brew install idb-companion

Note: Instructions on how to install brew can be found here

idb client

A cli tool and python client is provided to interact with idb.

It can be installed via pip:

pip3.6 install fb-idb

Repo Link – https://github.com/facebook/idb

Verification Vs Validation

Verification
Verification does not involve code execution, it includes checking of documents, design, code and program.

While testing does involve checking whether the system meets specified requirements,

Checks if the software has been built according to the requirements or not. Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.

Validation
Validation involves code execution. It includes testing and validation of the actual product. if the software has been built according to the requirements or not.

Checking whether the system will meet user and other stakeholder needs in its operational environment(s).

Confirmation by examination and through provision of objective evidence that the requirements for a specific intended use or application have been fulfilled.

Simulating dragAndDrop event

On Protractor/WebdriverJs we can simulate dragAndDrop in following ways,

this.swapStages = function(){
   var vStage1 = element(by.xpath(“(//div[@class = ‘stage’])[1]”));
   var vStage2 = element(by.xpath(“(//div[@class = ‘stage’])[2]”));
   vProt.actions().dragAndDrop(vStage1, vStage2).perform();
 };

this.swapStages = function(){
   var vStage1 = element(by.xpath(“(//div[@class = ‘stage’])[1]”));
   var vStage2 = element(by.xpath(“(//div[@class = ‘stage’])[2]”));
    vProt.actions().mouseMove(vStage1).
                mouseDown(vStage1).
                mouseMove(vStage2).
                mouseUp(vStage2).
                perform();
    vProt.sleep(5000);
 };

this.swapStages = function(){ var vElement = element(by.xpath(“(//div[@class = ‘stage’])[1]”));
 vProt.actions().dragAndDrop(vElement.find(),{x:40,y:40}).perform();
};

Please note that HTML5 drag events (dragstart, dragend, dragover, dragenter, dragleave, and drop) are not working – https://code.google.com/p/selenium/issues/detail?id=3604

Setting up Protractor on mobile devices

To run protractor on mobile devices Appium is used as server,

Pre-Requs:
Appium server should be up and running 
Protractor server should be running
Device(Android/iOS) should be connected to PC and accessible through adb

Its above all is Ok, only few changes in conf.js of protractor are required to point its requests appium,

  seleniumAddress: ‘http://localhost:4723/wd/hub’,
    capabilities: {
    platformName: ‘android’,
    deviceName: ‘galaxy s4’,
    browserName: ‘chrome’,
    newCommandTimeout: 60
      },
    baseUrl: ‘http://10.0.2.2:’ + (process.env.HTTP_PORT || ‘8000’),

Some points to understand, 
1. Selenium use port 4444 but to use Appium it should be port 4723 instead of 4444
2. platformName: should be name of env where script will execute, like Andorid/iOS
3. deviceName: should be name of device like s4/iphone 5
4. browserName: should be chrome/safari
5. baseUrl is 10.0.2.2 instead of localhost because it is used to access the localhost of the host machine in the android emulator/device

Sources:
https://github.com/angular/protractor/issues/361
https://github.com/angular/protractor/issues/697
https://github.com/angular/protractor/blob/master/docs/browser-setup.md

node global and local installations

 
Type of node installation
In npm 1.0, there are two ways to install things:

    1.    globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in{prefix}/share/man, if they’re supplied.

npm install packagename -g

   2.    locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in./node_modules/.bin/, and man pages aren’t installed at all.

npm install packagename

WHICH TO CHOOSE
Whether to install a package globally or locally depends on the global config, which is aliased to the -g command line switch.
Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.

In general, the rule of thumb is:
    1.    If you’re installing something that you want to use in your program, using require(‘whatever’), then install it locally, at the root of your project.
    2.    If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

Source: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation

Using Jasmin Reports with Protractor

Protractor supports integration with Jasmine reporters. Jasmine reporters have a collection of JavaScript Jasmine reporter classes. We’ll use JUnitXMLReporter which provideds the test execution results in XML format.

Install Jasmine reporter
npm install -g jasmine-reporters

Configurations
After successful installation configure report in conf.js, “resutls/” is directory where report will be saved,

onPrepare: function() {

file.require(‘jasmine-reporters’);
jasmine.getEnv().addReporter(
                     new jasmine.JUnitXmlReporter(‘results/‘, true, true)
);

Protractor

Introduction

Protractor is a Node.js framework that sits on top of the Selenium / WebDriver APIs. It acts as an abstraction layer to make it easier to write and run end to end tests against AngularJS web applications.
It contains every feature that is available in the Selenium WebDriver. Additionally, Protractor provides some new locator strategies and functions which are very helpful to automate the AngularJS application. Examples include things like: waitForAngular, By.binding, By.repeater, By.textarea, By.model, WebElement.all, WebElement.evaluate, etc.
It is perfectly possible, but painful, to write end to end tests for an AngularJS site using only Selenium tools. The challenge lies in determining when AngularJS is actually done with a given action, such as a change of view – this is somewhat more difficult than is the case for straightforward old-school AJAX operations. So Selenium test scripts for AngularJS tend to bloat with wait commands and checks.

Salient features of the Protractor Automation tool:

·      Allows running tests targeting remote addresses
·      Can take advantage of Selenium grid to run multiple browsers at once
·      Protractor works as a solution integrator – combining powerful tools and technologies such as NodeJS, Selenium, webDriver, Jasmine, Cucumber and Mocha.
·      Protractor also speeds up your testing as it avoids the need for a lot of “sleeps” and “waits” in your tests, as it optimizes sleep and wait times.
·      Protractor allows tests to be organized based on Jasmine, thus allowing you to write both unit and functional tests on Jasmine.
·      It runs on real browsers and headless browsers.

What is an End to End Test?

An end to end test runs against the front-end of a fully functional application. In the case of a web application, this implies driving a browser that loads pages, runs Javascript, interacts with the DOM, fills and submits forms, and so forth. The web application is served from a machine with a fully functional backend and suitably populated database. The setup is intended to mimic as closely as possible the live application, environment, and use cases.
You might compare this with unit testing, wherein a unit test runs against a small piece of functionality in isolation. Any data that might come from the rest of the application is mocked for the purposes of a unit test.

Installation

To install Protractor, node should be installed, if not please install from here. 
npm install -g protractor
To verify your installation, please type in the command,
Protractor –version
If Protractor is installed successfully then the system will display the installed version. Otherwise you will have to recheck the installation

Configurations

Next step is to create a configuration file (conf.js) with some parameters which will be passed to Protractor to execute our spec files.
Following are contents,
SeleniumAddress:  This allows you provide a URL to the Selenium Server that Protractor will use to execute tests. In this case Selenium Server must be previously started to be able to run tests on Protractor.
SeleniumServerJar: This allows you provide the file path of the SeleniumServer.jarfile. This parameter will be used by Protractor to control the Selenium life cycle. That way it is not necessary to start and stop the Selenium Server to run Protractor.
Specs: An array of test files can be sent through the specs parameter for Protractor to execute. The path of the test files must be relative to the config file.
seleniumArgs: This allows you to pass a parameter to Selenium if  SeleniumServerJar is being used.
capabilities: Parameters also can be passed to the WebDriver using the capabilities parameter. It should contain the browser against which Protractor should run the tests.
baseURL: A default URL may be passed to Protractor through the baseURL parameter. That way all calls by Protractor to the browser will use that URL.
framework: This can be used to set the test framework and assertions that should be used by Protractor. There are 3 options currently for this parameter: Jasmine, Cucumber and Mocha.
allScriptsTimeout: To set up a timeout for each test executed on Protractor use this parameter with a number value in milliseconds.
All of the parameters are encapsulated in a node object which should be named “config”. That way Protractor will identify those parameters inside that object.
Below is an example of a Protractor configuration file named config.js
exports.config = {
  // The address of a running selenium server.
seleniumAddress: ‘http://localhost:4444/wd/hub’,
specs: [‘homepage_test.js’, ‘project_test.js’],
  capabilities: {
    browserName: ‘chrome’,
    version: ”,
    platform: ‘ANY’
},
allScriptsTimeout: 22000,
 // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    isVerbose : true,
    includeStackTrace : true
  }
};

Execute Test case

Open the terminal and execute following command,
protractor /path/to/protractor.conf.js