I'm using JUnit and Selenium2 to test my application. I execute the tests using Maven with the surefire plugin running in Jenkins. The test where fine some weeks and I added more and more tests and now the tests fails with this message:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.11:test (default-test) on project guitest: Failure or timeout
...
Process leaked file descriptors
I first thought I'm just leave files open in my code, for example when taking screenshots using the WebDriver (and apache commons IO to copy them):
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destFile = new File(...);
FileUtils.copyFile(scrFile, destFile);
But the problem persists even after removing the screenshot recording.
Do you guys have any pointers what's wrong here and/or how to tackle this problem?
EDIT:
I've implemented a WebdriverPool, to reuse WebDrivers / browser instances. I use a shutdown hook to close all open instances when the test has finished:
Runtime.getRuntime().addShutdownHook(new Thread(){
#Override
public void run(){
for (WebDriver driver : drivers.values())
driver.close();
if (!driversInUse.isEmpty())
throw new IllegalStateException("There are still drivers in use (" + driversInUse.size() + ")");
}
});
Might this be the problem?
Related
I have the problem that migrateDb using Flyway in a Gradle project sometimes causes
Unable to obtain inputstream for resource: META-INF/db/mysql/V1__script.sql
This error doesn't occur all the time but only sometimes but if it happens it's quite persistent and also a clean/rebuild of the project doesn't solve it.
The SQL script that is mentioned is contained within a JAR file that is referenced from the project as part of a multi module project.
My researched only brought me to https://github.com/flyway/flyway/issues/702 but this didn't lead me to the right way.
I'm also very confused that flyway is able to find the file during the classpath search but is then not able to get the input stream.
If you should need any further info please ask.
Further debugging: It seems that the error seems to happen as soon as a new file is added to the DB JAR. After rebuild and migrateDb the error occurs. If I remove the script again the error still occurs although the script is not in the generated JAR anymore. So I guess the classpath for searching for scripts and retrieving input stream is different. Does anybody know what differences there might be?
Complete stack trace:
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain inputstream for resource: META-INF/db/mysql/V1__script.sql
at org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource.loadAsString(ClassPathResource.java:84)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.scanForMigrations(SqlMigrationResolver.java:139)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:99)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:49)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:122)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:104)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:90)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:43)
at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:114)
at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:164)
at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:157)
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:75)
at org.flywaydb.core.internal.command.DbValidate.validate(DbValidate.java:157)
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1280)
at org.flywaydb.core.Flyway.access$100(Flyway.java:71)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1176)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1168)
at org.flywaydb.core.Flyway.execute(Flyway.java:1650)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1168)
at org.flywaydb.gradle.task.FlywayMigrateTask.run(FlywayMigrateTask.java:28)
at org.flywaydb.gradle.task.AbstractFlywayTask.runTask(AbstractFlywayTask.java:382)
Gradle Task:
// task that migrates the database
task migrateDb(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
// parse hibernate config
def hibernateConfig = parseHibernateConfigByStageParameter()
// set config
url = hibernateConfig.url
driver = hibernateConfig.driver
user = hibernateConfig.username
password = hibernateConfig.password
locations = [ "classpath:${flywayDbPath}/${hibernateConfig.dbType}" ]
table = 'schema_version'
outOfOrder = true
ignoreMissingMigrations = true
}
Gradle dependency:
// dependencies
dependencies {
[...]
runtime project(':core:db:mysql')
[...]
}
During further testing I noticed that the error seems to be because of the Gradle Daemon. Adding --no-daemon to the migrateDb call works fine and doesn't trigger the error.
That's fine for me for now.
It turns out that I was deploying and old .war, which was built with some .sql files that were not around anymore.
Then I fixed this by running gradlew clean build
There has been a situation when I need to run with the user defined <systemPropertyVariables> in one of my utility class.
<systemPropertyVariables>
<environment>uat</environment>
</systemPropertyVariables>
I have defined this in my pom.xml file.
inside my utility class I am extracting this value using below
System.getProperty("environment");
When I run the test case through pom.xml it runs fine. But when I try to run it through testing.xml file or as a testng test, it gives me nullpointerException.
I have defined vmarguments in run configuration as a temp solution but when this code gets distributed again this won't work as run configuration is limited to the local machines.
Can anyone please help me on how to resolve this error. Where should I define the SystemPropertyVariable so that it also works when I run the testng suite individually.
One thing you can do is pass this values from testNG using parameter tag and you can retrieve these values in Test class. By this you can run this both from maven and testng
Hi i have found a solution for this if any one else is stuck with this type of problem while designing framework.
Write a simple java code
try{
your code
}catch(NullPointerException ee){
environment="";
e.printStackTrace();
}catch(Exception e){
Assert.assertTrue(fail);
}
it only handles your code when you run via testng.xml (which is not part of your major test runs) and fails when we get any other exceptions.
Trying to use the new cypress framework with a maven project - the documentation has only an npm module setup example (npm install cypress) and a package.json usage example.
How would this be converted to usage in a maven dependency?
You can also download Cypress directly without npm.
There are instructions as well as the direct download here.
Here's a great article on using maven to run Cypress tests.
You should be able to use a Docker container for Cypress via the maven Testcontainers plugin.
Here is a good article that allows you to execute cypress tests as a part of mvn build, so you can have your backend app up and running during the cypress testing. But I did a slight change because the solution in the article doesn't take any feedback about tests execution into consideration. So, this is what I've changed:
Container creation part:
#SneakyThrows
#NotNull
private GenericContainer<?> createCypressContainer()
{
var container = new GenericContainer<>(DockerImageName.parse("cypress/included:3.4.0"));
container.withClasspathResourceMapping("e2e", "/e2e", BindMode.READ_WRITE);
container.setWorkingDirectory("/e2e");
container.withCreateContainerCmdModifier(it -> it.withEntrypoint("cypress", "open").withWorkingDir("/e2e"));
container.addEnv("CYPRESS_baseUrl", "http://host.testcontainers.internal:" + port);
return container;
}
Test execution and results evaluation:
#Test
public void runCypressTests() throws InterruptedException, IOException
{
Testcontainers.exposeHostPorts(port);
try (GenericContainer<?> container = createCypressContainer()) {
container.start();
Container.ExecResult execResult = container.execInContainer("/bin/sh", "-c", "cypress run");
log.warn(execResult.getStdout());
assertEquals("End to end tests are failed. Execution exit code returned non 0 value",
0, execResult.getExitCode());
}
}
I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.
Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,
I am working quite some time with jMeter now but this is the first time I want to start several jMeter Tests from my own code.
Basically, I copied from here: 5 ways to launch jmeter test without using jmeter gui
The JMX-File has been created with the GUI containing two variables.
The HTTP Sampler contains in the "Server name or IP" field:
${__P(server)}
The Path field contains:
/${__P(target)}
The respective entries in the jmeter.properties file are:
server=127.0.0.1
target=README
When running in jMeter, both values get replaced and the correct URL is passed.
When accessing the both properties during Runtime in my java code it yields the correct results.
When jMeter tries to replace my values, I get this message:
"Not running version, return raw function string"
I tried to trace down the problem in the jmeter sources but did not get to a result.
The Java code I use is:
public static void main(String[] args) throws IOException {
StandardJMeterEngine jmeter = new StandardJMeterEngine();
JMeterUtils.loadJMeterProperties("C:\\data\\apache-jmeter-2.13\\bin\\jmeter.properties");
JMeterUtils.setJMeterHome("C:\\data\\apache-jmeter-2.13");
JMeterUtils.initLocale();
System.out.println("Property: " + JMeterUtils.getProperty("server"));
SaveService.loadProperties();
FileInputStream in = new FileInputStream("c:\\data\\test.jmx");
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
jmeter.configure(testPlanTree);
jmeter.run();
}
Any help is highly appreciated.
Best regards, Jan
I ran into the exact same issue. There is a separate jar artifact which contains a couple of Functions such as org.apache.jmeter.functions.Property2. You need to make sure that those get registered properly.
Using maven I added this to my pom:
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_functions</artifactId>
<version>${jmeter.version}</version>
</dependency>
Now, tell JMeter to search for additional components within it
JMeterUtils.setProperty("search_paths", "ApacheJMeter_functions-2.13.jar");
The string you add to the search path needs to match the artifact as it is found on the classpath. So, when launched from eclipse that is the path to the artifact within your maven repository.