In allure report unable to see logger statements put inside #Step annotated method - allure

I am doing POC on allure reporting.I created a Gradle project that has a test class with two #Test annotated methods.The same test class has #Step annotated method that has logger statements.This #Step annotated method is called from one of the #Test annotated methods.Upon running the tests,I do not see the logger info(present under #Step method) in allure result.
I have added needed dependencies and plugin in build.gradle.
content of build.gradle file.
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/4.8.1/userguide/java_library_plugin.html
*/
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id "io.qameta.allure" version "2.8.1"
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'io.qameta.allure:allure-testng:2.12.0'
implementation 'org.testng:testng:6.9.9'
compile('org.aspectj:aspectjweaver:1.9.4')
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.0.2'
compile 'org.apache.logging.log4j:log4j-web:2.0.2'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
allure {
version = '2.8.1'
autoconfigure = true
aspectjweaver = true
useTestNG {
version = '2.0-BETA20'
}
}
my sample test code:
public class SampleTestForAllureReport {
public static Logger logger = LoggerFactory.getLogger(SampleTestForAllureReport.class);
#Severity(SeverityLevel.BLOCKER)
#Description("This is a sample test for printing welcome")
#Test()
public void welcomeEvent()
{
loggingSteps();
System.out.println("WELCOME");
}
#Test()
public void exitEvent()
{
System.out.println("EXIT");
}
#Step("logger for welcome test")
public void loggingSteps()
{
logger.info("log for step1");
}
}
allure result.

Related

Unable to generate screenshot in Cucumber Extent Report

