Friday, April 29, 2022

Basics of Software Testing

What is Software?

      Software is a collection of code installed onto your computer's hard drive.

Types of software:

  • System software
  • Application software
            ->Windows application
            ->Web application
            ->Mobile application

what is software testing?    
  • Testing the software whether it is working according to the requirement.
Main Goal of testing:
  •   Expected Result = Actual Result(Test Pass)
  •   Expected Result != Actual Result(Test Fail)    
Types of Testing:     
  •  Manual Testing
             Testing the software without the help of a tool or software.
             Done by humans.
  •  Automation Testing
             Testing the software with the help of tools or other software.
             Done by human+machine.

Friday, April 22, 2022

Selenium WebDriver - Browser Commands

package selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selenium_Webdriver {
public static void main(String[] args) {
String driverExecutablePath = "C:\\Selenium\\chromedriver\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverExecutablePath);

// Create a new instance of the Chrome driver 
WebDriver driver = new ChromeDriver(); 

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

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

// Storing the Application Url in the String variable 
String url = "https://suriyaparithy.blogspot.com/"; 

//Launch the ToolsQA WebSite 
driver.get(url); 

// Storing Title name in the String variable 
String title = driver.getTitle(); 

// Storing Title length in the Int variable 
int titleLength = driver.getTitle().length(); 

// Printing Title & Title length in the Console window 
System.out.println("Title of the page is : " + title); 
System.out.println("Length of the title is : "+ titleLength); 

// Storing URL in String variable 
String actualUrl = driver.getCurrentUrl(); 

if (actualUrl.equals(url)){ 
System.out.println("Verification Successful - The correct Url is opened.");
}
else {
System.out.println("Verification Failed - An incorrect Url is opened."); 

//In case of Fail, you like to print the actual and expected URL for the record purpose 
System.out.println("Actual URL is : " + actualUrl); 
System.out.println("Expected URL is : " + url);
}

// Storing Page Source in String variable 
String pageSource = driver.getPageSource(); 

// Storing Page Source length in Int variable 
int pageSourceLength = pageSource.length(); 

// Printing length of the Page Source on the console 
System.out.println("Total length of the Pgae Source is : " + pageSourceLength); 

}
}


From Beginner to Expert: Java Loop Programming

 Loops :

  •   Loops are used to execute a set of statements repeatedly until a particular condition is satisfied.

Types of Loops :

  for loop: This executes a statement a particular number of times.

  while loop: This executes a statement an unknown number of times.

  do-while loop: This executes a statement at least one time.

The syntax for the "for" loop is :

  for(Variable Initialization; Boolean_Expression Test; Increment/Decrement){

   //Statements

}

Example :

package selenium;

public class Java_practise {

public static void main(String[] args) {

  // This will print -- 0,1,2,3,4,5

for(int Increment = 0;Increment<=5;Increment++){

System.out.println("Count is  ==> " + Increment );

}

// This will print -- 5,4,3,2,1,0

for(int Decrement = 5;Decrement>=0;Decrement--){

System.out.println("Count is ==> " + Decrement );

}

// This will print -- 0,2,4

for(int Increment = 0;Increment<=5;Increment+=2){

System.out.println("Skip every one another  ==> " + Increment );

}

// This will print -- 0,1,2,3,4,5

for(int Count = 0;Count<=10;Count++)

{

if(Count==6){

break;

}

System.out.println("Count is ==> " + Count );

}

// This will just print -- 3

            for(int Count = 0;Count<=5;Count++){

             if(Count==3){

         System.out.println("Count is ==> " + Count);

          continue;

}

}

}

}


The syntax for the while loop :
   while(Boolean_Expression Test){
//Statements
}

Example :
package selenium;
public class Java_practise {
   public static void main(String[] args) {
int Count = 0;
// This will print -- 5,10,15,20,25
while(Count < 25){
Count = Count + 5;
System.out.println("Count is ==> "+ Count);
}        
}
}

The syntax for the do-while loop  :
   do{
//Statements
}while(Boolean_Expression Test);

