Tuesday, January 26, 2016

Interacitve shell for php-webdriver to debug selenium

I do most of my selenium (actually locator’s) debugging in chrome console, $() for css selectors and and $x() for xpath selectors but when it actually comes to debugging selenium/webdriver api calls I prefer interactive shell of programming language (python, ruby and php and pretty decent built in shells)
Bellow is how you can configure php shell to play around with selenium

Installation

  • get composer Composer (If you don’t already use Composer)
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
  • get psysh A runtime developer console, interactive debugger and REPL for PHP
wget psysh.org/psysh
chmod +x psysh
./psysh
Then install the library:
php composer.phar require facebook/webdriver
All you need as the server for this client is the selenium-server-standalone-#.jar file provided here: http://selenium-release.storage.googleapis.com/index.html
Download and run that file, replacing # with the current server version.
java -jar selenium-server-standalone-#.jar

// author : Ahmed Mubbashir Khan
require_once 'vendor/autoload.php'; //composer generated autoload file
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;

$host = 'http://192.168.99.100:4444/wd/hub';
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
/* 
Or  if you wan't to modify $capabilities
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
$capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox');
$driver = RemoteWebDriver::create($host, $capabilities);
*/
//e.g. Mouse over on an element
$element = $driver->findElement(WebDriverBy::id('some_id'));
$driver->getMouse()->mouseMove( $element->getCoordinates() );
Reference:
 - [1]: http://selenium-release.storage.googleapis.com/index.html
 - [2]: https://github.com/facebook/php-webdriver
 - [3]: https://getcomposer.org/
-  [4]: http://psysh.org/

Monday, January 4, 2016

Jenkins: List all the jobs for which SCM is not currently configured

Put the following in  Jenkins Script Console  to  list all the jobs for which SCM is not currently configured:


// Licensed under MIT
// author : Ahmed Mubbashir Khan
// ---------------------------------------------------------
// This script goes through all the jobs and checks if they configured SCM is hudson.scm.NullSCM
// if they are, then prints it's info
// ---------------------------------------------------------
 

counter = 0
jobs = Jenkins.instance.getAllItems()
for (job in jobs) {
  if (job.scm instanceof hudson.scm.NullSCM){
    println "Job= '${counter++}' '${job.name}' scm '${job.scm}'"
  }
}

Sunday, October 25, 2015

Selenium, Jbehave , gradle and Serenity - Perfect combination for automating BDD styled checks in Java

I have just created this demo project using Selenium, gradle, Jbehave and Serenity

https://github.com/mubbashir/jbehave-selenium-bdd

Why add Serenity?

Serenity adds plugins to Jbehave and makes it a lot easier to write acceptance tests as mentioned on it site Serenity BDD helps you write cleaner and more maintainable automated acceptance and regression tests faster.
The other things I loved about Serenity is the it has wonderful reports  for BDD "Serenity also uses the test results to produce illustrated, narrative reports that document and describe what your application does and how it works."
See:


Structure

├── ReadMe.md  ## ReadME file of cource ;)
├── build.gradle ## gradle build file 
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew ## grdadle warapper
├── src
│   └── test
│       ├── java
│       │   └── test
│       │       ├── WebTest.java ## This is where the tests resides which add all the steps using net.serenitybdd.jbehave.SerenityStepFactory
│       │       └── selenium
│       │           ├── page ## This where all the pages extending net.serenitybdd.core.pages.PageObject
│       │           │   ├── google
│       │           │   │   └── GoogleLanding.java
│       │           │   └── interfaces
│       │           │       └── Landing.java
│       │           └── steps ## Pages are used in steps 
│       │               └── GoogleSteps.java
│       └── resources
│           └── stories
│               └── google
│                   ├── Search2.story
│                   └── search.story

Refrences

Tuesday, October 20, 2015

Adding pre-commit (package) to git repo of your python projects

Git pre commits  are quite useful to analyze  the code before you make a commit and pre-commit makes it quite easy to mange these hooks and rules to run via these hooks.
  • Install pre-commit, pip install pre-commit ## detailed instruction  on it's website pre-commit
  • Run pre-commit install ## Usage instruction  on it's website pre-commit
  • Create .pre-commit-config.yaml file in your project root
pre-commit install will install pre-commit into your git hooks, now on words it will be run on every commit. 
Every time you clone a  project running pre-commit install should always be the first thing you do.
The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow. 
  • To Run all pre-commit manually on all file type pre-commit run --all-files
  • To run specific hook (via the id in .pre-commit-config.yaml) on specific file(s) pre-commit run autopep8-wrapper --files features/steps/google_steps.py

We can also run all the pre commit hook as a CI step e.g. pre-commit run --all-files 

Individual tools can configure in accordance to according to there configuration. For example flake8 can be configured by adding a setup.cfg file 

Tuesday, October 6, 2015

Parallel execution of automated check via selenium, behave and docker


We were looking for a solution for executing selenium bases scenarios written in behave in parallel to speed up the execution time. Unluckily behave doesn't have this in build like cucumber  fortunately we came across https://github.com/hugeinc/behave-parallel  in which  upstemsync was just couple of weeks old :)

I already had a picture in mind how would the entire step would work so creating  a demo project wasn't too difficult.

Check out https://github.com/mubbashir/behave-selenium 
Following is screen recoding where I had connected to both nodes via VNC and checks were executed in Parallel  on features level


Links:
https://github.com/hugeinc/behave-parallel
https://github.com/behave/behave/
https://github.com/SeleniumHQ/docker-selenium


Wednesday, September 30, 2015

Flashback: Intro to Selenium and Automation- Slide deck

Flashback -  Today while going through some documents on my google drive I came across this presentation which I have used in the past back to give very basic introduction to selenium and automation.