1

I am trying to run a Selenium Web-Driver TestNG script in Eclipse. I am getting the error shown below.

TestNG run error

I have tried changing preferences, checking/unchecking "use project testNG jar", messing with the build path, and recreating the project. Can anyone please help me solve this problem so I can continue creating awesome scripts using TestNG?

James4701
  • 63
  • 1
  • 7
  • Usually the message in red, this case ending in `ClassLoader.loadClass` is more informative than the red crosses... But it looks like a version conflicts... check your gradle conf – Danielson Jul 29 '15 at 16:14
  • Gradle conf? What is that? – James4701 Jul 29 '15 at 17:06
  • My bad, misread Groovy for Gradle (off-topic, something to look into (or maven), reason for me to stick to Java)... But... Can you run it again, kill the pop-ups, scroll the red log upwards, and check to see whether you've got: `Unsupported major.minor version 51.0`? – Danielson Jul 29 '15 at 17:17
  • "java.lang.UnsupportedClassVersionError: org/testng/TestNG : Unsupported major.minor version 51.0" So yes I have that (sorry it won't let me use block quotes for some reason). – James4701 Jul 29 '15 at 17:34
  • See answer, I'm always a bit unsure on the error of wrong version, where the version is referring to, the lib of your version... – Danielson Jul 29 '15 at 17:43

1 Answers1

0

Your problem, based on Unsupported major.minor version 51.0 is wrong Java version. The library you are using is compiled in one version, and you are using a different one (most probably, or definitely) you are using a lower version.

Version 51.0 refers to Java 7. I'd say the library you are using is Java 7 and yours is lower... To change this, go to:

Window -> Preferences -> Java -> Compiler 

And set the Compiler compliance level higher, at least 1.7 (i.e. Java 7). If that's not an option, install a newer Java JDK (pref 1.8, that can, if you wish, also compile to Java 7).

Unsupported major.minor version 5{1,2,..}.0 (copied from https://stackoverflow.com/a/11432195/928952)

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

A more elaborative explanation of updating the JDK Eclipse is using:

project -> properties -> java build path-> Add Library -> JRE System Library-> Installed JREs -> Add(unless jdk* is already in the list, then select that and go to next post -> standard VM -> Directory button -> browse to the location where you installed the JDK. Inside that directory you see a couple of folders, including bin and lib.
Make sure you select the parent directory of them. Click OK. You'll then see a list of .jars under JRE system libraries (must!) -> hit finish. Select the checkbox next to jdk1.8*. Press OK then finish.
Now you've got the right Java version in the Build Path... Now we have to make sure that becomes the compiler Now we're back at the properties, Go to Java Compiler, make sure enable project specific settings is turned off. Click Configure Workspace Settings.... set the Compliance level: 1.8 -> apply (you get a message on compiler settings changed rebuild blablabla hit yes) then ok, then ok again...

Eclipse is given strange error on not finding libs

You can try deleting the .project and .classpath files in the root of your project. Delete the project from workspace (don't delete your source, backup first)... then reimport the project... might be that eclipse has configured something that doesn't exist anymore... helps me fix some dubious errors...

Community
  • 1
  • 1
Danielson
  • 2,605
  • 2
  • 28
  • 51
  • My Compiler compliance level was set at 1.6 and it says the version of my installed JDK is also 1.6. Is this the problem? Should I update my JDK? – James4701 Jul 29 '15 at 18:11
  • When I go to my Start Menu and search for "Java" and click "About Java", it says I have version 1.7. Why does Eclipse say I have JDK 1.6 installed? – James4701 Jul 29 '15 at 18:14
  • Does it say `Use compliance from execution environment 'JavaSE-1.6``or 1.7? If 1.6 go to `Java Build Path` -> `add library` if the workspace is wrong/old browse `Execution environment` first, if it's not in there, go to `Installed JREs` -> `Add` browse to the location your `JDK` (not JRE!) is installed. Othewise, select 1.7 (or 1.8) from the dropdown button – Danielson Jul 29 '15 at 18:34
  • I didn't notice your first comment. If you can first the 1.7 you can use that. Although I recommend downloading 1.8 JDK anyways... Because it has some nice features - IMHO. See (when you finished this of course ;-)) http://www.infoq.com/articles/Java-8-Quiet-Features (I saw I don't know all of them o_O, better start learning :-) ) – Danielson Jul 29 '15 at 18:44
  • Where would I see Use compliance from execution environment 'JavaSE-1.6`? Also when I go to "Installed JREs" and click "Add" and "Execution Environment Description", I go to my Java folder but cannot find a file with a .ee extension. Where should I be pointing this? – James4701 Jul 29 '15 at 18:49
  • The basedir is the directory where you also see bin and lib... window preferences java then build path – Danielson Jul 29 '15 at 18:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84608/discussion-between-james4701-and-danielson). – James4701 Jul 29 '15 at 18:52