method errors...

110 views
Skip to first unread message

Brent Magstadt

unread,
Sep 10, 2015, 8:10:33 PM9/10/15
to testng-users
Hi everyone. 
I'm nearing completion on getting my first framework up and running in Selenium, TestNG, and java. I'm getting an error on the actual test class (which as you can see I am starting out as pretty basic). The error is represented by the red underlining (in eclipse) under the first and second public void methods. Specifically underlined are 'setup(@Optional' and 'drivertype'. In the second method call the 'testStep1' is underlined. 

When hovering, these errors read as follows:

    (setup(@Optional):  void is an invalid type for the variable setup

    (drivertype):  Syntax error, insert ";" to complete LocalVariableDeclarationStatement

    (testStep1()):  Syntax error on token "testStep1", AnnotationName expected after this token

Here's the code:

public class testLoginsUser extends abstractAutomatedTest
{
public static void main(String[] args)
{
withmePortalPage portal;
@Parameters({ "driverType" })
@BeforeClass
public void setUp(@Optional("CHROME") String driverType) throws Exception
{
super.beforeClass(driverType);
portal = new wmPortalPage(driver, testResources); 
}
//  BEGIN TEST STEPS
  
@Test(groups = { "LoginUser" }, alwaysRun = true)
public void testStep1() throws Exception
{
// Step 1 - Login 
portal.login(pageVariableData.loginUsername, pageVariableData.loginPassword); 
String yoTitle;
yoTitle = driver.getTitle();
System.out.println(yoTitle);
}
}
}

When attempting to run this code the errors read:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
void is an invalid type for the variable setUp
Syntax error on token "(", ; expected
The annotation @Optional is disallowed for this location
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
Syntax error on token "testStep1", AnnotationName expected after this token
Syntax error, insert ")" to complete NormalAnnotation
Syntax error, insert "[ ]" to complete Dimension
Syntax error, insert ";" to complete LocalVariableDeclarationStatement

at com.wm.tests.logins.testLoginsUser.main(testLoginsUser.java:30)

I get that void is an invalid type, but honestly I'm not sure what type to use, and have tried a couple. And... that's probably not the problem, right?
I'm trying to get the framework solid before I start coding out tests, so this is pretty basic, as a test. Any advice on these errors would be very appreciated. 
Thanks in advance!
 -- brent

Mrunal Gosar

unread,
Sep 12, 2015, 12:43:06 PM9/12/15
to testng-users
hey you cannot have method inside method in java.. you need to clear ur java concepts first. you have setup and testStep method in main method which is wrong.
Reply all
Reply to author
Forward
0 new messages