Thursday, March 31, 2022

Selenium TestNG PART - 1

 TestNG :

  •      TestNG is an open-source testing framework where NG stands for 'Next Generation.
  •      Failed test cases can be run separately using TestNG.
  •      Test Reports can be generated using TestNG.

Program :

 package selenium;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.Test;


public class NewTestNG {

public String baseUrl = "https://suriyaparithy.blogspot.com/";

String driverPath = "C:\\Selenium\\chromedriver\\chromedriver.exe";

public WebDriver driver ;

  @Test

  public void homepage() {

  System.out.println("launching chrome browser");

  System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");

  WebDriver driver = new ChromeDriver();

  driver.manage().window().maximize();

  driver.get(baseUrl);

  String expectedTitle = "Learning Oracle Application and Software Testing";

  String actualTitle = driver.getTitle();

  Assert.assertEquals(actualTitle, expectedTitle);

  }

}


Selenium WebDriver - Google Search Page

 package selenium;


import java.time.Duration;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class Googlesearchpage {


public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://google.com");

System.out.println(driver.getCurrentUrl());

               System.out.println(driver.getTitle());

        

               driver.manage().timeouts().implicitlyWait(Duration.ofMillis(5000));

                Thread.sleep(5 * 1000);

        

             WebElement searchBox = driver.findElement(By.name("q"));

             WebElement searchButton = driver.findElement(By.name("btnK"));

        

        searchBox.sendKeys("suriyaparithy");

        searchButton.click();

        

        System.out.println(driver.getTitle());

        System.out.println(driver.getCurrentUrl());

        

        System.out.println(searchBox.getAttribute("value"));

        

        searchButton.getText();

        searchBox = driver.findElement(By.name("q"));

        searchBox.getAttribute("value");

}


}

Java Program Conditional Statement PART - 4

 package selenium;

public class Conditionalstatement {

public static void main(String[] args) {

int number =6;

//using ternary

System.out.println(number%2==0 ? "Even Number" : "Odd Number");

int person_age =15;

//Using Ternary Operator

System.out.println(person_age>=18 ? "Eligible for vote" : "Not eligible for vote");

//IF ELSEIF CONDITION

int num=10;

if(num>0)

{

System.out.println("Number is positive");

}

else if (num<0) 

{

System.out.println("Number is negative");

}

else if (num==0) 

{

System.out.println("Number is zero");

}

}

}


Java Program Operators PART - 3

 package selenium;

public class Operators {

public static void main(String[] args) {

//Conditional Operator - Use of Ternary operator

int age =20;

String res=(age >=18) ? "Eligible to vote": "Not eligible to vote";

System.out.println(res);

int a = 10;

int res1=++a; //pre increment   11 //first increases value of a then assignment happens

System.out.println(res1); //10

System.out.println(a);

boolean x=true;

boolean y=false;

System.out.println(x && y); // false if both values are true will return true if not false.&& - AND operator

System.out.println(x || y); // true if either one is true give true.|| - OR operator

System.out.println(!x); //false

System.out.println(!y); //true

}

}


Java Program For Data Types Part-2

 package selenium;

public class Datatypes {

public static void main(String[] args) {

//single line variable declaration

int a=10, b=20, c=30;

System.out.println(a);

        System.out.println(b);

System.out.println(c);

System.out.println(a+b); // add the a,b value

  long c1=123456789L; //Long data type

        System.out.println(c1);

    

                 int person_age=30; // Number data type

        System.out.println(person_age);

 float item_price=15.5f; //have to specify with f character if it is a float

 System.out.println(item_price);

char grade='B'; // Char data type

System.out.println(grade);

boolean status1=true;

boolean status2=false;

System.out.println(status1+" "+status2);

String person_name="Suriya Parithy"; // Name data type

System.out.println(person_name);

}

}