Pinscher Testing

“How can I best get up the mountain?” – Just climb upwards, and don’t think about it! Friedrich Nietzsche

Testing with NightwatchJS and PhantomJS

Nightwatch.js, based on Node.js, is an End-to-End (E2E) testing solution for browser and web app. Use the power of API Selenium WebDriver to perform commands and assertions on the elements of the DOM.

nightwatchjs site
PhantomJS is a scriptable headless WebKit with API JavaScript. Fast, native to various Web standards: DOM handling, CSS selectors, JSON, Canvas, and SVG.

phantomjs site

nightwatchjs_project

 

 

 

 

An example of step_definition.js ->

module.exports = function() {

    this.Given(/^I open site_example's page$/, function() {
        this
        	.resizeWindow(1024, 768)
            .url("http://www.site-example.it")
            .waitForElementVisible("body", 1000);
    });

    this.When(/^I search for iPhone$/, function() {
        this
        	.useXpath()
        	.waitForElementVisible("//input[@id='short_gsa_search_box']", 1000)
        	.setValue("//input[@id='short_gsa_search_box']", "iphone")
        	.click("//*[@id='gsa_menu_box']/a");
    });

    this.Then(/^the page title is as expected$/, function() {
        this.assert.containsText("//*[@id='c118109']/div[2]/div/span[1]", "Hai cercato: iphone");
    });
    
};

 

nightwatch.conf.js ->

module.exports = {
    "src_folders" : [require('nightwatch-cucumber')()],
    "output_folder" : "reports",
    "custom_commands_path" : "",
    "custom_assertions_path" : "",
    "globals_path" : "",
    "live_output" : false,
    "parallel_process_delay" : 10,
    "disable_colors": false,
    "test_workers" : false,

    "selenium" : {
        "start_process" : false,
        "server_path" : "lib/selenium-server-standalone-2.52.0.jar",
        "log_path" : "logs",
        "host" : "10.60.236.49",
        "port" : 6666,
        "cli_args" : {
            "webdriver.chrome.driver" : "",
            "webdriver.firefox.profile" : ""
        }
    },

    "test_settings" : {
        "default" : {
            "launch_url" : "http://ip_nightwatch_pc",
            "selenium_host" : "ip_nightwatch_pc",
            "selenium_port" : 6666,
            "silent" : true,
            "disable_colors": true,
            "screenshots" : {
                "enabled" : false,
                "path" : ""
            },
			"desiredCapabilities" : {
				"browserName" : "phantomjs",
				"phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
  				"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
  				"phantomjs.binary.path" : "/Users/jenkins/Desktop/nightwatchjs_job_jenkins/phantomjs-2.1.1-macosx/bin/phantomjs",
  				"javascriptEnabled" : true,
  				"acceptSslCerts" : true
			}
    	}
 	}
}

 

package.json ->

