Details
-
Type: Task
-
Status: Resolved
-
Priority: Major
-
Resolution: Not A Bug
-
Affects Version/s: 2.5.4
-
Fix Version/s: None
-
Component/s: Ant Tasks
-
Labels:None
-
Environment:Windows 7, JDK 1.6.18, JBehave 2.5.4, Selenium Server and Selenium-Java client.
-
Number of attachments :2
Description
Hi,
I'm having an issue with a very basic project using Jbehave and Selenium and hopefully someone can help me out.
I have managed to create a .scenario, LoginScenario.java and LoginSteps.java basic test with Selenium built in to test a login of a website. This is all setup in Eclipse with the correct .jars on the classpath and buildpath, it runs and works correctly. There is also a base.properties file that the test uses to determine the URL to test.
I've been trying to migrate the project into a command line build using an Ant script. I have almost carbon copied the build.xml from the Trader example from the Jbehave website except rather than reading in the dependencies from the pom.xml it copies local JARs into the classpath. Hopefully I have all the Jars I need. I've also left out the reporting stuff as I just want the tests to run firstly.
It fails to instantiate the LoginScenario.java file and further down in the error list is a ClassNotFoundError which makes me think the classpath isn't including the compiled classes even though the output says the compilation has been sucessful and prints out a very long classpath with the Jars in and the path C:\LoginProject\target\classes which is the destdir of the compile target.
I'm sure its just me missing something in the build.xml, I'm sure its not an issue with the Java classes themselves as they work fine in Eclipse when you run LoginScenario.java
Ive attached the project and under /lib there is a list of the JARS I would have in List of JARS.txt, sorry I know this is a bit of a rubbish way of doing things I'm just not particularly familiar with Maven and how to use its functionality.
Many Thanks,
Tom.
-
Hide
- LoginProject.zip
- 15 kB
- Tom Little
-
- LoginProject/.classpath 0.9 kB
- LoginProject/.project 0.4 kB
- LoginProject/.../org.eclipse.jdt.core.prefs 0.6 kB
- LoginProject/base.properties 0.0 kB
- LoginProject/bin/LoginScenario$1.class 2 kB
- LoginProject/bin/LoginScenario.class 1 kB
- LoginProject/bin/LoginSteps$1.class 0.8 kB
- LoginProject/bin/LoginSteps.class 2 kB
- LoginProject/bin/login_scenario.scenario 0.1 kB
- LoginProject/bin/SystemUnderTest.class 2 kB
- LoginProject/build.xml 2 kB
- LoginProject/co.uk.properties 0.0 kB
- LoginProject/EnvironmentVariables.txt 0.5 kB
- LoginProject/es.properties 0.0 kB
- LoginProject/fr.properties 0.0 kB
- LoginProject/it.properties 0.0 kB
- LoginProject/output.txt 18 kB
- LoginProject/pom.xml 0.9 kB
- LoginProject/pt.properties 0.0 kB
- LoginProject/src/LoginScenario.java 2 kB
- LoginProject/src/LoginSteps.java 2 kB
- LoginProject/src/login_scenario.scenario 0.1 kB
- LoginProject/src/SystemUnderTest.java 2 kB
-
Hide
- LoginProject.zip
- 23 kB
- Tom Little
-
- LoginProject/.classpath 0.9 kB
- LoginProject/.project 0.4 kB
- LoginProject/.../org.eclipse.jdt.core.prefs 0.6 kB
- LoginProject/base.properties 0.0 kB
- LoginProject/bin/LoginScenario$1.class 2 kB
- LoginProject/bin/LoginScenario.class 1 kB
- LoginProject/bin/LoginSteps$1.class 0.8 kB
- LoginProject/bin/LoginSteps.class 2 kB
- LoginProject/bin/login_scenario.scenario 0.1 kB
- LoginProject/bin/SystemUnderTest.class 2 kB
- LoginProject/build.xml 5 kB
- LoginProject/co.uk.properties 0.0 kB
- LoginProject/ERROR.bmp 230 kB
- LoginProject/es.properties 0.0 kB
- LoginProject/fr.properties 0.0 kB
- LoginProject/it.properties 0.0 kB
- LoginProject/lib/List of JARS.txt 4 kB
- LoginProject/pt.properties 0.0 kB
- LoginProject/src/LoginScenario.java 2 kB
- LoginProject/src/LoginSteps.java 2 kB
- LoginProject/src/login_scenario.scenario 0.1 kB
- LoginProject/src/SystemUnderTest.java 2 kB
Activity
Hi Mauro,
Thanks for your swift reply, I've configured Maven and created a POM.xml which contains those dependencies. This is now read in by the build.xml as an artifact and all the correct JARs that you mentioned are now copied over into target/lib. I am still getting the same Failed to Instantiate error though. I have attached the new Login Project, if you could run it using the command 'ant' or 'ant -verbose' and let me know if you get my error or whether it passes, I will then know if the code itself is fine and there is an outside element effecting the ClassPath or perhaps some version compatibility issue that is stopping my code from working or whether there is something within the code causing it.
I have done a few things to diagnose the issue further, I've tried running 'ant -noclasspath' which didn't help, I've also created an output.txt which is the verbose output I get when I first run my code, followed by the Failed To Instantiate error and stack trace in the terminal. I've also attached a file EnvironmentVariables.txt which lists all my relevant Environment Variables, you may see something obvious in there.
I realise this now may be out of the scope of help which you offer for JBehave, hopefully you can confirm whether it is an error with my existing code or something outside of this that is causing the issue.
Thanks for the reporting advice, I just want to get my class to run first then I'll sort all that out after.
Also I thought it was worth mentioning what appeared in my /target folder. I have two folders /target/lib with all the Jars you mentioned and I have /target/classes with LoginSteps.class, LoginSteps$1.class, LoginScenario.class, LoginScenario$1.class, SystemUndertest.class and login_scenario.scenario.
Also I wonder if the .classpath file that is left over from Eclipse may be affecting it somehow, I've left it in for you incase you think it might.
Thanks to anyone who can shed some light and thank you Mauro for the help I've recieved so far.
Tom.
Field | Original Value | New Value |
---|---|---|
Attachment | LoginProject.zip [ 49195 ] |
Your updated project works fine for me (Mac JDK 1.6). Yes, I would strongly advice to always to a clean when building, as you want to ensure that the build is consistently compiled from source and not picking up artifacts from other sources. Please try 'ant clean build'.
Thanks Mauro, I've tried any clean build with no luck. I think the next thing I will try is running the code on a virtual windows machine to see if this helps. I'll update you if I have any luck.
Thanks again.
Hi Mauro,
I've installed ant 1.8.1 (with the antlibs), Maven 2.2.1, JDK 1.6.0_18, and downloaded JBehave 2.5 on a Windows Vista machine and I've come across the exact same problem. Maybe this means there is a Windows issue here? The process of installation and setup were;
-Download ant and extract to C drive root, set ANT_HOME, Path and JAVA_HOME using the Windows GUI to values C:\apache-ant-1.8.1, C:\apache-ant-1.8.1\bin, C:\Program Files\Java\jdk1.6.0_18 respectively. Run the command : ant -f fetch.xml -Ddest=system from the C:\apache-ant-1.8.1 directory.
-Download maven and extract to C drive root, set Path to C:\apache-maven-2.2.1\bin.
-Download JBehave and extract to the C drive root, set Path to C:\jbehave-2.5\lib.
-Run 'ant clean build' from cmd in directory C:\LoginProject.
I'm not sure if there is anymore you can do for me but if you can think of anything that would be brilliant if not then thanks for the help provided.
Many thanks,
Tom.
I've verified that LoginProject works on Windows (XP) too. Using Ant 1.7 and 1.8 and JDK 1.6.
I find it hard to believe that it's a OS issue.
Can you try unzipping the latest version of LoginProject.zip into a separate clean dir, ensuring you have Maven Ant Tasks in the your $ANT_HOME/lib, and running
ant clean build?
Hi Mauro,
I have done that with no luck. I have however managed to get the tests to work on an XP virtual machine, a Vista virtual machine and my home unix machine. I am now trying on a Windows 7 virtual machine. There seems to be some setting on my local Windows 7 and the other Vista local machine that I tested it on, maybe a permissions issue, that is stopping the class loader from finding the class file. I have checked that the env variables are identical as are the versions. I'll update again on how the Windows 7 Virtual PC does. Quite baffling and frustrating at this point.
You're definately right that it's not an OS compatibility issue. Thanks for all the help.
Tom.
After 4 days of troubleshooting the issue is finally resolved. After getting past the ClassNotFoundError on a Windows 7 virtual machine I then inspected my machine to find out the fault. I found an earlier version of ant (1.7.1) in my repository and deleted all traces of it, including the ANT_HOME and apache-ant-1.8.1 directory that were there currently. I also found in my add/remove programs a Java Update 20 file, presumably left over from an old installation of JRE. This refused to be removed from the Add/Remove list, I ended up having to use Windows Install Clean Up utility to get rid of it. I believe this was affecting the JVM or classpath somehow.
After doing all that and rebooting I then did a fresh install of JDK 1.6.0_20 and apache-ant-1.8.1, set the ANT_HOME environment variable and the error no longer appeared. After slightly rejigging the pom.xml to get the latest jbehave core dependency and adding a few more jars to the lib folder the LoginScenario now runs from command line with 'ant clean build' and from Eclipse as before.
Thank you Mauro for all you help and sorry that this issue wasn't related to Jbehave, hopefully if there are any more complaints of this nature this post may help troubleshoot as all old or corrupted Java Updates or installs and ant versions should be wiped clean first.
Thanks again,
Tom.
No problem, Tom. Glad we could help to sort out the issue.
Status | Open [ 1 ] | Resolved [ 5 ] |
Resolution | Not A Bug [ 6 ] |
Tom, your problem seems to be a classpath one. I could not reproduce it because I did you manually download all the jars in the list. Instead I used transitive dependencies from the following 3 dependencies:
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-ant</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.jbehave.web</groupId>
<artifactId>jbehave-web-selenium</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium.server</groupId>
<artifactId>selenium-server</artifactId>
<version>1.0.1</version>
</dependency>
which produced the following list of jars:
ant-1.7.1.jar
ant-launcher-1.7.1.jar
bcprov-jdk15-135.jar
commons-codec-1.3.jar
commons-collections-3.2.1.jar
commons-io-1.4.jar
commons-lang-2.4.jar
commons-logging-1.0.4.jar
freemarker-2.3.16.jar
hamcrest-all-1.1.jar
jbehave-ant-2.5.6.jar
jbehave-core-2.5.6.jar
jbehave-web-selenium-2.1.6.jar
junit-dep-4.4.jar
org.mortbay.jetty-5.1.12.jar
selenium-core-1.0.1.jar
selenium-java-client-driver-1.0.1.jar
selenium-server-1.0.1.jar
selenium-server-coreless-1.0.1.jar
servlet-api-2.4.ja
Note that you can fetch these dependencies via Maven or via Ivy or any other tools that supports transitive dependencies.
With these jars I was able to run the scenario:
run-scenarios:
[scenarioRunner] Running scenario LoginScenario
[scenarioRunner] java.io.FileNotFoundException: selenium/epson/results.html (No such file or directory)
[scenarioRunner] at java.io.FileOutputStream.open(Native Method)
[scenarioRunner] at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
[scenarioRunner] at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
[scenarioRunner] at LoginScenario$1.forReportingScenarios(LoginScenario.java:28)
[scenarioRunner] at org.jbehave.scenario.ScenarioRunner.run(ScenarioRunner.java:53)
[scenarioRunner] at org.jbehave.scenario.ScenarioRunner.run(ScenarioRunner.java:42)
[scenarioRunner] at org.jbehave.scenario.AbstractScenario.runScenario(AbstractScenario.java:75)
[scenarioRunner] at org.jbehave.scenario.JUnitScenario.runScenario(JUnitScenario.java:54)
[scenarioRunner] at org.jbehave.ant.ScenarioRunnerTask.execute(ScenarioRunnerTask.java:35)
[scenarioRunner] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[scenarioRunner] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[scenarioRunner] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[scenarioRunner] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[scenarioRunner] at java.lang.reflect.Method.invoke(Method.java:597)
[scenarioRunner] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[scenarioRunner] at org.apache.tools.ant.Task.perform(Task.java:348)
[scenarioRunner] at org.apache.tools.ant.Target.execute(Target.java:357)
[scenarioRunner] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[scenarioRunner] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[scenarioRunner] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[scenarioRunner] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[scenarioRunner] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[scenarioRunner] at org.apache.tools.ant.Main.runBuild(Main.java:758)
[scenarioRunner] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[scenarioRunner] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[scenarioRunner] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[scenarioRunner]
[scenarioRunner] (login_scenario.scenario)
[scenarioRunner] Scenario:
[scenarioRunner] 10:09:59.198 INFO - Java: Apple Inc. 14.3-b01-101
[scenarioRunner] 10:09:59.199 INFO - OS: Mac OS X 10.5.8 x86_64
[scenarioRunner] 10:09:59.204 INFO - vnull [null], with Core v@VERSION@ [@REVISION@]
[scenarioRunner] 10:09:59.289 INFO - Version Jetty/5.1.12
[scenarioRunner] 10:09:59.291 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
[scenarioRunner] 10:09:59.292 INFO - Started HttpContext[/selenium-server,/selenium-server]
[scenarioRunner] 10:09:59.292 INFO - Started HttpContext[/,/]
[scenarioRunner] 10:09:59.301 INFO - Started SocketListener on 0.0.0.0:4444
[scenarioRunner] 10:09:59.301 INFO - Started org.mortbay.jetty.Server@4090c06f
[scenarioRunner] 10:09:59.375 INFO - Checking Resource aliases
[scenarioRunner] 10:09:59.381 INFO - Command request: getNewBrowserSession[*firefox, http://www.epson.co.uk, ] on session null
[scenarioRunner] 10:09:59.383 INFO - creating new remote session
[scenarioRunner] 10:09:59.520 INFO - Allocated session 81090682b8b74701bfd41ffae62b9f1a for http://www.epson.co.uk, launching...
[scenarioRunner] 10:09:59.577 INFO - Preparing Firefox profile...
[scenarioRunner] 10:10:10.999 INFO - Launching Firefox...
[scenarioRunner] Failure in running scenarios:
[scenarioRunner] LoginScenario: Method Method.startSystem1, annotated with BeforeScenario failed.
Note that it fails to write report, because the reporter is misconfigured. Check the documentation on how to configure it properly:
http://jbehave.org/reference/stable/reports.html