Friday, April 1, 2022

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

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

}

}