-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatadriven3.java
More file actions
70 lines (66 loc) · 1.96 KB
/
Datadriven3.java
File metadata and controls
70 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package DataDrivenFrameWork;
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.Assert;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.Sheet;
import jxl.Cell;
public class Datadriven3 {
static WebDriver driver;
@Test(dataProvider = "testdata")
public void Slabslogin(String User, String Pwd)throws InterruptedException
{
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).sendKeys("User");
driver.findElement(By.id("password")).sendKeys("Pwd");
driver.findElement(By.id("login-button")).click();
driver.close();
String url = driver.getCurrentUrl();
if(url.contains("https://www.saucedemo.com/"))
{
System.out.println("User Successful Login Test Case Passed");
}
else
{
System.out.println("User Fail to Login Test Case Failed");
}
Assert.assertEquals(url, "https://www.saucedemo.com/");
}
@AfterMethod
public void closeBrowser()
{
driver.close();
}
@DataProvider(name = "testdata")
public Object[][] readExcel() throws BiffException,IOException
{
File ff = new File("C:\\Users\\salka\\Documents\\DDFW\\DDFramework.xls");
Workbook ww =Workbook.getWorkbook(ff);
Sheet ss = ww.getSheet(0);
int cols = ss.getColumns();
int rows = ss.getRows();
System.out.println(cols);
System.out.println(rows);
String inputData [] [] = new String [rows] [cols];
for(int i=0;i<rows;i++)
{
for (int j=0;j<cols;j++)
{
Cell cc=ss.getCell(j,i);
inputData[i][j]=cc.getContents();
System.out.println(inputData[i][j]);
}
}
return inputData;
}
}