I'm getting an error in Cucumber.class saying
cannot convert from class cucumber to calls runner
Here's my code:
package testRunners;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="resources/features", glue="StepDefinition")
public class Login {
}
It happens when you have dependency mismatch in your project. More details can be seen after digging in pom.xml. Please share it.
For now you should be knowing that #Runwith takes something which extends ParentRunner Class, so make sure the Cucumber.class that you are using here is extending ParentRunner.
Related
I have placed the logback-test.xml in classpath
karate.log is not getting generated, I have seen there is a file called main.log that gets generated sometime
Here is the project structure
Here is the runner file
package com.org.KarateLearning;
import com.intuit.karate.KarateOptions;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.junit4.Karate;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertTrue;
public class ParallelTestRunner {
#Test
public void parallel() {
Results res = Runner.path("classpath:features").tags("~#ignore").parallel(5);
assertTrue(res.getErrorMessages(),res.getFailCount()==0);
}}
I have tried placing logback-test.xml in resources and com.org.KarateLearning but karate.log is not getting genearted
Deleted the existing file ( logback-test.xml ) and created a new one from below path under src/test/java
https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/logback-test.xml
Now file is getting generated in target folder
In between it was getting generated outside of target folder. Now its getting generated at correct location inside target folder.
Also note even after deleting the logback-test.xml log was getting generated. (not sure about the reason for it)
Now all works well
I have a problem with TestNG. I cannot run a test.
I am getting this error:
POM.xml has no errors.
Here is the code in test page:
import Pages.SearchPage;
import org.testng.annotations.Test;
import core.Web.AllListeners.*;
public class Search extends Listener {
#Test(groups = "Regression")
public void ticketBookingFunctionality() {
new SearchPage()
.openUrl()
.inputCaption("Comic")
.selectCityByValue()
.inputDateFrom("2020-01-01")
.inputDateTo("2021-07-05")
.clickButtonSearch()
.clickButtonBuy()
.chooseTicket()
.choosePrice()
.pushButtonFindTickets()
.closeLoginPopup();
}
}
Where can be the problem?
You need to add the following testng related jar files within your project.
To be fair, I am not testing the service, but am using a service as part of my test classes to test a Bluetooth library. So my test class needs to create a service that invokes the Bluetooth library. The test class then needs to bind to this service to perform the tests. However, attempting to start the service always gives me the following error which leads to a Nullpointer exception
W/ActivityManager: Unable to start service Intent { cmp=com.example.androidhdpadapter.test/com.lampreynetworks.ahd.oxp.transport.BluetoothTestService } U=0: not found
At this stage, the test class is very simple:
package com.lampreynetworks.ahd.oxp.transport;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.fail;
#RunWith(AndroidJUnit4.class)
public class AndroidServiceBluetoothAdapterTests
{
private final static String TAG =
AndroidServiceBluetoothAdapterTests.class.getName();
#Rule
public final ServiceTestRule serviceRule = new ServiceTestRule();
#Test
public void testAndroidBluetoothAdapter() throws TimeoutException, InterruptedException
{
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
Intent intent = new Intent(context, BluetoothTestService.class);
serviceRule.startService(intent);
Thread.sleep(12000);
IBinder binder = serviceRule.bindService(intent);
BluetoothTestService service = ((BluetoothTestService.TestManagerBinder) binder).getService();
serviceRule.unbindService();
}
}
There are NUMEROUS posts regarding problems with testing services and I have tried all of them (messing with gradle.build file dependencies, conflicts between androidx.test and android.support.test, etc.). I have also tried invoking the service in the standard manner without ServiceTestRule, but that likely failed because there is no AndroidManifest for the test that specifies the service (I don't know if that can be done).
Maybe it is not possible to use Androidx's ServiceTestRule unless one is actually testing a service that is part of an application. Here I am testing a Bluetooth Library that is typically invoked by a service, and this test service is NOT part of the library, but exists only in the androidTests directory.
The reason I am doing this is that Android has buggy Bluetooth and on some platforms, the Bluetooth spontaneously shuts down and then restarts. My Bluetooth Library tries to recover from this shutdown. The recovery works BUT for every spontaneous shutdown and recovery, I get a service leak. That is what I am trying to solve in a simplified framework instead of a full-fledged application.
On TomEE Plume 7.0.3/4 when I change my REST annotated classes package from org.superbiz then they are no more deployed when I deploy the war file.
Sample class is given below
package com.abc.rest.application;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
#ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class));
}
}
Now ApplicationConfig class is never read by the TomEE Plume. What configuration I need to make so that TomEE recognize my rest application config class and other jax-rs, ejb and jpa annotated classes.
In system.properties set openejb.classloader.forced-load=com.abc
then only my application packages would be loaded. Tricky to understand.
I know you can specify tags for features and then ignore them when running cucumber on the command line. But I'm using cucumber-jvm and running it from maven. #ignore doesn't work and I wouldn't know how to pass the to-be-ignored tags to the runner that executes the Gherkin tests.
The work-around is to move feature that are done to another directory while developing and testing new ones, but that's not how it should be. How do other users deal with this deficiency?
You can tell runner skip #ignore
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(features = {"classpath:my_feature.feature"},
tags = {"~#ignore"})
public class RunCukesTest {
}
You can tag your scenarios as #ignore which will be ignored.
If you want to run only selective scenarios then mark your every new feature that you want to test as #new_test. Tell the Cukes Runner to run only tags = #new_test
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(features = {"classpath:my_feature.feature"},
tags = {"#new_test"})
public class RunCukesTest {
}
Anything that you don't want to test should not have a tag or should have some other tag name