Example :
package selenium;
public class Java_practise {
  public static void main(String[] args) {
int CountOnce = 25;
System.out.println("<==== Next Count ====>");
// This will just print once 
do{
CountOnce = CountOnce + 5;  
System.out.println("Count is ==> "+ CountOnce);
}while(CountOnce < 25);
     
}
}

The syntax for enhanced for loop :
   for (data_type variable: array_name)

Examples :
package selenium;
public class Java_practise {
     public static void main(String[] args) {
// Array of String storing days of the week
    String days[] = { "Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sun"};

    // Enhanced for loop, this will automatically iterate on the array list 
    for (String dayName : days) {
      System.out.println("Days ==> "+ dayName);
    }

    System.out.println("<==== Normal For Loop ====>");
    // Normal for loop
    for (int i=0; i < days.length; i++) {
        System.out.println("Days ==> "+ days[i]);

     }
}
}



Thursday, April 21, 2022

Java Arrays: From Basics to Beyond

 Arrays :
  •  An array is a type of variable that can store multiple values. It is like a list of items but it always contains similar data type values.
  • An array is a data structure in java that can hold one or more values in a single variable.
  •  Array in java is a collection of similar types of values.

Example 1:
  String[] aCarMake = new String[5];
      aCarMake[0] = "BMW";
      aCarMake[1] = "AUDI";
      aCarMake[2] = "TOYOTA";
      aCarMake[3] = "SUZUKI";
      aCarMake[4] = "HONDA";

Example 2:
  String [] aCarMake = {"BMW", "AUDI", "TOYOTA", "SUZUKI", "HONDA"};

Example 3:
package selenium;
public class Java_practise {
public static void main(String[] args) {
//Declaring an Array
String [] aMake = {"BMW", "AUDI", "TOYOTA", "SUZUKI", "HONDA"};

// Calling the Print Array method and passing an Array as a parameter
Print_Array(aMake);
}

//This accepts Array as an argument of type String 
public static void Print_Array(String []array){
                 for(int i = 0;i<=array.length-1;i++){
System.out.println("All the values of an Array ==> " + array[i]);
}
}
}


Java - Decision making(IF Statement)

 1. Decision-making in java

  •   There are two types of decision-making statements in Java. One is very commonly used which is the If statement and you will find it almost in every piece of code. The second is the Switch statement.

 various forms of if...else statements in Java:-

  if statement

  if...else statement

  if...else if...else statement


if statement :

Example

package selenium;

public class Java_practise {

public static void main(String[] args) {

String sDay = "Sunday";

int iDay = 7;


if(sDay.equals("Sunday")){

System.out.println("Today is Sunday");

}


if(iDay==7){

System.out.println("Today is Sunday"); }

}

}


 if...else statement :


Example
package selenium;

public class Java_practise {

public static void main(String[] args) {
String sDay = "Saturday";
int iDay = 6;

if(sDay.equals("Sunday")){
System.out.println("Today is Sunday");
}else{
System.out.println("Today is not Sunday");
}

if(iDay==7){
System.out.println("Today is Sunday");
}else{
System.out.println("Today is not Sunday");
}
}
}


if...else if...else statement

Example
package selenium;

public class Java_practise {

public static void main(String[] args) {
String sDay = "Monday";
int iDay = 1;

if(sDay.equals("Sunday")){
System.out.println("Today is Sunday");
}else if(sDay.equals("Saturday")){
System.out.println("Today is not Saturday");
}else{
System.out.println("Today is a Weekday");
}

if(iDay==7){
System.out.println("Today is Sunday");
}else if(iDay==6){
System.out.println("Today is Saturday");
}else{
System.out.println("Today is a Weekday");
}
}
}



JAVA - Data Types and Variables

1. Data Type - int

  •   The integer data type is used to store numeric/numbers in the variable. 
  •    But a decimal number can not be stored in the 'int' data type.