{
  "name": "nightwatchjs",
  "version": "1.0.0",
  "description": "",
  "main": "nightwatch.conf.js",
  "dependencies": {
    "cucumber": "^0.9.5"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

 

feature_example.feature ->

Feature: Homepage Search

Scenario: Searching Homepage

    Given I open example_site's page
    When I search for iPhone
    Then the page title is as expected

 

Job Jenkins Nightwatch.js on Excute Command bash

  • export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  • cd /Users/jenkins/workspace/PhantomJS\ Cucumber-Nightwatchjs\ Tests
  • /Users/jenkins/workspace/PhantomJS\ Cucumber-Nightwatchjs\ Tests/node_modules/nightwatch/bin/nightwatch

 

Happy Testing with Ghosts! XD

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Run Selenium Grid on Safari browser

To run your tests on Safari browser need to download selenium-safari-driver-last_version.jar
safari-driver

Selenium Grid Node start with:

java -jar selenium-server-standalone-last_version.jar -role node -nodeConfig nodeconfig.json -Dwebdriver.safari.driver=selenium-safari-driver-last_version.jar

Set nodeconfig.json:

{
    "capabilities":
    [
        {
            "seleniumProtocol":"WebDriver",
            "browserName":"safari",
            "maxIstances":1
        }
    ],
    "configuration":
    {
        "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "maxSession": 5,
        "port": 4448,
        "register": true,
        "registerCycle": 5000,
        "hubPort": 4444
        "hubHost": "ip_hub"
    }
}

 

How to add the WebDriver extension to Safari (Safari extz)

You have to unpack the selenium-safari-driver.jar in selenium folder, copy the files SafariDriver.safariextz downloaded selenium-safari-extension and double click on it.
At this point you will open the extensions preferences safari and you will see the active and installed WebDriver.

Happy testing on Safari!;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Lint your Swift with Tailor

Tailor is a static analysis and lint tool for source code written in Apple’s Swift programming language. It analyzes your code to ensure consistent styling and help avoid bugs.

Tailor supports Swift 2 out of the box and helps enforce style guidelines outlined in the The Swift Programming Language, GitHub, Ray Wenderlich, and Coursera style guides.

tailor-site
tailor-wiki

I have integrated Tailor with Jenkins in a job “iOS Tailor Testing – App Example”
tailor –format=json . | tailorf >> tailor_report.html

tailorf is a python formatter created to convert json tailor output in html report.

Structure Project tailorf
tailorf-project

 

 

 

 

 

Source code of tailorf:

tailor.html ->

<!DOCTYPE html>
<html>
<head>
    <title>Tailor Report</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>

<div class="container">

<h2>TAILOR REPORT</h2>


<h3>

Summary
</h3>


<table class="table table-condensed">

<td>
            {% for key, value in data.summary.iteritems() %}

<tr>{{ key }}: {{ value }}</tr>

            
            {% endfor %}
        </td>

    </table>





    {% for file in data.files %}

<h4>

{{ basename_function(file.path, prefix) }}
</h4>


<table class="table table-condensed table-bordered">

<tr>

<td><strong>Severity</strong></td>


<td><strong>Rule</strong></td>


<td><strong>Location - line/column</strong></td>


<td><strong>Error message</strong></td>

        </tr>

        {% for error in file.violations %}

<tr>

<td>
                <mark>{{ error.severity }}</mark>
            </td>


<td>{{ error.rule }}</td>


<td>{{ error.location.line }}/{{ error.location.column }}</td>


<td><em>{{ error.message }}</em></td>

        </tr>

        {% endfor %}
    </table>





    {% endfor %}
</div>

</body>
</html>

 

__init__.py ->

import json
import os
import sys

from jinja2 import Environment, PackageLoader


def __basename_function(path, prefix):
    return os.path.relpath(path, prefix)


def format(file=sys.stdin):
    env = Environment(loader=PackageLoader('tailorf', 'templates'))
    env.globals['basename_function'] = __basename_function
    data = json.load(file)
    paths = [file["path"] for file in data["files"]]
    prefix = os.path.commonprefix(paths)
    template = env.get_template('tailor.html')
    print template.render(data=data, prefix=prefix)

 

requirements.txt ->
jinja2
setuptools

 

setup.cfg ->
[metadata]
description-file = README.md

 

README.md ->
tailorf
================

 

setup.py ->

from setuptools import setup

setup(
    name='tailorf',
    packages=['tailorf'],
    version='0.1.1',
    description='Format tailor json output to HTML',
    author='Giuseppe Cilia',
    author_email='pinschertesting@gmail.com',
    url='https://gitlab_url/tailor-formatter',
    download_url='https://gitlab_url/tailor-formatter/repository/archive.targ.gz?ref=0.1.1',
    keywords=['formatter', 'tailor', 'html'],
    classifiers=[],
    install_requires=['jinja2'],
    package_data={'tailorf': ['templates/*.html']},
    entry_points={
        'console_scripts': [
            'tailorf = tailorf:format',
        ]
    }
)

 

How to install tailorf?
sudo pip install tailorf

tailorf-report

 

 

 

 

 

 

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

SonarQube and Jenkins for Windows Phone App

We have talked many time in many posts of SonarQube but, how to integrate a project for Windows Phone APP and Jenkins for continuous automatic static testing?
Easy!:)

Download MSBuild.SonarQube.Runner-2.0.zip
msbuild-sonarqube-runner-download

in SonarQube.Analysis.xml insert the ip of server, user and password:
sonar.host.url: http://sonar_server_ip:9000
sonar.login: admin
sonar.password: admin

1. Open a Developer Command Prompt for VS2015 from the Start menu.
2. Navigate to the folder containing the project that you want to analyze.
3. Run the following commands:
path=%path%;C:\Sq\MSBuild.SonarQube.Runner-1.0.1 (env variable added)
MSBuild.SonarQube.Runner begin /n:AppExample /v:1.0 /k:blm
Msbuild
MSBuild.SonarQube.Runner end

AppExample is the name of project visualized in Sonar Server Dashboard.

To integrate SonarQube and Jenkins need write the follow code in an Execute Windows batch command:
C:\Sq\MSBuild.SonarQube.Runner-2.0\MSBuild.SonarQube.Runner.exe begin /n:AppWallet /v:1.0 /k:blm
nuget restore WalletApp.sln
MSBuild /t:Clean,Build /p:Configuration=Release
C:\Sq\MSBuild.SonarQube.Runner-2.0\MSBuild.SonarQube.Runner.exe end

Happy Testing;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Run Selenium Grid on Microsoft Edge browser

To run your tests on Microsoft Edge browser need to download IEDriverServer.exe and MicrosoftWebDriver.exe

Microsoft WebDriver download

IEDriverServer.exe 64 bit Windows IE

IEDriverServer.exe 32 bit Windows IE

 

Selenium Grid Node start with:

java -jar selenium-server-standalone-last_version.jar -role node -nodeConfig nodeconfig.json -Dwebdriver.edge.driver=”C:\Program Files (x86)\Microsoft Web Driver\MicrosoftWebDriver.exe”

Set nodeconfig.json:


{
  "capabilities":
  [
    {
      "seleniumProtocol":"WebDriver",
      "browserName":"MicrosoftEdge",
      "maxIstances":1
    }
  ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 4447,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444
    "hubHost": "ip_hub"
  }
}

 

Happy testing on Microsoft Edge!;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

SonarQube and Jenkins

SonarQube is an open platform to manage code quality. As such, it covers the 7 axes of code quality:

  1. Architecture and Design
  2. Duplications
  3. Unit Tests
  4. Complexity
  5. Potential bugs
  6. Coding rules
  7. Comments

SonarQube has got a very efficient way of navigating, a balance between high-level view, dashboard, TimeMachine and defect hunting tools. This enables to quickly uncover projects and/or components that are in Technical Debt to establish action plans.

More than 20 programming languages are covered through plugins.

Get Started in Two Minutes.

  • After download of SonarQube server, sonarqube-downloads
  • #On Windows, execute – C:\sonarqube\bin\windows-x86-xx\StartSonar.bat
    #On other operating system, execute – /etc/sonarqube/bin/[OS]/sonar.sh console
    SonarQube host url = http://localhost:9000
  • Install a Database (we choose MySql on Mac OS)
    brew install mysql
    mysql.server restart (or from System Preference -> MySQL -> Start MySQL Server)
    create user ‘sonarqube’@’localhost’ identified by ‘sonarqube’;
    create database sonarqube;
    grant all privileges on sonarqube.* to ‘sonarqube’@’localhost’; (assign to user create the DB)
    use sonarqube; (check)
    show tables; (check)
  • Install SonarQube Plugin (* purchase plugins)
    Sonar-Installing-Plugin
  • On Jenkins install the plugin for SonarQube
    sonarqube-jenkins-plugin so to set SonarQube Runner and SonarQube on Jenkins Configuration
  • In sonar-scanner.properties let’s set the values for the DB created to SonarQube
  • Continue in SonarQube and Gradle for Android (an example)

sonaqube-jenkins1

 

 

 

 

sonarqube-jenkins2

 

 

 

Happy Automatic Static Testing with SonarQube;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

SonarQube and Gradle for Android

SonarQube is an open platform to manage code quality. As such, it covers the 7 axes of code quality:
1. Architecture and Design
2. Duplications
3. Unit Tests
4. Complexity
5. Potential bugs
6. Coding rules
7. Comments

Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven of declaring the project configuration. Gradle uses a directed acyclic graph (“DAG”) to determine the order in which tasks can be run.
Gradle was designed for multi-project builds which can grow to be quite large, and supports incremental builds by intelligently determining which parts of the build tree are up-to-date, so that any task dependent upon those parts will not need to be re-executed.

To integrate SonarQube and Gradle in an Android project you need set the build.grade file of the feature in this way:

buildscript {
    repositories {
        ....
    }
    dependencies {
        ....
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
    }
}
subprojects {
    ....
    apply plugin: "sonar-runner"
    sonarRunner {
        sonarProperties {
            properties["sonar.sources"] += "src/main/java"
        }
    }
}

task clean(type: Delete) {
    ....
}

allprojects {
    repositories {
        ....
    }
}

and build.gradle file of the app in this way:

apply plugin: "sonar-runner"
....

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
dataBinding {
        	enabled = true
    	    }
sonarRunner {
        sonarProperties {
            property "sonar.host.url", "http://localhost:9000"
            property "sonar.projectKey", "org.sonarqube:java-gradle-simple"
            property "sonar.projectName", "App Demo SonarQube"
            property "sonar.projectDescription", "App Demo SonarQube Description"
            property "sonar.projectVersion", "1.0"
            property "sonar.projectBaseDir", "app/src/main/java"
            property "sonar.working.directory", "build/sonar"
            property "sonar.scm.provider", "git"
        }
    }
....

Happy Static Testing with SonarQube!;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Smartphone Test Farm for iOS

Apple with Xcode 7 introduces UI Testing as new features of the existing XCTest framework.

The UI Testing advantages are:
– Easy UI recording
– Performance Test
– Code Coverage

ui-testing-videos-wwdc2015

With UI Testing it is possible to run tests on physical devices and simulators.
Instead of running the tests in series to n devices connected to the MAC through this script you will be able to run the tests in parallel on n device attached (in the example we perform the tests in parallel on four devices at a time).
We must create in this specific case four job for the execution of tests on the devices.

Jenkins job “Smartphone Test Farm iOS”


#!/bin/bash

set -e

job_name="iOS UI Testing Tests - App Example"
num_jobs=4

function log {
echo "[$(date)] $1"
}

#Read attached devices
devices=$(instruments -s devices | grep -v Simulator | cut -f2 -d\[ | cut -f1 -d\] | grep -v - | tail -n +2)

if test -z "$devices"; then
log "Warning! no devices found"
exit 1
fi
j=0
for i in $devices; do

job_id=$(( $j % ${num_jobs} ))

log "Doing device id: $i"
curl -X POST "https://jenkins_url/job/${job_name}_${job_id}/build" --data-urlencode json="{\"parameter\": {\"name\":\"devices\",\"value\":\"${i}\"}}"
j=$(($j + 1));
done

log "Invocked jenkins without errors"

 

#N Jenkins job to execution of tests “iOS UI Testing Tests – App Example”

scan –scheme “example_scheme” –destination ‘id=’${devices}

scan is part of fastlane: connect all deployment tools into one streamlined workflow.
scan uses the latest APIs and tools to make running tests plain simple and offer a great integration into your existing workflow, like fastlane or Jenkins.
scan-fastlane

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

STF – Smartphone Test Farm for Android

STF (or Smartphone Test Farm) is a web application for debugging smartphones, smartwatches and other gadgets remotely, from the comfort of your browser.

Installation:
1. git clone https://github.com/openstf/stf.git
2. brew install rethinkdb graphicsmagick zeromq protobuf yasm pkg-config
3. npm install -g stf
4. git config –global url.https://github.com/.insteadOf git://github.com/
5. npm install
6. npm link
7. rethinkdb
8. stf local –public-ip http://IP_address
9. http://IP_address:7100/#!/devices

Happy Testing with STF!;)

