1

I have created test script for the upload file. In the script, I have written the code for upload different kind of file and check the result.

But i have confusion about passing multiple data to the excel.

I'm using below code:

@DataProvider(name = "Authentication2")
public static Object[][] credential2()
{
    List<String> invaliddatalist=Arrays.asList(filepathinvalid,filepathinvalid2);
    int len=invaliddatalist.size();
    Object[][] objArray = new Object[len][];
        for(int i=0;i<len;i++)
        {
            objArray[i] = new Object[1];
            objArray[i][0] = invaliddatalist.get(i);

        }
    return objArray;            
}

public void Wrongdata(String[] appdata) throws InterruptedException 
{
        // TODO Auto-generated method stub  
        // List<String> invaliddataList = Arrays.asList(filepathinvalid,filepathinvalid2); 
        Thread.sleep(2000);
        WebElement choosefile=m1.getDriver().findElement(By.name("files"));

        for(int i=0;i<appdata.length;i++)
        {
             choosefile.sendKeys(appdata[i]);
        }

        WebElement upload=m1.getDriver().findElement(By.id("register-button"));
        upload.submit();
        WebElement dialog=m1.getDriver().findElement(By.id("dialog-notifications-error"));
        String errforinvaliddata=dialog.getText();
        System.out.println("err for invalid data->"+errforinvaliddata);
        String msg="Only pdf files are allowed.";

        if(msg.equals(errforinvaliddata))
        {
            for(int i=0;i<appdata.length;i++)
            {
                uploadinfo.put("i", new Object[] { i,appdata[i],"Fail" });
            }

            Assert.assertTrue(false);
            m1.getDriver().navigate().back();

        }
        else
        {
            String url=m1.getDriver().getCurrentUrl();

            System.out.println("errorurl->"+url);
            String exppath="https://veridocglobal.com/errorpage.htm?aspxerrorpath=/Document/Create";

            if(url.equals(exppath))
            {
                //uploadinfo.put("3", new Object[] { "3",p1,"error" });
                Assert.assertTrue(false);
                m1.getDriver().navigate().back();

            }       
        }       

    }

@AfterClass
public void afterclassmethod() throws IOException
{

    Set < String > keyid = uploadinfo.keySet();
    int rowid = 0;

    for (String key : keyid) 
    {
             HSSFRow row = sheet.createRow(rowid++);
             Object [] objectArr = uploadinfo.get(key);
             int cellid = 0;

             for (Object obj : objectArr) 
             {
                Cell cell = row.createCell(cellid++);
                cell.setCellValue((String)obj);
             }
     }
     FileOutputStream out = new FileOutputStream(new File("path"));
     workbook1.write(out);
     out.close();
     System.out.println("xlsx written successfully");
}
2
  • What are the data you are going to pass excel? – Sachintha Nov 2 '17 at 17:48
  • which i have pass in array – Rutvi Soni Nov 3 '17 at 4:56
0
@DataProvider(name = "Authentication2")
      public static Object[][] credentials2() {

            return new Object[][] { {"3","/home/rutvi/Pictures/download.jpg"},{"4","/home/rutvi/Downloads/Standards.docx"},{"5","/home/rutvi/Music/Shree_Hanuman_Chalisa-Hariharan[www.Mp3MaD.Com].mp3"}};

      }
    @Test(dataProvider = "Authentication2",priority=2)

    public void Wrongdata(String id,String p1) throws InterruptedException {
        // TODO Auto-generated method stub

    //   List<String> invaliddataList = Arrays.asList(filepathinvalid,filepathinvalid2);

        Thread.sleep(2000);

        WebElement choosefile=m1.getDriver().findElement(By.name("files"));

        choosefile.sendKeys(p1);


        /*for(int i=0;i<appdata.length;i++)
        {
         choosefile.sendKeys(appdata[i]);
        }
        */
             WebElement upload=m1.getDriver().findElement(By.id("register-button"));
             upload.submit();

                WebElement dialog=m1.getDriver().findElement(By.id("dialog-notifications-error"));
                String errforinvaliddata=dialog.getText();


                System.out.println("err for invalid data->"+errforinvaliddata);

                String msg="Only pdf files are allowed.";


                if(msg.equals(errforinvaliddata))
                {

                    /*for(int i=0;i<appdata.length;i++)
                    {
                        uploadinfo.put("i", new Object[] { i,appdata[i],"Fail" });
                    }
                    */
                    uploadinfo.put(id, new Object[] {id,p1,"faill" });
                    Assert.assertFalse(true);




                    m1.getDriver().navigate().back();

                }
                else
                {
                    String url=m1.getDriver().getCurrentUrl();

                    System.out.println("errorurl->"+url);
                    String exppath="https://veridocglobal.com/errorpage.htm?aspxerrorpath=/Document/Create";

                    if(url.equals(exppath))
                    {

                        Assert.assertTrue(false);
                        uploadinfo.put(id, new Object[] { id,p1,"error" });
                        m1.getDriver().navigate().back();

                    }       
                }       

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.