So I have written test cases with Jmockit and on my dev machine they run with java 8 and junit 4. Our bamboo server has java 10 installed and I consistently receive errors for all my tests:
build 20-Mar-2019 11:58:10 [INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.915 s - in org.tsocs.txn.OCSServiceTest
build 20-Mar-2019 11:58:10 [INFO] Running org.tsocs.ws.services.RolloverBundleTest
build 20-Mar-2019 11:58:11 [ERROR] Tests run: 8, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.684 s <<< FAILURE! - in org.tsocs.ws.services.RolloverBundleTest
build 20-Mar-2019 11:58:11 [ERROR] failInvalidBundle(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.303 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] successUpdateBundleWithNoRolloverAmountAndSendSMS(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.039 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] failNotRollOverBundle(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.039 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] successRolloverTransfer(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.041 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] failBundleAlreadyTransferred(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.039 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] failInsufficientFundsForTransfer(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.041 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] failInsufficientFundsToRollover(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.041 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
build 20-Mar-2019 11:58:11
build 20-Mar-2019 11:58:11 [ERROR] failBundleExpiredOrDepleted(org.tsocs.ws.services.RolloverBundleTest) Time elapsed: 0.043 s <<< ERROR!
build 20-Mar-2019 11:58:11 java.lang.IllegalStateException:
build 20-Mar-2019 11:58:11 Missing #Tested or #Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build 20-Mar-2019 11:58:11 when initializing field "Timestamp tradeStartTime"
build 20-Mar-2019 11:58:11 of #Tested object "RolloverBundle testService"
I thought it maybe a compatibility issue with junit4/java11/jmockit. I've refactored the code to use junit 5 however none of the mocks are being injected now and received alot of other issues as a result IE: db objects not being created or null pointers:
[ERROR] Tests run: 8, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.183 s <<< FAILURE! - in org.tsocs.ws.services.RolloverBundleTest
[ERROR] failInvalidBundle Time elapsed: 0.031 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failInvalidBundle(RolloverBundleTest.java:396)
[ERROR] successUpdateBundleWithNoRolloverAmountAndSendSMS Time elapsed: 0.03 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.successUpdateBundleWithNoRolloverAmountAndSendSMS(RolloverBundleTest.java:125)
[ERROR] failNotRollOverBundle Time elapsed: 0.014 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failNotRollOverBundle(RolloverBundleTest.java:599)
[ERROR] successRolloverTransfer Time elapsed: 0.036 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.successRolloverTransfer(RolloverBundleTest.java:225)
[ERROR] failBundleAlreadyTransferred Time elapsed: 0.015 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failBundleAlreadyTransferred(RolloverBundleTest.java:461)
[ERROR] failInsufficientFundsForTransfer Time elapsed: 0.016 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failInsufficientFundsForTransfer(RolloverBundleTest.java:320)
[ERROR] failInsufficientFundsToRollover Time elapsed: 0.015 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failInsufficientFundsToRollover(RolloverBundleTest.java:678)
[ERROR] failBundleExpiredOrDepleted Time elapsed: 0.015 s <<< ERROR!
java.lang.NullPointerException
at org.tsocs.ws.services.RolloverBundleTest.failBundleExpiredOrDepleted(RolloverBundleTest.java:524)
It looks like none of the mocked objects are being injected. Test case looks like:
package org.tsocs.ws.services;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import mockit.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.EJBUtils;
import org.addon.MobileService;
import org.errors.TradeSwitchException;
import org.financial.FinancialBeanRemote;
import org.message.MessageBeanRemote;
import org.message.MessagePurpose;
import org.model.entity.NodeInfo;
import org.resourcemessage.dao.LanguageResourceDAO;
import org.tsocs.dao.BundleItemsDAO;
import org.tsocs.dao.BundleItemSubsDAO;
import org.tsocs.dao.UsageNotificationDAO;
import org.tsocs.entity.BundleItem;
import org.tsocs.entity.BundleItemSubs;
import org.tsocs.entity.UsageNotification;
import org.tsocs.ws.services.structures.RollOverBundleResp;
import org.tsocs.ws.webui.RolloverBundleConfigViewModel;
import org.txn.Amount;
import org.txn.ISO8583;
import org.txn.TxnBeanRemote;
import org.txn.TxnUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class RolloverBundleTest
{
private static final long BUNDLE_SUBSCRIPTION_ID = 6667L;
private static final long BUNDLE_ITEM_ID = 1023L;
private static final long BUNDLE_IRN = 888L;
private static final long NODE_IRN_ID = 777L;
private static final Amount balance = new Amount(BigDecimal.valueOf(5000L));
private static final Amount credit = new Amount(BigDecimal.valueOf(200L));
#Tested(fullyInitialized = true)
private RolloverBundle testService;
#Mocked
private BundleItemsDAO mockBundleItem;
#Mocked
private BundleItemSubsDAO mockBundleItemSubscription;
#Mocked
private FinancialBeanRemote mockFinancialBean;
#Mocked
private MessageBeanRemote mockMessageBean;
#Mocked
private UsageNotificationDAO mockUsageNotification;
#Mocked
private TxnBeanRemote mockTxnBean;
#Mocked
private LanguageResourceDAO mockLangRes;
#Mocked
private MobileService mockMobileService;
#BeforeEach
public void init()
{
new MockUp<EJBUtils>()
{
#Mock
public FinancialBeanRemote lookupFinancialBean() throws TradeSwitchException {
return mockFinancialBean;
}
#Mock
public TxnBeanRemote lookupTxnBean() throws TradeSwitchException {
return mockTxnBean;
}
#Mock
public MessageBeanRemote lookupMessageBean() throws TradeSwitchException {
return mockMessageBean;
}
};
}
#Test
public void failInsufficientFundsToRollover() throws Exception
{
final String errorMessage = "Borked. rollover amount exceeds balance";
final BundleItemSubs bundleOfJoy = new BundleItemSubs();
bundleOfJoy.setBundleItem(BUNDLE_ITEM_ID);
bundleOfJoy.setIrn(BUNDLE_IRN);
final BundleItem item = new BundleItem();
item.setBundleAttr(BundleItem.IS_ROLLOVER);
item.setRolloverAmount(new Amount(BigDecimal.valueOf(10_000L)));
final NodeInfo node = new NodeInfo();
node.setNodeIrn(NODE_IRN_ID);
final Map<String, String> args = new HashMap<>();
args.put(RolloverBundleConfigViewModel.MessageTypes.INSUFFICIENT_FUNDS.getType(), "1");
new Expectations()
{
{
mockBundleItemSubscription.get(withEqual(BUNDLE_SUBSCRIPTION_ID));
result = bundleOfJoy;
mockBundleItem.get(withEqual(BUNDLE_ITEM_ID));
result = item;
mockFinancialBean.getBalance(anyLong, anyString);
result = balance;
mockFinancialBean.getCreditLimit(anyLong, anyString);
result = credit;
mockBundleItemSubscription.hasBundleSubsExpiredOrDepleted(anyLong);
result = false;
mockLangRes.getResourceMessage(anyLong, anyLong);
result = errorMessage;
}
};
testService.setArgs(args);
testService.setNodeInfo(node);
final RollOverBundleResp response = testService.rollOverBundle(BUNDLE_SUBSCRIPTION_ID);
assertNotNull(response);
assertNull(response.expiryDate);
assertTrue(response.syserrorResp.getSysResultMsg().contains(errorMessage));
new Verifications()
{
{
mockBundleItemSubscription.get(BUNDLE_SUBSCRIPTION_ID);
times = 1;
mockBundleItem.get(withEqual(BUNDLE_ITEM_ID));
times = 1;
mockBundleItemSubscription.hasBundleSubsExpiredOrDepleted(anyLong);
times = 1;
mockFinancialBean.getBalance(anyLong, anyString);
times = 1;
mockFinancialBean.getCreditLimit(anyLong, anyString);
times = 1;
mockLangRes.getResourceMessage(anyLong, anyLong);
times = 1;
mockUsageNotification.notificationsByBundleItem(anyLong, anyInt);
times = 0;
mockMessageBean.sendMessage(anyLong, anyString, anyString, anyString, (MessagePurpose) any);
times = 0;
}
};
}
}
I've looked at the samples in the jmockit github page but I can't see that I am doing anything out of the ordinary. I have the agent arg line defined in the surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>
-javaagent:${settings.localRepository}/org/jmockit/jmockit/1.45/jmockit-1.45.jar
</argLine>
<disableXmlReport>true</disableXmlReport>
</configuration>
</plugin>
This is my first time using jmockit(tho am familair with mockito) Any assistance greatly appreciated
Environment:
OS: macOS Mojave 10.14.3
JDK: 11.0.2-amzn
maven: 3.6.0
junit: 5.4.1
jmockit: 1.45
Since the Jmockit framework is complaining about the missing fields for the java.sql.Timestamp constructor I went and added:
#Injectable
private int year, month, date, hour, minute, seconds, nano;
Test is working under JDK 10 and 11
Related
I am trying to do a tiny poc (a add operation in a celery task) with Kotlin -> celery -> python.
Python->celery->Python is ok. But with https://github.com/crabhi/celery-java and this "wrong" code:
package poc_kotlin_celery
import com.geneea.celery.*
fun main() {
val client: Celery = Celery.builder()
.brokerUri("amqp://localhost/%2F")
.backendUri("rpc://localhost/%2F")
.build();
val args = arrayOf(1, 2)
val result: AsyncResult<Int> = client.submit("task.add", args)
val suma: Int = result.get() as Int
println(suma as Int);
}
I can not fix the compilation errors:
$ gradle run
> Task :app:compileKotlin FAILED
e: /home/miguel/code/poc_kotlin_celery/app/src/main/kotlin/poc_kotlin_celery/App.kt: (15, 16): Unresolved reference: AsyncResult
e: /home/miguel/code/poc_kotlin_celery/app/src/main/kotlin/poc_kotlin_celery/App.kt: (15, 42): Not enough information to infer type variable R
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 730ms
1 actionable task: 1 executed
So i have a bare react-native application wherein i am using expo modules.
I am using the expo location module and getting the following error.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:361: error: cannot find symbol
new Permissions.PermissionsRequestListener() {
^
symbol: class PermissionsRequestListener
location: interface Permissions
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:502: error: cannot find symbol
mPermissions.getPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
^
symbol: method getPermission(String)
location: variable mPermissions of type Permissions
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:503: error: cannot find symbol
&& mPermissions.getPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
^
symbol: method getPermission(String)
location: variable mPermissions of type Permissions
Note: /home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/taskConsumers/GeofencingTaskConsumer.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':expo-location:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 16s
at checkExecSyncError (child_process.js:607:13)
at execFileSync (child_process.js:627:13)
at runOnAllDevices (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at buildAndRun (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at then.result (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7);
So my best guess is there is an error while importing stuff from permission module.
So i have these lines in expo-permissions app level build.gradle file.
compileOnly('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
I am also using jettifier, i am guessing there is some issue with respect to transpiling code to android x.
I changed this
compileOnly('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
to
implementation 'com.facebook.react:react-native:+'
and everything works fine.
I would like to know exactly what is happening and if this deserves a pull request.
Any help on the same would be highly appreciated thanks.
ok, in my case I needed to raise the following versions from android/build.grade:
buildscript {
ext {
buildToolsVersion = "28.0.3" -> "29.0.2"
minSdkVersion = 21
compileSdkVersion = 28 -> 29
targetSdkVersion = 28 -> 29
}
I'm encountering issue with a custom gradle task. Seems like gradle refuse to start a command line process.
Here is the custom task:
task generateAllure(type: Exec) {
workingDir "$projectDir/allure/bin"
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'allure.bat', 'generate', '-c', '../../integration/build/allure-results'
} else {
commandLine 'bash', '-c', 'allure', 'generate', '-c',"$projectDir/integration/build/allure-results"
}
}
tasks.withType(Test)*.finalizedBy generateAllure
With the appropriate dependency:
compile group: 'ru.yandex.qatools.allure', name: 'allure-commandline', version: '1.4.18'
After using gradle clean test execution fails on:
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':generateAllure'.
> A problem occurred starting process 'command 'cmd''
Any thoughts about that? Thanks!
UPD:
This is the stacktrace i'm getting after performing gradle -S clean test:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':generateAllure'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:262)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:246)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:136)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:201)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.executeWithTask(DefaultTaskPlanExecutor.java:192)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'cmd''
at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:231)
at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:209)
at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:355)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:85)
at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
... 6 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'cmd'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67)
... 7 more
Caused by: java.io.IOException: Cannot run program "cmd" (in directory "D:\Git\rozetka-test-automation\allure\bin"): CreateProcess error=267, The directory name is invalid
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 10 more
Caused by: java.io.IOException: CreateProcess error=267, The directory name is invalid
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 11 more
Now with the stacktrace the problem is pretty much clear.
In the task you defined
task generateAllure(type: Exec) {
workingDir "$projectDir/allure/bin"
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'allure.bat', 'generate', '-c', '../../integration/build/allure-results'
} else {
commandLine 'bash', '-c', 'allure', 'generate', '-c',"$projectDir/integration/build/allure-results"
}
}
tasks.withType(Test)*.finalizedBy generateAllure
You've set the working directory to "$projectDir/allure/bin" this value get interpolated into "D:\Git\rozetka-test-automation\allure\bin" which apparently doesn't exist on your system
Keep in mind that "doesn't exist" might also mean "doesn't exist yet", it depends on what you're doing in the rest of your build.
Under the assumption the allure\bin is not created by the build - something is wrong with your path.
I am trying to start Selenium from Gradle in order to run Protractor tests.
Here is my Gradle script:
//main task to run protractor tests
task uiTests << {
println "Starting protractor tests"
}
//start Selenium server
task startSelenium << {
println "Starting Selenium..."
ant.exec(executable: '/bin/bash', spawn: true) {
arg(value:'webdriver-manager')
arg(value:'start')
}
}
//run protractor
task runProtractor(type: Exec) {
commandLine 'protractor', 'bignibou-client/protractor.conf.js'
}
//start selenium, then run protractor
uiTests.dependsOn([startSelenium, runProtractor])
However, the output seems to indicate that the Selenium process has not being started:
:runProtractor
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:172
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
at ClientRequest.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:172:16)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at Socket.socketErrorListener (_http_client.js:259:9)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at emitErrorNT (net.js:1250:8)
at doNTCallback2 (node.js:429:9)
at process._tickCallback (node.js:343:17)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
at [object Object].Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:445:22)
at [object Object].DriverProvider.getNewDriver (/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
at [object Object].Runner.createBrowser (/usr/local/lib/node_modules/protractor/lib/runner.js:182:37)
at /usr/local/lib/node_modules/protractor/lib/runner.js:263:21
at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
at /usr/local/lib/node_modules/protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1
:runProtractor FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':runProtractor'.
> Process 'command 'protractor'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Can anyone please provide informed tips and guidance?
By referring the webdriver-manager script directly as shown below sorted the issue:
//main task to run protractor tests
task uiTests << {
println "Starting protractor tests"
}
//start Selenium server
task startSelenium << {
println "Starting Selenium..."
ant.exec(executable: 'webdriver-manager', spawn: true) {//CHANGED!!
arg(value: 'start')
}
}
//run protractor
task runProtractor(type: Exec) {
commandLine 'protractor', 'bignibou-client/protractor.conf.js'
}
//start selenium, then run protractor
uiTests.dependsOn([startSelenium, runProtractor])
I am new to Jenkins.
I have sample selenium code like below in Java project:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SampTest
{
public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
driver.quit();
}
}
This works perfect.
I configured like below in Jenkins:
Create a new project with name.
In Advanced options, added Workspace as "D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src"
In build section, i used Execute Windows batch command like "javac SampTest.java | java SampTest"
(Basically i dont know what to use here. Can someone help me here).
When i build the project now i see an error message saying below:
Started by user anonymous
Building in workspace D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src
[src] $ cmd /c call C:\Users\user\AppData\Local\Temp\hudson578216989100659838.bat
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>javac SampTest.java | java SampTest
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" SampTest.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
SampTest.java:2: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
^
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class WebDriver
location: class SampTest
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class FirefoxDriver
location: class SampTest
4 errors
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE