Monday, January 27, 2020

Arrays

Arrays: A container which stores multiple values of same data type

Declaring an Array:

Traditional Way:

        int a[] = new int[5];
                a[0] = 2;
a[1] = 3;
a[2] = 4;
a[3] = 3;
a[4] = 7;

Most simple way

int b[] = { 12, 3, 4, 5, 6 };

How to retrieve values present in array?

Ans: Using index.

see below program for more and better understanding.

Sample Program 

public static void main(String[] args) {

int a[] = new int[5];
a[0] = 2;
a[1] = 3;
a[2] = 4;
a[3] = 3;
a[4] = 7;// initialized values into that array
int b[] = { 12, 3, 4, 5, 6 };
for (int i = 0; i < b.length; i++) {
System.out.println(b[i]);// retrieve values present in the array

}


}


Multidimensional Array

Declaration:
                                  ↓ where 3 is column(see below)
int a[][] = new int[2][3];
                             ↑- where 2 is row(see below)


         C   C    C

R      1    2    3

R      4     5    6

Traditional Way of multidimensional declaration

int a[][] = new int[2][3];

a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;

modern /simple way

int b[][] = { { 1, 2, 3 }, { 4, 5, 6 } }; // multidimensional array


Write a program to get minimum value from above metric.

                      1  2  3

                      4  5  6


There are two rows and three columns.

so i for row & j for column



public class Multidimensional {

public static void main(String[] args) {

int b[][] = { { 1, 2, 3 }, { 4, 5, 6 } }; // multidimensional array

int min = b[0][0];// keeping the first element of matrix as min for our reference

for (int i = 0; i < 2; i++)// row
{
for (int j = 0; j < 3; j++)//column
                          {
if (b[i][j] < min) {
min = b[i][j];
}
}

}
System.out.println(min);
}

}


Note: Execute and understand :)




Now to get max number out off below  matrix.

// 4 5 6
// 5 4 9

public class PrintMaxNumberFromMatrix {

public static void main(String[] args) {
// TODO Auto-generated method stub

// 4 5 6
// 5 4 9
//
int matrix[][] = { { 4, 5, 6 }, { 5, 4, 9 } };
int max = matrix[0][0];

for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (matrix[i][j] > max)
;

max = matrix[i][j];

}

}
System.out.println(max);
}

}




-------------------


To find the maximum number in the identified colomn(which is lowest in )


public class Check {

public static void main(String[] args) {

int b[][] = { { 6, 4, 3 }, { 4, 0, 6 }, { 3, 2, 7 } }; // multidimensional
// array
int min = b[0][0];// keeping the first element of matrix as min for our
// reference
int minColumn = 0;

for (int i = 0; i < 3; i++)// row
{
for (int j = 0; j < 3; j++)// column
{
if (b[i][j] < min) {
min = b[i][j];
minColumn = j;

}

}

}
int max = b[0][minColumn];
int k = 0;
while (k < 3) {
if (b[k][minColumn] > max) {
max = b[k][minColumn];
}
k++;

}
System.out.println(max);
// System.out.println("the min value in matrix is"+min);

}

}

Saturday, January 18, 2020

Constructors and their usage

Key and important note on constructors


  • Block of code executed whenever an object is created
  • Constructor does not return any values
  • Name of the Constructor  should be the class name.
  • Compiler will call default/implicit constructor(java- library-if not defined any constructor block).
  • Constructor will be called whenever an object is created.
  • In real-time Constructor  is used to define variables or to initiate properties 

sample code for constructor:

public class constructorDemo {

public constructorDemo() {
System.out.println("i am in the constructor");

}

public void getData() {

System.out.println("i am the method");
}

public static void main(String[] args) {
// TODO Auto-generated method stub
constructorDemo obj = new constructorDemo();
// obj is created to call constructor (constructorDemo)

}

}


Parameterized constructor


public class constructorDemo {

public constructorDemo() {
System.out.println("i am in the constructor");

}

public constructorDemo(int a, int b) {
System.out.println("i am in the parametrized constructor");
int c = a + b;
System.out.println(c);

}

public constructorDemo(String str) {
System.out.println(str);
}

public void getData() {

System.out.println("i am the method");
}

public static void main(String[] args) {
// TODO Auto-generated method stub
constructorDemo obj = new constructorDemo(4, 5);
constructorDemo obj1 = new constructorDemo("Hello");
// obj is created to call constructor (constructorDemo)

}

}

