How to fetch data as input from excel and use it as a input to login or some other page? Please help

18,029 vistas
Ir al primer mensaje no leído

Hemapriya Rajendran

no leída,
28 ene 2013, 2:43:37 a.m.28/1/2013
para seleniu...@googlegroups.com
Assume, I have the excel sheet which contains the input values for my application. While testing the application with selenium webdriver,
It has to fetch the data from excel (for eg: Username and password) and apply it in the login page of the application and send the result back whether it is pass or fail.
I am using TestNG with selenium webdriver.

Please help me I am new to using selenium.

This is my code for entering user name and password and click on login button


import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CoreMeasureSTK {
            WebDriver driver;
            WebElement userName;
            WebElement password;

            @BeforeTest
            public void start() throws MalformedURLException {
                        driver = new FirefoxDriver();
                        driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
            }

  @Test
  public void Test() {
              driver.get("url");
                      
                          // Entering user name and password
                        userName = driver.findElement(By.id("Login1_UserName"));
                        userName.sendKeys("qczxn");
                        //String expectedName = userName.getAttribute("value");              
                        password = driver.findElement(By.id("Login1_Password"));
                        password.sendKeys("Change@123");
                        //String expectedPassword = password.getAttribute("value");                      
                        driver.findElement(By.id("Login1_LoginButton")).click();

chaitanya

no leída,
28 ene 2013, 3:05:10 a.m.28/1/2013
para seleniu...@googlegroups.com
Hi Hemapriya,
In This way you can fetch username and password from Excel and use it as per your tests...
import jxl.Sheet;
import jxl.Workbook;
public void read() throws IOException {
Workbook w;
File inputWorkbook = new File(inputFile);
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet in excel workbook
Sheet sheet = w.getSheet(0);
for (int j = 1; j < sheet.getRows(); j++) {
String username = sheet.getCell(0, j).getContents();
String password = sheet.getCell(1, j).getContents();

}

And Once the test is done.you can write the results to the excel sheet as below...
Pass your result as an argument to this method...
public void writeResult(String result) {
synchronized (result) {
try {
// use this in order to write output to text file
// File file =new File("result.txt");
// String outFileName = result + "\\" + (new
// java.sql.Date(today.getTime())) + ".xls";
String fileName = "result-"+version+".ods";
//File file = new File("result.xls");
File file = new File("/home/chaitanya/workspace/"+fileName);
BufferedWriter bufferWritter = new BufferedWriter(
new FileWriter(file.getName(), true));
bufferWritter.write(result+"\t");
bufferWritter.close();
} catch (IOException e) {
e.printStackTrace();
}

NaveenKumar Reddy R

no leída,
28 ene 2013, 3:06:45 a.m.28/1/2013
para seleniu...@googlegroups.com
HI Hema,

   Refer this http://functionaltestautomation.blogspot.in/2009/10/dataprovider-data-driven-testing-with.html.




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/hYaC4KfeJu0J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hemapriya Rajendran

no leída,
28 ene 2013, 4:23:26 a.m.28/1/2013
para seleniu...@googlegroups.com
Hi Chaitanya,

Thanks for your help.
I'll try this code and let you know the result.

Regards,
Hemapriya R

Hemapriya Rajendran

no leída,
29 ene 2013, 11:11:32 a.m.29/1/2013
para seleniu...@googlegroups.com
Hi, It is working fine. Thanks for Chaitanya and Navin inputs.

Regards,
Hemapriya R

Karthick Nk

no leída,
30 oct 2014, 1:04:49 a.m.30/10/2014
para seleniu...@googlegroups.com
Hi Hemapriya,
 
Can you send me the example of input getting from excel sheet. 

Abhi Ram

no leída,
13 ene 2015, 1:03:42 a.m.13/1/2015
para seleniu...@googlegroups.com
Hi All,

Use the below java .jar in your projects for reading and writing a data from excel

POIRE

Its a Microsoft Ms-office(Excel,Ms Word,PowerPoint) files handling with Java with the help of the POI classes. This API was develop on the top of the POI library. Its has so many methods for working with the Ms-office files(Excel,Ms Word,PowerPoint). These methods will work on the both the binary(.xls, .doc, .ppt) and XML(.xlsx, .docx, .pptx). with the help of the NPOIFSFileSystem & OPCPackage classes in the POI. with these classes the reading and writing into file would be faster. In this i included so many user friendly methods with the help of POI Library.

GitHub

https://github.com/ssirekumar/POIRE
https://github.com/ssirekumar/POIRE/releases

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

rajeev singh

no leída,
28 ago 2015, 3:32:29 a.m.28/8/2015
para Selenium Users
Hi SSire Kumar,


I am new to automation, and have downloaded both standalone and standalone doc and imported into my referenced library, now how can i use this to read a particular cell data of my excel sheet. my excel sheet is imported into eclipse and having under a folder in xlsx extension. i have to read data from row 2, column 3.


Regards,
Rajeev

Jegadeesh mani

no leída,
28 ago 2015, 3:39:17 a.m.28/8/2015
para seleniu...@googlegroups.com
Hi rajeev singh,

please go through the below link..

http://www.guru99.com/creating-keyword-hybrid-frameworks-with-selenium.html

Thanks,
Jegadeesh

chethan kumar

no leída,
20 ene 2016, 2:08:45 a.m.20/1/2016
para Selenium Users
hi Hemapriya Rajendran

please send full code ...login page code ..data takes from excel sheet ..

Thanks 
chethan

Krishnan Mahadevan

no leída,
20 ene 2016, 2:15:40 a.m.20/1/2016
para Selenium Users
Chethan,
What exactly is your query ? Can you please add a bit more context ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

purvang talatiya

no leída,
7 dic 2017, 12:34:03 a.m.7/12/2017
para Selenium Users
Hello Rajendran,

Hope you are doing well,

I want help from you for webdriver, I want a code for multiple email and password can be verified from excel file and give me as well in excel with status column that weather it is pass or fail.

somasekhar patil

no leída,
18 abr 2018, 8:32:19 a.m.18/4/2018
para Selenium Users
Hi ,
I used this code but i m not getting hw to fetch data from Excel file,where exectly we have to make changes plz let me know 
1)I have changed URL and Excel path then what i have to change .



package package1;



import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;


import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class yoda2 {


public static void main(String[] args) { 
// Launch FireFox WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");
WebDriver driver;

driver=new ChromeDriver();
driver.get("http://192.168.1.200:91/");
driver.manage().window().maximize();
// Enter YODA URL 
    

// Enter UserID 
driver.findElement(By.name("userid")).sendKeys("xx3517"); 

 // Enter Password driver.findElement(By.name("password")).sendKeys("123123a"); 

 // Click on Submit button after entering User ID and Password driver.findElement(By.name("btnSubmit")).click(); 

// Click on Remind Me later driver.findElement(By.name("successOK")).click(); 

 try { File file = new File("E:\\MFB_NEW_WS\\new3\\Soma\\Excelfile\\Login_ExcelSheet.xlsx"); 

 FileInputStream iFile = new FileInputStream(file);

 XSSFWorkbook wb = new XSSFWorkbook(iFile);      

XSSFSheet sheet = wb.getSheet("Sheet1"); 

int rowCount = sheet.getLastRowNum();

System.out.println("the no of rows are : " + rowCount);

for (int row=1; row<=rowCount; row++)
{ String location = sheet.getRow(row).getCell(0).getStringCellValue();

 String activity = sheet.getRow(row).getCell(1).getStringCellValue();

 int order=(int) sheet.getRow(row).getCell(2).getNumericCellValue();

 System.out.println(location + " , " + activity + " , " +order );
 }

 iFile.close();

 }

 catch (IOException e) { e.printStackTrace();
 } 

// Click on Search Button on YODA home page 

driver.findElement(By.className("MenuBarItemSubmenu")).click(); 

driver.findElement(By.xpath("//*[text()='Fulfillment Details']")).click();

driver.findElement(By.name("location")).sendKeys(location); 

driver.findElement(By.name("activity")).sendKeys(activity); 

driver.findElement(By.name("orderID")).sendKeys(order); 

driver.findElement(By.id("fulfillment_submit")).click(); } }




Advance Thanks 
Somu




On Monday, January 28, 2013 at 1:13:37 PM UTC+5:30, Hemapriya Rajendran wrote:

somasekhar patil

no leída,
18 abr 2018, 8:40:11 a.m.18/4/2018
para seleniu...@googlegroups.com
Hi 
Please help me out how to fetch the data from excel for login .


Thanks and regards
Somu

Somasekhar Patil



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d1a744a9-a16d-4181-9213-b3da30d0fc30%40googlegroups.com.

Janaka Ramesh

no leída,
13 jun 2019, 6:52:13 a.m.13/6/2019
para Selenium Users
hi ji

if in excel sheet there are some 100-200 records how all these datas can be fetch automatically from the excel . can u please help me with the coding using selenium webdriver
i am new to this plz help me frnds.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos