I am able to run the serenity test cases by using gradle. I use the command $ gradle clean test aggregate. Reports are also getting generated however when I click on the links provided in the Reports it fails to navigate and gives an error message. I have created the package structure as mentioned in the link below.
http://thucydides.info/docs/articles/an-introduction-to-serenity-bdd-with-cucumber.html
However still I'm not able to resolve this. Below are my Runner, Step definition and repository class.
Runner Class:
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(features = "src/test/resources/features/LoginFeatureSerenity.feature")
public class TestRunnerSerenity {
}
Step Definition class:
package org.gradle.stepdef;
public class LoginStepDefSerenity {
#Managed
public WebDriver driver;
#ManagedPages
public Pages pages;
LoginPageRepository page;
// Scenario 1: Verify New Serenity Test Case
#Step
#Given("^User is on LoginSerenity Page$")
public void user_is_on_LoginSerenity_Page() throws Throwable {
page.open();
}
#Step
#When("^User enters valid Serenity credentials$")
public void user_enters_valid_Serenity_credentials() throws Throwable {
page.setusername("kaustubhsaxena");
page.setpassword("saxenasdhfghjfg");
page.loginButton.click();
}
#Step
#Then("^User is able to login Serenity$")
public void user_is_able_to_login_Serenity() throws Throwable {
assertThat(page.loginValidationMessage.getText(), is("Login failed"));
// page.logoutButon.click();
driver.close();
}
}
Repository Class
#DefaultUrl("http://localhost:8000/app/#/login")
public class LoginPageRepository extends PageObject {
#FindBy(id = "username")
protected WebElement username;
public void setusername(String value) {
element(username).type(value);
}
public WebElementFacade username() {
return element(username);
}
// Fields for Password
#FindBy(id = "password")
protected WebElement password;
public void setpassword(String value) {
element(password).type(value);
}
public WebElementFacade password() {
return element(password);
}
}
Can you please help me on this. Thanks in advance
Fortunately I got the solution of this.
In the build.gradle below plugin needs to be added so that it will handle the reporting part.
apply plugin: 'com.jfrog.bintray'
Thanks for your help on this.
Related
I am trying to write integration tests for Quarkus using Mockito, but I fail using Argument captor.
Here is a minimal (not) working example :
#QuarkusTest
#ExtendWith(MockitoExtension.class)
public class SimpleTest {
#Captor
private ArgumentCaptor<Context> contextArgumentCaptor;
#Test
public void testOne() {
System.out.println(contextArgumentCaptor);
}
}
contextArgumentCaptor is "null".
If I remove #QuarkusTest, contextArgumentCaptor is created.
It also works with #QuarkusTest and direct Argument creator :
#QuarkusTest
public class ConfigTest {
private ArgumentCaptor<Context> contextArgumentCaptor;
#BeforeEach
public void setup() {
contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
}
#Test
public void givenValidCloudEvent_whenHandleHandoverFunction_ThenHandoverStarted() {
System.out.println(contextArgumentCaptor);
}
}
So it is really the combinaison of #QuarkusTest with #Captor that doesn't work.
Any idea?
Yes, using #QuarkusTest along with the #Captor will not work correctly. You must create the captor yourself
I am trying to get IEventBroker injected into my code to send out notifications.
Everything else works but eventBroker never gets injected. I do not get any compile time errors.
It just comes up null when the code is executed.
I've trimmed the code because it wouldn't let me submit it.
Thanks for any help in advance!
package com.test.services.internal;
imports ...
#Component
public class EnvironmentServiceImpl implements IEnvironmentService {
#Inject
private IEventBroker eventBroker;
private EntityManagerFactory entityManagerFactory;
private EntityManager entityManager;
#Activate
#SuppressWarnings("unchecked")
protected void activateComponent() {
getAll(environments -> {
if (environments.isEmpty()) {
List<Environment> initialModel = getMockEnvironments();
initialModel.forEach(this::save);
}
});
}
#Deactivate
protected void deactivateComponent() {
}
#Override
public void getAll(Consumer<List<Environment>> taskConsumer) {
eventBroker.post(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED,
createEventData(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED, updateEnvironment.getId()));
}
private Map<String, String> createEventData(String topic, String environmentId) {
}
}
this question is the duplicate post. the reason i ask is I couldn't get a valid answer (or at least the answer that i could understand) from them
hence I am asking again.
below is the code.there is an executable RunnerTest and a baseClass
#RunWith(Cucumber.class)
#CucumberOptions(plugin = {"html:target/whisper-html-report", "json:target/whisper_report.json", "com.cucumber.listener.ExtentCucumberFormatter:output/report.html"},tags = {"#Tag"})
public class RunnerTest {
}
public class BaseClass {
#Before
public void startUp() {
try {
driver = webModel.getUtils().browser();
driver.get(webModel.getUtils().getProperty("url"));
driver.manage().window().maximize();
} catch (Exception e) {
e.printStackTrace();
}
}
#After
public void tearDown(Scenario scenario) throws IOException {
if (scenario.isFailed()) {
TakesScreenshot camera = (TakesScreenshot) driver;
byte[] screenshot = camera.getScreenshotAs(BYTES);
scenario.embed(screenshot, "image/png");
System.out.println("screenShot taken");
}
driver.close();
driver.quit();
}
}
Feature file
#Tag
Feature: will this run
Scenario: try to execute feature
Given I feel like running the code
Then I run the code
Step definition-
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
public class run_this_MyStepdefs {
#Given("^I feel like running the code$")
public void iFeelLikeRunningTheCode() {
System.out.println("yes i feel like running the code");
}
#Then("^I run the code$")
public void iRunTheCode()
{
System.out.println("hence i am running the code");
}
}
below us the error code
cucumber.runtime.CucumberException: Failed to instantiate classBaseClass
I was trying to instantiate the base class, and this was the reason for the cucumber exceptions.
The moment I removed the base class object, all seemed to work fine.
I am getting an error while building google api client in a fragment. The error I am getting is;
java.lang.ClassCastException: net.janusjanus.we4x4_v1.upload cannot be cast to com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener
I have implemented GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, and LocationListener
and requesting the build as following;
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener) getActivity())
.addApi(LocationServices.API)
.build();
first I had a problem declaring the new GoogleApiClient.Builder where I declared it as ;
mGoogleApiClient = new GoogleApiClient.Builder(this)
underlined as an error, thus I had to try several ways to declare it, with getActivity() and getContext(). but I got the same error ?
Any idea on what I am doing wrong here and the correct way ?
Well simply in my case i had to declare the GoogleApiClient.Builder as following;
mGoogleApiClient = new GoogleApiClient.Builder(UploadPictures.this.getContext())
where UploadPictures is the fragment name.
Hope this could be helpful for someone.
implement GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, and LocationListener
#Override
public void onConnectionFailed(ConnectionResult result) {
}
#Override
public void onConnected(Bundle arg0) {
}
#Override
public void onConnectionSuspended(int arg0) {
}
#Override
public void onLocationChanged(Location location) {
}
And then change code to:
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
My Spring Data Cassandra configuration looks like this:
#Configuration
#EnableCassandraRepositories(basePackages = {
"mypackage.repository.cassandra",
})
public class DistributedRepositoryConfiguration {
// ...
#Bean
public CassandraSessionFactoryBean session() throws Exception {
CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
session.setCluster(cluster().getObject());
session.setKeyspaceName(configuration.get().getKeyspace());
session.setConverter(converter());
session.setSchemaAction(SchemaAction.CREATE);
return session;
}
}
Generally, Spring Data Cassandra works in my project. However, when I start my application I have no tables created. Anyone who could tell me what I'm doing wrong?
It is not written well in documentation if you want to have automatic table creation you should tell cassandra where to look for entity classes:
<cassandra:mapping entity-base-packages="your.package" />
If you want to do the same using annotiation configuration you have to explicitly tell CassandraTemplate where to look for it. So
#Bean
public CassandraSessionFactoryBean session() throws Exception {
CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
session.setCluster(cluster().getObject());
session.setKeyspaceName(keyspaceName);
session.setConverter(converter());
session.setSchemaAction(SchemaAction.CREATE);
return session;
}
#Bean
public CassandraConverter converter() throws Exception {
return new MappingCassandraConverter(mappingContext());
}
#Bean
public CassandraMappingContext mappingContext() throws Exception {
BasicCassandraMappingContext bean = new BasicCassandraMappingContext();
bean.setInitialEntitySet(CassandraEntityClassScanner.scan(("package.with.your.entities")));
return bean;
}
To do it with ease I suggest using AbstractCassandraConfiguration and override methods which You need.
I checked the class AbstractCassandraConfiguration and found the following code:
public String[] getEntityBasePackages() {
return new String[] { getClass().getPackage().getName() };
}
Since my config class isn't in the main package, the component scan does not find my classes with the #Table annotation. So I override the method "getEntityBasePackages()" using my StartUp class and everything worked fine.
This is my config class:
#Configuration
public class CassandraConfig extends AbstractCassandraConfiguration {
#Value("${spring.data.cassandra.keyspace-name}")
private String keyspaceName;
#Override
protected String getKeyspaceName() {
return keyspaceName;
}
#Override
public String[] getEntityBasePackages() {
return new String[]{AppStartup.class.getPackage().getName()};
}
#Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
return Collections.singletonList(CreateKeyspaceSpecification
.createKeyspace(keyspaceName)
.ifNotExists(true)
.with(KeyspaceOption.DURABLE_WRITES, true)
.withSimpleReplication());
}
#Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
}
}
Using this class, your application should create the required keyspace and tables to run.
If you using CassandraDataConfiguration just annotated you base class application with:
#EntityScan("mypackage.repository.cassandra")
The base package information will be used in CassandraDataAutoConfiguration.cassandraMapping method to add this package to cassandra mapping.