1. Gmail Login with Multiple data
package com.gmail;
import
java.io.FileInputStream;
import
java.io.IOException;
import
org.openqa.selenium.By;
import
org.openqa.selenium.NotFoundException;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.ie.InternetExplorerDriver;
import
Claims.FetchExcelData;
import
jxl.Sheet;
import
jxl.Workbook;
import
jxl.read.biff.BiffException;
public class
MultipleLogin {
public static void
main(String[] args) throws BiffException, IOException, NotFoundException,
InterruptedException
{
System.setProperty("webdriver.ie.driver", "C:\\Selenium
Automation\\IeServerDriver\\IEDriverServer.exe");
WebDriver
driver = new InternetExplorerDriver();
driver.get(FetchExcelData.Fetch("C:\\Selenium Automation1\\Test
data\\TestData.xls", "URL"));
driver.manage().window().maximize();
FileInputStream
fs= new FileInputStream("C:\\Selenium
Automation1\\Test data\\LoginTest.xls");
Workbook
wb= Workbook.getWorkbook(fs);
Sheet
sh= wb.getSheet(0);
System.out.println(sh.getRows());
System.out.println(sh.getColumns());
for (int row = 0; row
< sh.getRows()-1; row++)
{
String
username = sh.getCell(0, row).getContents();
System.out.println("Username"
+ username);
driver.findElement(By.name("Email")).sendKeys(username);
String
password = sh.getCell(1, row).getContents();
System.out.println("Password"
+ password);
driver.findElement(By.name("passwrd")).sendKeys(password);
driver.findElement(By.name("SignIn")).click();
Thread.sleep(3000);
driver.findElement(By.name("Logout")).click();
Thread.sleep(3000);
}
}
}
2.
package MultiSignUp;
import java.io.IOException;
import java.util.logging.Logger;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import TestUtil.TestUtil;
public class SignUpMultiple extends TestUtil{
public static Logger logger = Logger.getLogger(SignUpMultiple.class.getName());
public String location = "C:\\Selenium\Automation\src\\TestData\\Testdata.xls";
public String baseurl="paste the URL";
public String sheetname1 = "SignUp";
public String sheetname2 = "Login";
@BeforeClass
public void setUp() throws InterruptedException{
driver= new FirefoxDriver();
logger.info("Firefox driver instantiate");
driver.get(baseurl);
driver.manage().window().maximize();
Thread.sleep(2000);
}
@Test(dataProvider="Login")
public void LoginTest(String EmailAddress,String password,String Status,String TestCaseDescription) throws Exception{
WaitForElementPresent("Login_hyperlink");
getObject("Login_hyperlink").click();
String windowhandle= driver.getWindowHandle();
driver.switchTo().window(windowhandle);
waitFor5Seconds();
String HomePage = driver.getTitle();
System.out.println(HomePage);
getObject("Loginpage_EmailAddress_txt").clear();
typeData("Loginpage_EmailAddress_txt", EmailAddress);
getObject("Loginpage_password_txt").clear();
typeData("Loginpage_password_txt", password);
waitFor5Seconds();
getObject("Login_button").click();
if(getObject("Loginpage_dat_txt")!=null){
System.out.println("Valid Email Address and valid pwd"+Status+TestCaseDescription);
waitFor5Seconds();
takeScreenShot("Welcome home page", "modulename", "Filename");
String LoginPage = driver.getTitle();
System.out.println(LoginPage);
getObject("Settings_Menu").click();
logger.info("User clicked on Settings option in Login home page");
getObject("Settings_SignOut").click();
waitFor5Seconds();
}
if(getObject("Loginpage_Email_Invalid")!=null){
System.out.println("InValid Email Address and Valid passwords entered :"+ Status + TestCaseDescription);
waitFor5Seconds();
getObject("Loginpage_close_btn").click();
}
if(getObject("Loginpage_Invalidpaswd_msg")!=null){
System.out.println("Valid Email id and INvalid pwd entry "+ Status + TestCaseDescription);
}
}
@AfterClass
public void tearDown() throws IOException
{
takeScreenShot(driver.getTitle(), "tearDown", "Enrollment");
driver.close();
driver.quit();
}
@DataProvider(name="Login")
public Object[][] createdata1() throws Exception{
Object[][] retobjArr = getExcelData(location, sheetname2, "LoginHyperlink", "Loginbtn");
return (retobjArr);
}
}
No comments:
Post a Comment