STF

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Winium – Windows Phone Testing

Winium, as Appium, is an open source test automation tool, Selenium-based tool, for testing Windows Phone Apps on Emulators.
Winium is an alternative to Coded UI, test automation tool of Visual Studio Enterprise.

In the project that you want to test you just need to add the reference to Winium.StoreApps.InnerServer, run the following command in the Package Manager Console of Visual Studio:
Install-Package Winium.StoreApps.InnerServer

At the source code following add lines to be called on the UI thread after visual root is initialized:
AutomationServer.Instance.InitializeAndStart();

For each element that you want test need to add this instruction:
AutomationProperties.AutomationId = “loginpage” AutomationProperties.Name = “loginpage” (for example you want to scroll login page).

If you want to write tests in Python you need to install Python and Selenium Package:
pip install selenium (selenium-python-installation)

Download and Start Winium Server (Winium.StoreApps.Driver.exe):
Winium.StoreApps.Driver.zip

and run tests. (python test_register_form.py).

Test Register Form with Winium, example:


# coding: utf-8
import unittest
import os

from selenium.webdriver import Remote
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

class TestMainPage(unittest.TestCase):
desired_capabilities = {
"app": os.getenv('APPX', '') #we take appx from env and from a job on jenkins (see under test)
}

def setUp(self):
self.driver = Remote(command_executor="http://localhost:9999",
desired_capabilities=self.desired_capabilities)