Example :

 package selenium;

 public class Java_practise {

 public static void main(String[] args) {

                int mark;

mark = 445;

System.out.println("suriya total mark in 10 th " + mark);

 }

 }


2. Data Type - char

  •   The character data type is used to store just one character in the variable. It is very rarely used in Selenium. 

Example :

 package selenium;

 public class Java_practise {

 public static void main(String[] args) {

char a;

                 a = 'S';

        //Print the value of the char variable

      System.out.println("Value of char is : " +  a);

}

}


3. Data Type - double

  •   To declare a variable used to hold such a decimal number, you can use the double keyword.

Example :

package selenium;

public class Java_practise {

public static void main(String[] args) {

double PI;

    //Initialize the double variable with value 'P'

        PI = 3.14159;

  //Print the value of the double variable

        System.out.print("PI: " + PI);

}

}



Tuesday, April 12, 2022

Selenium Java - Shadow DOM, TestNG, Read properties file

 package selenium;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.github.sukgu.Shadow;
public class Login_Page_NG {
WebDriver driver;
@BeforeTest
public void beforetest() throws InterruptedException, IOException {
  System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get( "Paste the your URL");
}
//Test case - Both User name and Password are entered correctly.
  @Test(enabled=true,priority=0)
  public void user_and_password_correct() throws InterruptedException, IOException {
  Shadow shadow = new Shadow(driver);
  WebElement element = shadow.findElement("form");

  //File Read
  FileReader reader=new FileReader("datafile.properties");
  Properties p=new Properties();  
  p.load(reader);
  element.findElement(By.id("username")).sendKeys(p.getProperty("username"));
  element.findElement(By.id("password")).sendKeys(p.getProperty("password"));
  WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));
  signin.submit();
  Thread.sleep(3000);
  driver.findElement(By.linkText("LogOut")).click();
  System.out.println("User name and Password are entered correctly - Login Successful");
  Thread.sleep(5000);
 }

  //Test case - Both Username and Password Fields are blank.
  @Test(enabled=true,priority=1)
  public void user_and_password_blank() throws InterruptedException {
  Shadow shadow = new Shadow(driver);
  WebElement element = shadow.findElement("form");
  WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));
  signin.submit();
  Thread.sleep(3000);
  System.out.println("Username cannot be empty");
 }

  //Test case - The username field is filled and the Password field is blank.
  @Test(enabled=true,priority=2)
  public void userfilled_and_password_blank() throws InterruptedException, IOException {
  Shadow shadow = new Shadow(driver);
  WebElement element = shadow.findElement("form");
  FileReader reader=new FileReader("datafile.properties");
  Properties p=new Properties();  
  p.load(reader);
  element.findElement(By.id("username")).sendKeys(p.getProperty("username"));
  WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));
  signin.submit();
  System.out.println("Password cannot be empty");
  Thread.sleep(3000);
  }

  //Test case - Enter invalid user name & invalid password
  @Test(enabled=true,priority=3)
  public void invalid_username_and_password() {
  Shadow shadow = new Shadow(driver);
  WebElement element = shadow.findElement("form");
  WebElement username = element.findElement(By.id("username"));
           username.click();
  username.sendKeys("oracle");
  WebElement password = element.findElement(By.id("password"));
  password.click();
  password.sendKeys("qwerty");
 WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));
  signin.submit();
 System.out.println("User does not exist.");
 }
}

Saturday, April 2, 2022

Java Program - Data types and variables PART-5

 package selenium;
public class Datatypesandvariable {
   public static void main(String[] args)  {

//Data types and variables
int rollno, tamil, english, maths, science, social, total;
String sname;
float avg;

rollno=1;
sname="suriya";
tamil=65;
english=80;
maths=70;
science=90;
social=85;

total=tamil+english+maths+science+social;
avg=total/5;

System.out.println("Roll Number : " + rollno);
System.out.println("Student Name : " + sname);
System.out.println("Tamil : " + tamil);
System.out.println("English : " + english);
System.out.println("Maths : " + maths);
System.out.println("Science : " + science);
System.out.println("Social : " + social);
System.out.println("Total : " + total);
System.out.println("Average : " + avg);
    }
}