I am unable to see screenshot getting captured in the Extent report for cucumber.
I have debuged and observed that the code gets executed, but the screenshot is not saved in the file of extent report or cucumber html report.
Screenshot Code
public void screenshot(Scenario scenario) {
if(scenario.isFailed()) {
byte[] screenshot=SeleniumUtils.captureScreenshot(); scenario.public void screenshot(Scenario scenario) { embed(screenshot, "image1/png"); }
Runner Class
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features", tags = "#login_internal_user", glue
= {
"stepDefinitions"
}, plugin = {
"pretty",
"rerun:src/test/java/features/rerun.txt",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:",
"html:reports"
}
)
public class loginRunner {
#AfterClass
public static void teardown() {
SeleniumUtils.quitDriver();
}
}
Extent.properties file
# indicate which reporters to use
extent.reporter.logger.start=true
# point to any configuration used
extent.reporter.logger.config=src/main/resources/extent-config.xml
# specify output path
extent.reporter.logger.out=reports/importsTeam-reports
screenshot.dir=reports/importsTeam-reports/screenshots/
Maven Properties
Extent Cucumber Adapter version- 1.0.7
Cucumber Jars- 4.2.0
You should use the html reporter. your property file should include,
extent.reporter.html.start = true
extent.reporter.html.config = <html config xml>
extent.reporter.html.out = <output path>

Camel Properties file load from Junit Integration Test

I have a Camel Route which uses CDI to load a properties file from the JBoss configuration directory ...works perfect.
What I need to do is load one of the properties that are loaded in
an Arquillian integration test I am writing.
Example:
Content of Fiddler.properties file in the JBoss configuration directory
silly.value = Laughing
serious.value = politics
Example Producer class to load properties
/**
* Create the Camel properties component using CDI #Produces
*/
#Produces
#Named("properties")
PropertiesComponent propertiesComponent() {
final PropertiesComponent component = new PropertiesComponent();
// load JBoss properties file
component.setLocation(
"file:${jboss.server.config.dir}/fiddler.properties"
);
return component;
}
A given property from the Fiddler.properties file is now available in the main Camel route as {{silly.value}} or {{serious.value}}
Problem:
What I would like to do is load/reference one of these property values from my Arquillian Integration Test … probably in the #BeforeClass method …something like below:
#RunWith(Arquillian.class)
public class MainRouteIT {
.
.
Boolean allOK = false;
#BeforeClass
public static void setupTest() throws Exception {
allOK = new testCheck(
{{silly.value}}, {{serious.value}}
);
.
.
Any idea if something like this is possible in Camel within an Arquillian test ?
Here is the solution we are using (but without Arquillian):
First define a CDI alternative for the Camel "properties" component, which will use testing property values.
Then annotate your unit test in order to use the alternate producers of Camel components.
#Alternative
public class CamelAlternatives {
#Produces
#ApplicationScoped
#Named("properties")
public PropertiesComponent propertiesComponent() {
PropertiesComponent component = new PropertiesComponent();
component.setLocations( Arrays.asList("classpath:common.properties", "classpath:testing.properties") );
return component;
}
#RunWith(CamelCdiRunner.class)
#Beans(alternatives = {CamelAlternatives.class})
public class MyUnitTest {
...
}

Android Room Persistence library and Kotlin

I am trying to write a simple app using Kotlin and Room Persistence Library.
I followed the tutorial in the Android Persistence codelab.
Here is my AppDatabase class in Kotlin:
#Database(entities = arrayOf(User::class), version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun userModel(): UserDao
companion object {
private var INSTANCE: AppDatabase? = null
#JvmStatic fun getInMemoryDatabase(context: Context): AppDatabase {
if (INSTANCE == null) {
INSTANCE = Room.inMemoryDatabaseBuilder(context.applicationContext, AppDatabase::class.java).allowMainThreadQueries().build()
}
return INSTANCE!!
}
#JvmStatic fun destroyInstance() {
INSTANCE = null
}
}
}
But when I tried to run the app, it crashes immediately.
Here is the crash log:
Caused by: java.lang.RuntimeException: cannot find implementation for com.ttp.kotlin.kotlinsample.room.AppDatabase. AppDatabase_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:90)
at android.arch.persistence.room.RoomDatabase$Builder.build(RoomDatabase.java:340)
at com.ttp.kotlin.kotlinsample.room.AppDatabase$Companion.getInMemoryDatabase(AppDatabase.kt:19)
at com.ttp.kotlin.kotlinsample.MainKotlinActivity.onCreate(MainKotlinActivity.kt:28)
at android.app.Activity.performCreate(Activity.java:6272)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
It looks like the class AppDatabase_Impl wasn't autogenerated. I checked the original java app downloaded from codelab and found that AppDatabase_Impl was autogenerated.
Kotlin version: 1.1.2-3
Room version: 1.0.0-alpha1
Is there anyone experienced with this?
Edit:
Using kapt solves my problem. In my case, I have to replace annotationProcessor with kapt.
Usually in project build.gradle I define the dependencies versions:
ext {
buildToolsVersion = '25.0.2'
supportLibVersion = '25.3.1'
espressoVersion = '2.2.2'
archRoomVersion = '1.0.0-alpha1'
}
so in app build.gradle the dependencies look like:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:${rootProject.supportLibVersion}"
compile "android.arch.persistence.room:runtime:${rootProject.archRoomVersion}"
annotationProcessor "android.arch.persistence.room:compiler:${rootProject.archRoomVersion}"
kapt "android.arch.persistence.room:compiler:${rootProject.archRoomVersion}"
androidTestCompile("com.android.support.test.espresso:espresso-core:${rootProject.espressoVersion}", {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
}
Now you can define Entities Daos and Database in Kotlin.
Database:
#Database(entities = arrayOf(User::class), version = 1)
abstract class Database : RoomDatabase() {
abstract fun userDao(): UserDao
}
Entity:
#Entity(tableName = "user")
class User {
#PrimaryKey(autoGenerate = true)
var id: Int = 0
var name: String = ""
}
Dao:
#Dao
interface UserDao {
#Query("SELECT * FROM user")
fun getAll(): List<User>
#Insert
fun insertAll(vararg users: User)
#Delete
fun delete(user: User)
}
NB: Query with parameters.
Kotlin renames params, so the SQL query to retrieve all the emails that belong at a user via the userId is:
#Query("SELECT * FROM email "
+ "INNER JOIN user ON user.id = email.userId "
+ "WHERE user.id = :arg0")
fun getEmailsForUser(userId: Int): List<Email>
In my case, in build.gradle, when you have "annotationProcessor" you need to duplicate with "kapt" and it works.
compile "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
Try out these steps
Step 1. Set the room_version in the project.gradle file
buildscript {
ext.kotlin_version = '1.1.51'
ext.room_version = '1.0.0-alpha9-1'
...
Step 2. Apply the kotlin-kapt plugin in the app.gradle file, and this solved my issue.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
...
Step 3. Add the kapt dependency in the app.gradle file
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
...
}
Anyone interested in using Kotlin with Room and Data Binding can see this sample project https://github.com/entrpn/kotlin-room-databinding
i almost gave up. but after doing just what dharmin007 said i also had to clean the project. that made it work. I've noticed that whenever you add kapt to gradle you MUST clean the project after synching gradle.
I don't know if there is a necessity to my answer I know that some of the above answers already included this to their answers but they added other things
ONLY ADD
apply plugin: 'kotlin-kapt'

Simple RootAction plugin in Jenkins not working

I've just started developing plugins in jenkins and tried to implement a root action by writing a plugin which implements RootAction. From the documentation of this interface (http://javadoc.jenkins-ci.org/?hudson/model/RootAction.html) it seems very easy compared to other plugins but I'm not getting it to work..
Here is my class which implements RootAction:
#Extension
public class MultiActionView implements RootAction {
public String getIconFileName() {
return "/plugins/multi-action-view/images/24x24/myPicture.png";
}
public String getDisplayName() {
return "My RootAction";
}
public String getUrlName() {
return "http://www.stackoverflow.com/";
}
}
I see that my plugin is installed but nothing shows in the sidepanel despite it says in the documentation that the rootaction will be added automatically. I've tried with and without an index.jelly file in the appropriate folder of my project but with no positive results.
Does anyone have any idea of why this plugin is not showing or can come with a working example of how to create a simple root action in jenkins? Thanks!
// Bogge

Example of testing a RPC call using GWT-TestCase with GAE