def test_content(self):
driver = self.driver

#close keyboard
#name_login.send_keys(Keys.RETURN)
login_page = driver.find_element_by_id('loginPage')
login_page.click()

button_register = driver.find_element_by_id('RegisterBtn')
button_register.click()

#step 1
name = driver.find_element_by_id('name')
name.send_keys("nametest")
name = driver.find_element_by_id('surname')
name.send_keys("surnametest")
credential_page = driver.find_element_by_id('credentialPage')
credential_page.click()
button_next = driver.find_element_by_id('nextbutton')
button_next.click()

#step 2
phone = driver.find_element_by_id('phone')
phone.send_keys("0123456789")
email = driver.find_element_by_id('email')
email.send_keys("testemail@wind.it")
contact_page = driver.find_element_by_id('contactPage')
contact_page.click()
button_next = driver.find_element_by_id('nextbutton')
button_next.click()

#step 3
otp = driver.find_element_by_id('otp')
otp.send_keys("4444")
otp_page = driver.find_element_by_id('otpPage')
otp_page.click()
button_next = driver.find_element_by_id('nextbutton')
button_next.click()

#step 4
#switch on/off
privacy = driver.find_element_by_id('privacy')
privacy.click()
button_next = driver.find_element_by_id('nextbutton')
button_next.click()

#step 5
password = driver.find_element_by_id('password')
password.send_keys("passwordtest")
conferma_password = driver.find_element_by_id('confermapassword')
conferma_password.send_keys("passwordtest")
password_page = driver.find_element_by_id('passwordPage')
password_page.click()
button_next = driver.find_element_by_id('nextbutton')
button_next.click()

def tearDown(self):
self.driver.quit()

if __name__ == '__main__':
unittest.main()

 

Jenkins job to creation APPX (execute windows batch command):
nuget restore ExampleApp.sln
MSBuild /t:Clean,Build /p:Configuration=Release

Winium.StoreApps

Happy testing on Windows Phone Apps!;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page

Page 1 of 7

Powered by WordPress & Theme by Anders Norén