Saturday, January 27, 2018

Selenium + Cucumber Integration


Cucumber is nice way of achieving automation. Below is a sample automation steps on logging into Facebook app & logging out of the application itself.

Note: Below sample includes :
            Selenium and Cucumber integration with passing parameters
            Data driven testing sample
            All reports generation for Cucumber
       

You have to have following Jar list :

cucumber-reporting-0.1.14-sources.jar
junit-4.12-sources.jar
cobertura-2.1.1.jar
cucumber-jvm-deps-1.0.3.jar
cucumber-core-1.2.2.jar
cucumber-junit-1.2.2.jar
cucumber-java-1.2.2.jar
cucumber-html-0.2.2-sources.jar

Data driven testing sample
===================

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
// glue - here you give the full qualified package name
@CucumberOptions(features="features",
glue="feature.description",
plugin={"html:target/cucumber-html-report",
"json:target/cucumber.json",
"pretty:target/cucumber-pretty.txt",
"usage:target/cucumber-usage.json",
"junit:target/cucumber-results.xml"})
public class TestRunner {

}


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class SampleTest {

    private WebDriver driver;

@Given("^Open \"([^\"]*)\" and the \"([^\"]*)\" start \"([^\"]*)\" application$")
public void Open_chrome_and_start_application(String driverName ,String driverLocation, String applicationName) throws Throwable {

    System.setProperty(driverName, driverLocation);

            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--disable-notifications");

    driver = new ChromeDriver(chromeOptions);

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
         
    driver.manage().window().maximize();
            driver.get(applicationName);
}

@When("^Enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
public void Enter_valid_username_and_valid_password(String userName, String password) throws Throwable {
    driver.findElement(By.id("email")).sendKeys(userName);
    driver.findElement(By.id("pass")).sendKeys(password);     
}

@Then("user should be able to login successfully")
public void user_should_be_able_to_login_successfully() throws Throwable {
    driver.findElement(By.id("loginbutton")).click();
}

@Then("user should be able to logout successfully")
public void user_should_be_able_to_logout_successfully() throws Throwable {
             driver.findElement(By.id("userNavigationLabel")).click();
     driver.findElement(By.linkText("Log Out")).click();
}
}

Feature: Test Facebook smoke scenario

    Scenario Outline: Test login with valid credentials
    Given Open "webdriver.chrome.driver" and the "C:\\xyz\\chromedriver.exe" start "http://www.facebook.com" application
    When Enter valid "<userName>" and valid "<password>"
    Then user should be able to login successfully
    And user should be able to logout successfully

    Examples: 
      | userName                 | password  |
      | abc_efgh@yahoo.com | xxxx |
      |xyz@yahoo.com | yyyy



Sunday, January 21, 2018

Selenium ...

Selenium Grid

* You can automate upto 5 browsers.
* You can run both Web Driver & RC.
* Only one Hub for a grid.
* Before creating the grid make sure firewall settings are correctly configured.

Setting up the Hub

G:\TestAutomation\Selenium>java -jar selenium-server-standalone-2.48.2.jar -role hub
13:51:50.635 INFO - Launching Selenium Grid hub
2018-01-22 13:51:51.626:INFO::main: Logging initialized @1291ms
13:51:51.637 INFO - Will listen on 4444
13:51:51.672 INFO - Will listen on 4444
2018-01-22 13:51:51.675:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT
2018-01-22 13:51:51.722:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@2ddc9a9f{/,null,AVAILABLE}
2018-01-22 13:51:52.619:INFO:osjs.ServerConnector:main: Started ServerConnector@1a75e76a{HTTP/1.1}{0.0.0.0:4444}
2018-01-22 13:51:52.622:INFO:osjs.Server:main: Started @2287ms
13:51:52.624 INFO - Nodes should register to http://172.18.175.50:4444/grid/register/
13:51:52.625 INFO - Selenium Grid hub is up and running
14:00:46.294 INFO - Registered a node http://172.18.175.50:5555

Setting up/ Registering Node1

G:\TestAutomation\Selenium>java -Dwebdriver.chrome.driver=E:\Software\chromedriver.exe -jar selenium-server-standalone-2.48.2.jar -role node -hub  http://172.18.175.50:4444/grid/register/
14:00:45.605 INFO - Launching a Selenium Grid node
14:00:46.113 INFO - Java: Oracle Corporation 9.0.1+11
14:00:46.113 INFO - OS: Windows 10 10.0 amd64
14:00:46.119 INFO - v2.48.0, with Core v2.48.0. Built from revision 41bccdd
14:00:46.167 INFO - Driver class not found: com.opera.core.systems.OperaDriver
14:00:46.168 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
14:00:46.198 INFO - Version Jetty/5.1.x
14:00:46.200 INFO - Started HttpContext[/selenium-server,/selenium-server]
14:00:46.256 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@45385f75
14:00:46.256 INFO - Started HttpContext[/wd,/wd]
14:00:46.257 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
14:00:46.258 INFO - Started HttpContext[/,/]
14:00:46.263 INFO - Started SocketListener on 0.0.0.0:5555
14:00:46.263 INFO - Started org.openqa.jetty.jetty.Server@2c1b194a
14:00:46.264 INFO - Selenium Grid node is up and ready to register to the hub
14:00:46.285 INFO - Starting auto registration thread. Will try to register every 5000 ms.
14:00:46.285 INFO - Registering the node to the hub: http://172.18.175.50:4444/grid/register
14:00:46.294 INFO - The node is registered to the hub and ready to use 

Accessing grid hub from URL :

http://172.18.175.50:4444/grid/console


import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class SeleniumGrid {

    WebDriver driver;   // WD   
    String nodeUrl;  // node1
   
/**     
 * WD & node01 runs in two different machines      
 */    
private void invokeRemoteBrowser() {
        try {

            nodeUrl = "http://172.18.175.50:5555/wd/hub";

            DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
            desiredCapabilities.setBrowserName("chrome");
            desiredCapabilities.setPlatform(Platform.WINDOWS);

            driver = new RemoteWebDriver(new URL(nodeUrl), desiredCapabilities);

            driver.manage().deleteAllCookies();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

            driver.get("https://www.yahoo.com");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


Monday, July 10, 2017

Identity Claim Management : 

This is a screen cast video done by me on claim management :



Web Link :
https://www.youtube.com/watch?v=lIcDvJzhvIE

Thursday, December 1, 2016


XACML Architecture


1. Its an access control policy language.
2. The Identity Server supports XACML 3.0, which is based on Balana XACML implementation.
3. The XACML engine of the WSO2 Identity Server has two major components, i.e., PAP and PDP. 


Eg: 

MyPolicy.xml
==========

<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="MyPolicy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
     <Target>
   <AnyOf>
            <AllOf>
  <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
         <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
         <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" 
                                            DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
  </Match>
     </AllOf>
  </AnyOf>
      </Target>
          <Rule Effect="Permit" RuleId="permit"/>
</Policy>


Request 
=======

https://localhost:9443/entitlement/Decision/pdp

Authorization         Basic YWRtaW46YWRtaW4=
Accept                   application/xml
Content-Type        application/xml


<Request CombinedDecision="false" ReturnPolicyIdList="false" xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
    <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action">
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
        </Attribute>
    </Attributes>
    <Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="false">
            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">http://127.0.0.1/service/very_secure/</AttributeValue>
        </Attribute>
    </Attributes>
</Request>


Response
========

<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
    <Result>
        <Decision>Permit</Decision>
        <Status>
            <StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
        </Status>
    </Result>
</Response>

Thursday, October 27, 2016

Java Script Basics 


[1] Calling a function of another file from your javascript file

file 01:  graphinventor.js
=================

 console.log("-----------------------------------------Time Unit ");
 console.log("Previous Time Stamp ");


var test123 = function (data){
console.log("-----------------------------------------inside test123 ");
console.log(data)
alert("This is an alert" +data);

}

[3] https://datatables.net/manual/ajax

file 02: gadgetconf.js
===============

processData: function(data) {

console.log('data '+JSON.stringify(data));
 // in console of the browser (Ctrl+c) you see the content now as json data

console.log("------------------------");
test123(data);
console.log("------------------------");

}

main.js file (Loading graphinventor.js file first)
==========

       <!-- Custom -->
          <script src="js/graphinventor.js"></script>
          <script src="js/gadgetconf.js"></script>
          <script src="js/main.js"></script>

[2] Callback function is a function passed into another function.



Java Script Basics 


[1] Calling a function of another file from your javascript file

file 01:  graphinventor.js
=================

 console.log("-----------------------------------------Time Unit ");
 console.log("Previous Time Stamp ");


var test123 = function (data){
console.log("-----------------------------------------inside test123 ");
console.log(data)
alert("This is an alert" +data);

}

file 02: gadgetconf.js
===============

processData: function(data) {

console.log('data '+JSON.stringify(data));
 // in console of the browser (Ctrl+c) you see the content now as json data

console.log("------------------------");
test123(data);
console.log("------------------------");

}

main.js file (Loading graphinventor.js file first)
==========

       <!-- Custom -->
          <script src="js/graphinventor.js"></script>
          <script src="js/gadgetconf.js"></script>
          <script src="js/main.js"></script>

[2] Callback function is a function passed into another function.


Sunday, October 23, 2016

Json  Notes:  


Json Objects:


var me = {
"age" : "25",
"address" : "Kottawa",
"gender" : "male"
};


Json Arrays:


var family = [{
   "name" : "Dimuthu",
   "age" : "25",
   "gender" : "male"
},
{
   "name" : "Nadeesha",
   "age" : "25",
   "gender" : "male"
}];


JsonNeted Objects:


var family = {
   "Dimuthu" : {
       "sirname" : "Lanerolle",
       "age" : "25",
       "gender" : "male"
   },
   "Nadeesha" : {
       "sirname" : "Lanerolle",
       "age" : "25",
       "gender" : "male"
   }
}