How is that for a lot of acronyms!
I am having trouble testing GWT's RPC mechanism using GWT's GWTTestCase. I created a class for testing using the junitCreator tool included with GWT. I am attempting to test using the built in Google App Engine using the created "hosted mode" testing profile created by junitCreator. When I run the test, I keep getting errors saying things like
Starting HTTP on port 0
HTTP listening on port 49569
The development shell servlet received a request for 'greet' in module 'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml'
[WARN] Resource not found: greet; (could a file be missing from the public path or a <servlet> tag misconfigured in module com.google.gwt.sample.stockwatcher.StockWatcher.JUnit.gwt.xml ?)
com.google.gwt.user.client.rpc.StatusCodeException: Cannot find resource 'greet' in the public path of module 'com.google.gwt.sample.stockwatcher.StockWatcher.JUnit'
I hope that someone somewhere has successfully run junit test (using GWTTestCase or just plain TestCase) that will allow for the testing of gwt RPC. If this is the case, could you please mention the steps you took, or better yet, just post code that works. Thanks.
SyncProxy allows you to make GWT RPC call from Java. So you can test your GWT RPC with regular Testcase (and faster than GwtTestcase)
See
http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/
http://www.gdevelop.com/w/blog/2010/03/13/invoke-gwt-rpc-services-deployed-on-google-app-engine/
I got this working. This answer assume's you're using Gradle, but this could easily be adopted to run from ant. First, you'll have to make sure that you separate your GWT tests from your regular JUnit tests. I created 'tests/standalone' for the regular tests, and 'tests/gwt' for my GWT tests. I still get 1 single HTML report in the end that has all of the info.
Next, you need to make sure JUnit is part of your ant classpath, as described here:
http://gradle.1045684.n5.nabble.com/Calling-ant-test-target-fails-with-junit-classpath-issue-newbie-td4385167.html
Then, use something similar to this to compile your GWT tests and run them:
task gwtTestCompile(dependsOn: [compileJava]) << {
ant.echo("Copy the test sources in so they're part of the source...");
copy {
from "tests/gwt"
into "$buildDir/src"
}
gwtTestBuildDir = "$buildDir/classes/test-gwt";
(new File(gwtTestBuildDir)).mkdirs()
(new File("$buildDir/test-results")).mkdirs()
ant.echo("Compile the tests...");
ant.javac(srcdir: "tests/gwt", destdir: gwtTestBuildDir) {
classpath {
pathElement(location: "$buildDir/src")
pathElement(location: "$buildDir/classes/main")
pathElement(path: configurations.runtime.asPath)
pathElement(path: configurations.testCompile.asPath)
pathElement(path: configurations.gwt.asPath)
pathElement(path: configurations.gwtSources.asPath)
}
}
ant.echo("Run the tests...");
ant.junit(haltonfailure: "true", fork: "true") {
classpath {
pathElement(location: "$buildDir/src")
pathElement(location: "$buildDir/classes/main")
pathElement(location: gwtTestBuildDir)
pathElement(path: configurations.runtime.asPath)
pathElement(path: configurations.testCompile.asPath)
pathElement(path: configurations.gwt.asPath)
pathElement(path: configurations.gwtSources.asPath)
}
jvmarg(value: "-Xmx512m")
jvmarg(line: "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005")
test(name: "com.onlyinsight.client.LoginTest", todir: "$buildDir/test-results")
formatter(type: "xml")
}
}
test.dependsOn(gwtTestCompile);
Finally, here's a simple GWT test:
public class LoginTest extends GWTTestCase
{
public String getModuleName()
{
return "com.onlyinsight.ConfModule";
}
public void testRealUserLogin()
{
UserServiceAsync userService = UserService.App.getInstance();
userService.login("a", "a", new AsyncCallback<User>()
{
public void onFailure(Throwable caught)
{
throw new RuntimeException("Unexpected Exception occurred.", caught);
}
public void onSuccess(User user)
{
assertEquals("a", user.getUserName());
assertEquals("a", user.getPassword());
assertEquals(UserRole.Administrator, user.getRole());
assertEquals("Test", user.getFirstName());
assertEquals("User", user.getLastName());
assertEquals("canada#onlyinsight.com", user.getEmail());
// Okay, now this test case can finish.
finishTest();
}
});
// Tell JUnit not to quit the test, so it allows the asynchronous method above to run.
delayTestFinish(10 * 1000);
}
}
If your RPC instance doesn't have a handy getInstance() method, then add one:
public interface UserService extends RemoteService {
public User login(String username, String password) throws NotLoggedInException;
public String getLoginURL(OAuthProviderEnum provider) throws NotLoggedInException;
public User loginWithOAuth(OAuthProviderEnum provider, String email, String authToken) throws NotLoggedInException;
/**
* Utility/Convenience class.
* Use UserService.App.getInstance() to access static instance of UserServiceAsync
*/
public static class App {
private static final UserServiceAsync ourInstance = (UserServiceAsync) GWT.create(UserService.class);
public static UserServiceAsync getInstance()
{
return ourInstance;
}
}
}
I hope that helps.

Resources