Thursday, January 2, 2020

Gradle_Set_Up

Installation:

1. Eclipse
2. Help
3. Eclipse Marketplace
4. search for gradle 
5. Note: Select "Buildship Gradle Integration 3.0"
6. click install




7. Download Gradle

https://drive.google.com/open?id=13X7tM0-hjcI5C3IK4_0JLdHqEE9bj-wV

8.Extract and save in any of the drive.

9. Copy and Add path as below


10.Add the dependencies under build.gradle. open and add the below dependencies




--------------------------------------------------------------------------------------------
/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.6.1/userguide/java_library_plugin.html
 */
apply plugin: 'java'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
version = '1.2.1'




repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
      mavenCentral()
      maven {url  "http://nexus01.cloud.operative.com:8081/nexus/content/groups/public" }
      mavenLocal()
}


dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    compile 'org.seleniumhq.selenium:selenium-java:3.14.0'
    compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
    compile 'org.apache.poi:poi-ooxml:3.10-FINAL'
    compile 'org.apache.poi:poi-ooxml-schemas:3.10-FINAL'
    compile 'com.squareup.okhttp:okhttp:2.7.5'
    compile 'com.squareup.okhttp3:okhttp:3.9.1'
    compile 'org.mongodb:mongodb-driver:3.4.3'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.8'
    compile 'com.fasterxml.jackson.core:jackson-core:2.9.8'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'javax.json:javax.json-api:1.1'
    compile 'org.glassfish:javax.json:1.0.4'
    compile 'com.googlecode.json-simple:json-simple:1.1.1'
    compile 'org.json:json:20171018'
    compile 'org.elasticsearch:elasticsearch:5.6.2'
    compile 'org.elasticsearch.client:transport:5.6.2'
    compile 'com.amazonaws:aws-java-sdk:1.11.163'
    compile 'redis.clients:jedis:2.6.2'
    compile 'mysql:mysql-connector-java:5.1.6'
     // https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
    compile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.7.1'
    testCompile 'org.testng:testng:6.14.3'
    testCompile 'io.rest-assured:rest-assured:3.0.0'
    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:28.0-jre'
    compile fileTree(dir: 'lib', include: '*.jar')
    compile 'com.opencsv:opencsv:5.0'
    // https://mvnrepository.com/artifact/com.aventstack/extentreports
    compile group: 'com.aventstack', name: 'extentreports', version: '3.0.0'
    // https://mvnrepository.com/artifact/com.relevantcodes/extentreports
    compile group: 'com.relevantcodes', name: 'extentreports', version: '2.40.2'
    // https://mvnrepository.com/artifact/io.rest-assured/xml-path
   compile group: 'io.rest-assured', name: 'xml-path', version: '3.1.0'
   // https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator
   compile group: 'io.rest-assured', name: 'json-schema-validator', version: '3.0.0'

     
     
    
}

ext.testFile = System.getProperty('Test_Plan') ?: 'testng.xml'

test {
    useTestNG {
        suites "/$testFile"
         useDefaultListeners = true
    }
    test.ignoreFailures = true
    reports.html.enabled = false
   }
  
  test {
   systemProperty "Env",System.getProperty("Env")
  }
   


 task testJar(type: Jar) {
  classifier = 'tests'
from sourceSets.test.output
}

 task testSourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'testSources'
    from sourceSets.test.allSource
}


artifacts {
  archives testJar
}


---------------------------------------------------------------------------------------------------------------------------------

Wednesday, January 1, 2020

TestNG_Set_Up

Installation:

1. Eclipse
2. Help
3.Install New Software


4. Enter http://beust.com/eclipse/




5.Click Next.

6.Eclipse shall restart after click on yes.

Configuration:

1.Right click on the Project
2.Click on the properties.


3. Select Java Build Path and click on Add Library.


4. Select TestNG and Next>Finish>Ok


5. You should be seeing below in your project.



TestNG set up completed. Cheers:-) 


Selenium_Grid_With_Docker_Compose(yml file)

 docker-compose.yml version: "3" services:   hub:     image: selenium/hub:3.141.59     ports:       - "4444:4444"   chro...