Selenium - Facebook Create New Account

 package selenium;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Fb_Create_New_Account {
 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://en-gb.facebook.com/");
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
driver.findElement(By.linkText("Create New Account")).click();
driver.findElement(By.name("firstname")).sendKeys("Suriya");
driver.findElement(By.name("lastname")).sendKeys("Parithy");
driver.findElement(By.name("reg_email__")).sendKeys("8012345679");
        driver.findElement(By.name("reg_passwd__")).sendKeys("123098");
        
      //Static dropdown
        Select date = new Select(driver.findElement(By.id("day")));
        Thread.sleep(1000);
        date.selectByVisibleText("1");
        Select month = new Select(driver.findElement(By.id("month")));
        Thread.sleep(1000);
        month.selectByValue("4");
        Select year = new Select(driver.findElement(By.id("year")));
        Thread.sleep(1000);
        year.selectByValue("1996");
        
      //Radio button
        driver.findElement(By.xpath("//input[@value='2']")).click(); //for selecting male
        driver.findElement(By.name("websubmit")).click();
        driver.close();
 }
}

Friday, April 1, 2022

Selenium - Get the Actual Message in WebDriver

 Path - 1 :
  WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.alert-danger p")));
      List<String> alertTextList = driver.findElements(By.cssSelector("div.alert-danger p"))
              .stream()
              .map(WebElement::getText)
              .toList();
      System.out.println("Application Status :" + alertTextList);

Path - 2 :
 WebElement actmessage = new WebDriverWait(driver, 15)
           .until(ExpectedConditions.elementToBeClickable(By.className("Toastify")));
 String act = actmessage.getText();
System.out.println("Application Status :" + act);

Path - 3 :
WebElement display =  driver.findElement(By.className("alert-content"));
String act = display.getText();
//To print the value
System.out.println("Element displayed is :" + act);

Selenium TestNG (Priority, Skip) PART - 2

 package selenium;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class NewTestNG {
  @Test(priority = 0)
  public void RegisterwithNoData() {
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
 driver.manage().window().maximize();
driver.get("http://www.kurs-selenium.pl/demo/register");
driver.findElement(By.cssSelector("input[name=firstname]"));
      driver.findElement(By.cssSelector("input[name=lastname]"));
      driver.findElement(By.cssSelector("input[name=phone]"));
      driver.findElement(By.cssSelector("input[name=email]"));
      driver.findElement(By.cssSelector("input[name=password]"));
      driver.findElement(By.cssSelector("input[name=confirmpassword]"));
      driver.findElement(By.cssSelector(".signupbtn")).click();
      WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.alert-danger p")));
List<String> alertTextList = driver.findElements(By.cssSelector("div.alert-danger p"))
              .stream()
              .map(WebElement::getText)
              .toList();
      System.out.println("Application Status :" + alertTextList);
 }

  @Test(enabled = false)
  public void RegisterwithInvalidEmail() {
  System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().window().maximize();
      driver.get("http://www.kurs-selenium.pl/demo/register");
      driver.findElement(By.cssSelector("input[name=firstname]")).sendKeys("suriya");
      driver.findElement(By.cssSelector("input[name=lastname]")).sendKeys("parithy");
      driver.findElement(By.cssSelector("input[name=phone]")).sendKeys("8123456789");
      driver.findElement(By.cssSelector("input[name=email]")).sendKeys("suriya@gmail");
      driver.findElement(By.cssSelector("input[name=password]")).sendKeys("12345678");
 driver.findElement(By.cssSelector("input[name=confirmpassword]")).sendKeys("12345678");
      driver.findElement(By.cssSelector(".signupbtn")).click();
 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.alert-danger p")));
List<String> alertTextList = driver.findElements(By.cssSelector("div.alert-danger p"))
              .stream()
              .map(WebElement::getText)
              .toList();
      System.out.println("Application Status :" + alertTextList);
       }
}