Selenium Test script works fine on eclipse but not from Jenkins or command lin

Saleej
Messages : 43
Inscription : jeu. janv. 29, 2015 4:50 am

Selenium Test script works fine on eclipse but not from Jenkins or command lin

Message par Saleej »

I am new to Squash Ta and when I tried to follow tutorial on the site to test sample web application with Squash TA and Selenium I ran into following error when i executed it from Jenkins and command line prompt on windows.

[ERROR] org.squashtest.ta.backbone.tools.ReflectionUtils - Test Automation Engine error (non SUT) : method 'convert' from engine component of class 'org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle' with argument 'org.squashtest.ta.framework.components.FileResource' has thrown an exception.
java.lang.NullPointerException
at org.squashtest.ta.plugin.commons.library.java.CompilerConnector.compile(CompilerConnector.java:103)
at org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle.convert(FileToJavaCodeBundle.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.squashtest.ta.backbone.tools.ReflectionUtils.invoke(ReflectionUtils.java:253)
at org.squashtest.ta.backbone.engine.wrapper.ResourceConverterHandler.convert(ResourceConverterHandler.java:103)
at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.applyConverter(DefaultConvertResourceRunner.java:130)
at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.convertResource(DefaultConvertResourceRunner.java:94)
at org.squashtest.ta.backbone.engine.instructionrunner.DefaultConvertResourceRunner.doRun(DefaultConvertResourceRunner.java:54)
at org.squashtest.ta.backbone.engine.instructionrunner.AbstractDefaultInstructionRunner.run(AbstractDefaultInstructionRunner.java:70)
at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runPhase(TestRunnerImpl.java:158)
at org.squashtest.ta.backbone.engine.impl.TestRunnerImpl.runTest(TestRunnerImpl.java:122)
at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.runAllTests(EcosystemRunnerImpl.java:183)
at org.squashtest.ta.backbone.engine.impl.EcosystemRunnerImpl.run(EcosystemRunnerImpl.java:98)
at org.squashtest.ta.backbone.engine.impl.SuiteRunnerImpl.execute(SuiteRunnerImpl.java:68)
at org.squashtest.ta.backbone.engine.impl.EngineImpl.execute(EngineImpl.java:64)
at org.squashtest.ta.maven.SquashTAMojo.executeImpl(SquashTAMojo.java:212)
at org.squashtest.ta.maven.AbstractSquashTaMojo.execute(AbstractSquashTaMojo.java:197)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:136)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:71)
at hudson.remoting.UserRequest.perform(UserRequest.java:121)
at hudson.remoting.UserRequest.perform(UserRequest.java:49)
at hudson.remoting.Request$2.run(Request.java:324)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
[ERROR] org.squashtest.ta.backbone.engine.impl.TestRunnerImpl - The execution raised an error in the TEST phase of the TA script 'PetStoreSeleniumTest.ta' with the message: 'Test Automation Engine error (non SUT) : method 'convert' from engine component of class 'org.squashtest.ta.plugin.commons.converter.FileToJavaCodeBundle' with argument 'org.squashtest.ta.framework.components.FileResource' has thrown an exception.'.
Which seems to be generic error thrown by squash TA whenever the test script fails. Have seen similar error when the test failed in eclipse for firefox driver

One thing to note is that on executing the script using chrome driver wherein i set the driver path in the script, in the console I can see below statement

Starting ChromeDriver 2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29) on port 55057
Only local connections are allowed.
Similar sort of message when referring to IE drivers as well

But on running the same job in jenkins or command line on windows, similar message not seen and the test fails at the same point in the console wherein I can see the above message related to "Only local connections are allowed"

Test Script:

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class Test1{
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();

@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new ChromeDriver();
//driver = new FirefoxDriver();
baseUrl = "http://localhost:8080/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void testPetStoreSelenium() throws Exception {
driver.get(baseUrl);
driver.findElement(By.linkText("Enter the Store")).click();
driver.findElement(By.xpath("//tr[5]/td/a/img")).click();
driver.findElement(By.xpath("//tr[3]/td/b/a/font")).click();
driver.findElement(By.xpath("//tr[3]/td[5]/a/img")).click();
driver.findElement(By.xpath("//td[2]/center/a/img")).click();
driver.findElement(By.xpath("//center[2]/a/img")).click();
driver.findElement(By.name("username")).clear();
driver.findElement(By.name("username")).sendKeys("j2ee");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("j2ee");
driver.findElement(By.name("update")).click();
driver.findElement(By.cssSelector("p > input[type=\"image\"]")).click();
driver.findElement(By.xpath("//center[3]/a/img")).click();
}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}

}

private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}

private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
Could you please advice whats wrong with the script as it works fine on SQUASH TA eclipse?

Please note that the driver path set in the setproperty is valid. Also i tried running script using firefox and IE as well but that too failed from cmd

If I can get this script running and TM-TA link working, this seems to be promising tool as far as I can see
Avatar de l’utilisateur
bfranchet
Messages : 142
Inscription : jeu. nov. 22, 2012 1:36 pm

Selenium Test script works fine on eclipse but not from Jenkins or command lin

Message par bfranchet »

Hello,

Could you give us the content of your .ta script and the tree of your TA resource directory which contains your selenium sources

Regards
Saleej
Messages : 43
Inscription : jeu. janv. 29, 2015 4:50 am

Selenium Test script works fine on eclipse but not from Jenkins or command lin

Message par Saleej »

Content of PetStoreSeleniumTest.ta script

SETUP :

TEST :
# EXECUTE_SELENIUM2 selenium WITH MAIN CLASS Test1

TEARDOWN :

-----------------------------------------------------------------------------------------------------

Please refer to attached screenshot for tree heirarchy for resources folder / rather the project



[attachment=216]SquashProject-Treeheirarchy.png[/attachment]
Pièces jointes
SquashProject-Treeheirarchy.png
SquashProject-Treeheirarchy.png (57.03 Kio) Consulté 3674 fois
Avatar de l’utilisateur
bfranchet
Messages : 142
Inscription : jeu. nov. 22, 2012 1:36 pm

Selenium Test script works fine on eclipse but not from Jenkins or command lin

Message par bfranchet »

Hello

I see nothing bad in what you send.
From what I see in your log, your test failed while it tries to compile the java sources.

Could you verify that your JAVA_HOME environment variable point to a java jdk and not to a jre ?

Regards
Saleej
Messages : 43
Inscription : jeu. janv. 29, 2015 4:50 am

Selenium Test script works fine on eclipse but not from Jenkins or command lin

Message par Saleej »

Thanks.. Changing the environment variable to jdk resolved the issue. I am successfully able to run the test using Jenkins as well as Command line.

On positive note, Final thing I am stuck with is display of test scripts within job in Test cases added to Squash TM. As this thread is not related to same, will add separate one for the issue with it

Thanks for your help and quick response. Much appreciated
Répondre

Revenir à « SKF »