You are on page 1of 5

******************** Screenshots ********************************

package sample1;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.imageio.ImageIO;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.io.FileHandler;
import org.testng.annotations.Test;

public class ScreenshotTest {


@Test
public void f() throws IOException, AWTException, InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\New folder\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://demo.automationtesting.in/AutoComplete.html");

// Screenshot using Robot class


Robot robot1 = new Robot();
Dimension sc_size = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rect = new Rectangle(sc_size);
BufferedImage source = robot1.createScreenCapture(rect);
File destination = new File ("F:\\HCL Training Assignments\\SCC1.jpg");
ImageIO.write(source, "jpg", destination);

// Screenshot without using Robot class


TakesScreenshot ts = (TakesScreenshot) driver;
File source1 = ts.getScreenshotAs(OutputType.FILE);
File destination1 = new File ("F:\\HCL Training Assignments\\sc1.jpg");
FileHandler.copy(source1, destination1);

Thread.sleep(3000);
driver.close();
}
}

******************************* Datepicker **********************

package sample1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class DatepickerTest {


@Test
public void f() throws InterruptedException {

System.setProperty("webdriver.chrome.driver", "D:\\New folder\\


chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.leafground.com/pages/Calendar.html");
JavascriptExecutor jse = (JavascriptExecutor) driver;

jse.executeScript("document.getElementById('datepicker').value='12/20/2021'");

Thread.sleep(2000);
driver.close();

}
}

************************** scroll *******************************


package sample1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ScrollTest {


@Test
public void f() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\New folder\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

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

driver.get("https://www.w3schools.com/howto/howto_css_custom_scrollbar.asp");

// For simple scrolling


JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("scroll(0, 200)");
Thread.sleep(2000);

WebElement el = driver.findElement(By.xpath("//a[contains(text(),'Hide
Scrollbar')]"));
JavascriptExecutor jse1 = (JavascriptExecutor) driver;
jse1.executeScript("arguments[0].scrollIntoView(true);",el);
Thread.sleep(3000);
driver.close();
}
}

************************* POM ( Repository) ********************


package object_repository;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.testng.annotations.Test;

public class Elements1 {


@Test
public static WebElement Timecell(WebDriver driver) {
return driver.findElement(By.xpath("//input[@type='text']"));
}

public static WebElement Savebutton(WebDriver driver) {


return driver.findElement(By.id("le_apply"));
}
}

*********************** Functionality ****************************

package functionality;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;

import object_repository.Elements1;

public class Login1 {


@Test
public void f() {
System.setProperty("webdriver.chrome.driver", "D:\\New folder\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

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

driver.get("https://wf24.myhcl.com/iTime/iTime/index.html?v=35#/TimeSheet");

Elements1.Timecell(driver).sendKeys("09:00");
Elements1.Savebutton(driver).click();
}
}

******************** PageFactory **********************************

package object_repository;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.testng.annotations.Test;

public class Elements {

@FindBy(xpath="//input[@type='text']")
public static WebElement Timecell;

@FindBy(id="le_apply")
public static WebElement Savebutton;
}

*****************************************************************
package functionality;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;

import object_repository.Elements;

public class Login {


@Test
public void f() {
System.setProperty("webdriver.chrome.driver", "D:\\New folder\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

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

driver.get("https://wf24.myhcl.com/iTime/iTime/index.html?v=35#/TimeSheet");

PageFactory.initElements(driver,Elements.class);
Elements.Timecell.sendKeys("09:00");
Elements.Savebutton.click();

}
}

************************* Data Driven (jxl) **************************

package object_repository;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.testng.annotations.Test;

public class Elements {

@FindBy(id="userName")
public static WebElement username;
@FindBy(id="password")
public static WebElement password;

@FindBy(id="submitBtn")
public static WebElement btn;

}
=====================================
package datadriven;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import object_repository.Elements;

public class JxlTest {

@Test
public void f() throws BiffException, IOException, InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\New folder\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("https://ksrtc.in/oprs-web/login/show.do");

Workbook w1=Workbook.getWorkbook(new File("F:\\HCL Training Assignments\\


tests.xls"));
Sheet s1=w1.getSheet(0);
for(int i=1;i<s1.getRows();i++) {
String username = s1.getCell(0, i).getContents();
String password = s1.getCell(1,i).getContents();
PageFactory.initElements(driver,Elements.class);
Elements.username.sendKeys(username);
Elements.password.sendKeys(password);
Thread.sleep(1000);
Elements.btn.click();
System.out.println(username);
System.out.println(password);

}
driver.close();
}}

You might also like