Friday, May 20, 2022

Java Programming Examples

 1. Java Syntax:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
System.out.println("suriya parithy");
}
}

2. Data types and variables:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  // type variableName = value;
  String name = "suriya";
  int myNum = 15;
  float myFloatNum = 5.99f;
  char myLetter = 'S';
  boolean myBool = true;
  
  System.out.println(name);
  System.out.println(myNum);
  System.out.println(myFloatNum);
  System.out.println(myLetter);
  System.out.println(myBool);
  }
}

3. Java Operators:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  int sum1 =100 + 200;
  int sum2 = sum1 + 300;
  int x = 4;
  int y = 6;
  System.out.println(sum1);
  System.out.println(sum2);
  System.out.println(x-y);
  System.out.println(x == y); // returns false because 4 is not equal to 6
  System.out.println(x != y); // returns true because 4 is not equal to 6
  System.out.println(x > y); 
  System.out.println(x < y);
  System.out.println(x > 3 && x < 10); // returns true because 4 is greater than 3 AND 4 is less than 10
  System.out.println(x > 3 || x < 5); // returns true because one of the conditions are true(4 is greater than 3)
  }
}

4. Java Strings:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  String name = "suriya parithy";
  System.out.println("The length of the name string is:" + name.length());
  System.out.println(name.toUpperCase()); // Outputs "SURIYA PARITHY"
  System.out.println(name.toLowerCase()); // Outputs "suriya parithy"
  }
}

5. Java Math:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  System.out.println(Math.max(15, 20));
  System.out.println(Math.min(5, 10));
  System.out.println(Math.sqrt(64));
  }
}


👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

Wednesday, May 18, 2022

Selenium Java - Shadow DOM, TestNG, Properties File, Extent Reports, Screenshot

 package selenium;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java. text.SimpleDateFormat;

import java.util.Date;

import java.util.Properties;

import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.ITestResult;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

import io.github.sukgu.Shadow;



public class Job_Failure_Login_Page_NG {

public WebDriver driver;

public ExtentReports extent;

public ExtentTest extentTest; 



@BeforeTest

public void setExtent(){

  extent = new ExtentReports(System.getProperty("user.dir")+"/test output/result/LoginPageReport.html", true); 

//To add system or environment info by using the add system info method.

extent.addSystemInfo("User Name", "Suriya");

extent.addSystemInfo("Environment", "Automation Testing");

extent.addSystemInfo("Application","Job"); 

extent.addSystemInfo("Test Scenario","Login Functionality");


}


@AfterTest

public void endReport(){

extent.flush(); 

      //extent.close(); 

}



public static String getScreenshot(WebDriver driver, String screenshotName) throws IOException{

String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());

TakesScreenshot ts = (TakesScreenshot) driver;

File source = ts.getScreenshotAs(OutputType.FILE);

// after execution, you could see a folder "FailedTestsScreenshots"

// under src folder

String destination = System.getProperty("user.dir") + "/FailedTestsScreenshots/" + screenshotName + dateName  + ".png";

File finalDestination = new File(destination);

FileUtils.copyFile(source, finalDestination);

return destination;

}


@BeforeMethod

public void setup() throws InterruptedException, IOException {

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

driver = new ChromeDriver(); 

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

driver.manage().deleteAllCookies();

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

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

driver.get("URL");

Thread.sleep(3000);



}

  @Test(enabled=true,priority=0)

  public void user_and_password_correct() throws InterruptedException, IOException {

  extentTest = extent.startTest("Enter correct username and password");

  Shadow shadow = new Shadow(driver);

  WebElement element = shadow.findElement("amplify-form-section");

  //File Read

  FileReader reader=new FileReader("datafile.properties");

  Properties p=new Properties();  

  p.load(reader);

  

  extentTest.log(LogStatus.INFO, "Enter valid Username");

  element.findElement(By.id("username")).sendKeys(p.getProperty("username"));

  extentTest.log(LogStatus.INFO, "Enter valid Password");

  element.findElement(By.id("password")).sendKeys(p.getProperty("password"));

 

  extentTest.log(LogStatus.INFO, "Click on the SIGN IN button "); 

  WebElement signin = element.findElement(By.cssSelector("[class=button][type=submit]"));

  signin.submit();

  extentTest.log(LogStatus.INFO, "Home Page Open");

  Thread.sleep(3000);

  driver.findElement(By.linkText("LogOut")).click();

  Thread.sleep(5000);

   

 }


  
  @AfterMethod

public void Down(ITestResult result) throws IOException{


      if(result.getStatus()==ITestResult.FAILURE){

       extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getName()); //to add name in extent report

extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS "+result.getThrowable()); //to add error/exception in extent report

            String screenshotPath = getScreenshot(driver, result.getName());

extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath)); //to add screenshot in extent report

//extentTest.log(LogStatus.FAIL, extentTest.addScreencast(screenshotPath)); 
    //to add screencast/video in extent report

}

else if(result.getStatus()==ITestResult.SKIP){

extentTest.log(LogStatus.SKIP, "Test Case SKIPPED IS " + result.getName());

}

else if(result.getStatus()==ITestResult.SUCCESS){

extentTest.log(LogStatus.PASS, "Test Case PASSED IS " + result.getName());


}

extent.endTest(extentTest); //ending test and ends the current test and prepare to create html report

driver.quit();

}

}

    

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

Wednesday, May 4, 2022

Types of Test Automation Framework

Framework:

  A testing framework is a set of rules used for creating and designing test cases.  

Different types of frameworks:

1. Linear Scripting Framework:

  •   Linear Scripting Framework is a basic level test automation framework that is in the form of ‘Record and Playback’ in a linear fashion.
  •   This framework is also known as the ‘Record and Playback’ framework.
  •   This type of framework is used to test small-sized applications.

2. Modular Testing Framework:

  •   In the modular testing framework, testers create test scripts module-wise by breaking down the complete application under test into smaller, independent tests.
  •   In simple words, testers divide the application into multiple modules and create test scripts individually.

3. Data-driven Framework:

  •   The data-driven test automation framework is focused on separating the test script logic and the test data from each other.
  •   It allows us to create test automation scripts by passing different sets of test data.
  •   The test data set is kept in external files or resources such as MS Excel Sheets, MS Access Tables, SQL Database, XML files, etc.,

4. Behavior-Driven Development Testing Framework:

  •   The purpose of this Behavior Driven Development framework is to create a platform that allows everyone (such as Business Analysts, Developers, Testers, etc,) to participate actively.
  •   It requires increased collaboration between Development and Test Teams.
  •   It doesn’t require the users to be acquainted with a programming language. We use non-technical, natural language to create test specifications.

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

Friday, April 29, 2022

Essential Strategies for Learning 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.

👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.

Friday, April 22, 2022

Selenium WebDriver Browser Commands Explained: Best Practices and Examples

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); 

}
}


👋 Hi, I'm Suriya — QA Engineer with 4+ years of experience in manual, API & automation testing.

📬 Contact Me | LinkedIn | GitHub

📌 Follow for: Real-Time Test Cases, Bug Reports, Selenium Frameworks.