@DataProvider(name = "Authentication1")
    public static Object[][] credentials1()
    {

        return new Object[][] { 
                                { "12234", " 6576","gfdgfdg"," dfg","gfd "},
                                {"&^*&^","&*^*&^","soni.rutvigmail.com","ghgfh","ghfghgfh"},
                                {"Rutvi","Soni","[email protected]","123456","123456"},
                                {"Rutvi","Soni","[email protected]","123456","123456"},
                                {"Rutvi","Soni","[email protected]","123456","123456"},
                                {"Rutvi","Soni","[email protected]","123456","123456"},
                                {"Rutvi","Soni","[email protected]","123456","123456"},
                                {"Rutvi","Soni","soni.rutvi%gmail.com","123456","123456"},
                                {"Rutvi","Soni","soni#[email protected]","123456","123456"},
                            };

    }
    @Test(dataProvider = "Authentication1" )
    public void invaliddata(String fname, String lname,String email,String pass,String cpass)
    {
        driver.get("http://canvaswish.7bits.in/canvaswish/register");

        WebElement firstname = driver.findElement(By.id("FirstName"));
        firstname.clear();
        firstname.sendKeys(fname);

        WebElement lastname = driver.findElement(By.id("LastName"));
        lastname.clear();
        lastname.sendKeys(lname);

        WebElement mail = driver.findElement(By.id("Email"));
        mail.clear();
        mail.sendKeys(email);

        WebElement password = driver.findElement(By.id("Password"));
        password .clear();
        password .sendKeys(pass);

        WebElement conpassword = driver.findElement(By.id("ConfirmPassword"));
        conpassword .clear();
        conpassword.sendKeys(cpass);

        WebElement register = driver.findElement(By.id("register-button"));
        register.click();

        String geturl=driver.getCurrentUrl();
        System.out.println("geturl->"+geturl);

        if(geturl.equals(expectedurl))
        {
            Assert.assertTrue(true);
            testresultdata.put("3", new Object[] { 2d,fname,lname, email, pass,cpass, expectedurl, geturl, "Pass" });

        }
        else
        {
            testresultdata.put("3", new Object[] { 2d,fname,lname, email, pass,cpass, expectedurl, geturl, "Fail" });
            Assert.assertTrue(false);

        }

    }

@AfterClass
    public void setupAfterclass() throws IOException
    {
        Set<String> keyset = testresultdata.keySet();
        int rownum = 0;

        for (String key : keyset)
        {
            Row row = sheet.createRow(rownum++);
            Object[] objArr = testresultdata.get(key);
            int cellnum = 0;


            for (Object obj : objArr)
            {
                Cell cell = row.createCell(cellnum++);

                if (obj instanceof Date)
                    cell.setCellValue((Date) obj);
                else if (obj instanceof Boolean)
                    cell.setCellValue((Boolean) obj);
                else if (obj instanceof String)
                {
                        if(obj.equals("Pass"))
                        {
                            font.setColor(HSSFColor.GREEN.index);
                            style.setFont(font);
                            cell.setCellStyle(style);
                            cell.setCellValue((String) obj);   
                        }
                        else if(obj.equals("Fail"))
                        {
                            font.setColor(HSSFColor.RED.index);
                            style.setFont(font);
                            cell.setCellStyle(style);
                            cell.setCellValue((String) obj);
                        }

                        {

                            style.setFont(font);  
                            cell.setCellValue((String) obj);
                        }
                }
                else if (obj instanceof Double)
                    cell.setCellValue((Double) obj);
            }
        }
        try
        {
            FileOutputStream out = new FileOutputStream(new File("E:\Register.xls"));
            workbook1.write(out);
            out.close();
        //  System.out.println(" written successfully..");
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }   

I want to multiple test cases in excel sheet but now problem is that last is onle in sheet



Source link https://sqa.stackexchange.com/questions/25753/how-to-display-data-in-excel-through-data-

LEAVE A REPLY

Please enter your comment!
Please enter your name here