'The annotaion @Test is disallowed for this location'!

Hello guys,

i am in need of urgent help,
This is my code so far

package com.appium.facebook.androiduiselector;

import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

public class FacebookLoginTest {

@Test

DesiredCapabilities capabilities = new DesiredCapabilities();
		(Will write the code further here..)

}

In above code error is shown as "The annotation @Test is disallowed for this location "

where i am wrong,what I am missing,please somebody guide

Thanks

Jennifer

You must specify like below:

@Test
public class FacebookLoginTest {

DesiredCapabilities capabilities = new DesiredCapabilities();
		(Will write the code further here..)
}

Hello ,

I placed @Test before public class FacebookLoginTest exactly as you mentioned
But still the error is displayed on @Test as The annotation @Test is disallowed for this location

Somewhere its related to junit jar files i guess, can you provide some other solution?

If you are going to use this annotation, you must import junit.jar or tesng.jar

In this situation, i suggest you to select tesng instead of junit to run your tests.

Create a maven project in Eclipse and add below dependencies on pom.xml

<dependency>
	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>LATEST</version>
</dependency>
<dependency>
	<groupId>org.testng</groupId>
	<artifactId>testng</artifactId>
	<version>6.9.6</version>
</dependency>

If you are going to test mobile, then you need to add appium as well.

<dependency>
			<groupId>io.appium</groupId>
			<artifactId>java-client</artifactId>
			<version>3.2.0</version>
		</dependency>

Then you can use @Test annotation in your tests.

please refer the screenshots.

That stil didnt solved the problem .same error i am getting… :confused:

Could you please post your code and error log in here ?

testNG @Test annotation can be applied only to a method /class but u r applying it to code statement …

package com.appium.facebook.androiduiselector;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

public class FacebookLoginTest {
@Test
public void setUP() {
DesiredCapabilities capabilities = new DesiredCapabilities();
(Will write the code further here…)
}
}

Thanks guys for suggestion,although I have removed all the dependencies and installed eclipse recofiured it again,if i encounter this same issue I will post here

The @Test annotation is always must placed in between class and method, It should declare the before the method. You want to take the method them put the @Test annotation without method the class annotation is not accepted.

This will do it! Because @Test annotation requires a method declaration to be followed right after it.