0

I have Eclipse Java EE IDE Helios Service Release 2 Build id: 20110218-0911; I am trying use them with SeleniumRC and when I compile the code appears the next error message:

  • Type mismatch: cannot convert from DataProviderSites to annotation
  • The attribute DataProviderSites is undefined for the annotation type Test

However, when I validate the code, is visualized "the validation completed with no errors or warnings"

The Code in DataProviderSites.java is:

package script;

import org.junit.Test;                   
import junit.framework.TestCase;

import com.thoughtworks.selenium.SeleneseTestBase;
import org.junit.AfterClass;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;
import java.io.File;
import jxl.*; 


public class DataProviderSites extends SeleneseTestBase {

    @BeforeClass
    public void setUp() throws Exception {
        SeleniumServer seleniumserver=new SeleniumServer();
        seleniumserver.boot();
        seleniumserver.start();
        setUp("http://www.examinator.ws/", "*firefox");
        selenium.open("/");
        selenium.windowMaximize();
        selenium.windowFocus();
    }


    @DataProviderSites
    (name = "DPS1")
    public Object[][] createData1() throws Exception{
        Object[][] retObjArr=getTableArray("test\\Resources\\Data\\sitios.xls",
                "DataPool", "TestData");
        return(retObjArr);
    }


    @Test(DataProviderSites = "DPS1")

        public void testDataProviderSites(String nombre) throws Exception {    
        selenium.type("sitio", nombre);
        if (selenium.isTextPresent("examinator"))
            selenium.click("xpath=/descendant::button[@type='submit']");

        else

        selenium.waitForPageToLoad("30000");

        selenium.click("xpath=/descendant::a[text()='"+nombre+"']");

        }

    @AfterClass
    public void tearDown(){
        selenium.close();
        selenium.stop();
    } 

    public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{
        String[][] tabArray=null;

            Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
            Sheet sheet = workbook.getSheet(sheetName); 
            int startRow,startCol, endRow, endCol,ci,cj;
            Cell tableStart=sheet.findCell(tableName);
            startRow=tableStart.getRow();
            startCol=tableStart.getColumn();

            Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);                

            endRow=tableEnd.getRow();
            endCol=tableEnd.getColumn();
            System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                    "startCol="+startCol+", endCol="+endCol);
            tabArray=new String[endRow-startRow-1][endCol-startCol-1];
            ci=0;

            for (int i=startRow+1;i<endRow;i++,ci++){
                cj=0;
                for (int j=startCol+1;j<endCol;j++,cj++){
                    tabArray[ci][cj]=sheet.getCell(j,i).getContents();
                }
            }


        return(tabArray);
    }
}

Anybody have a idea to resolve this?

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
TesteoHG
  • 1
  • 1
  • 3

2 Answers2

2

Just click the error and click "Convert to TestNG(Annotations)".

Solution List

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
0

Validation does not check the logic like it does not check for syntax of code. But when we compile the program it will check for syntax so you got type cast exception.

Validation success does not mean program is correct.

I think annotations(@Test(DataProviderSites = "DPS1"), @DataProviderSites (name = "DPS1")) causes the exception.

Balakrishna
  • 166
  • 2
  • 13
  • is clear that the error is into this annotations, but I still don't know how resolve it...if I delete this annotations, how indicate the values to take? – TesteoHG Jan 07 '13 at 14:09
  • Well, trying I found a quick fix to my question: delete "@DataProviderSites (name = "DPS1")" on the code and only I leave "@Test", with this no occurs errors in my environment. Thanks at all... – TesteoHG Jan 07 '13 at 14:54