Selenium - Allure does not create screenshots - maven

I have a problem with connecting screenshots in the report generated by allure using jenkins.
1. I have an interface called ListenersT
package Test;
import Test.resources.Base;
import io.qameta.allure.Allure;
import io.qameta.allure.Attachment;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class ListenersT extends Base implements ITestListener {
Base b = new Base();
public void onFinish(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onStart(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
//screenshot
try {
b.getScreenshot(result.getName());
} catch (IOException e) {
e.printStackTrace();
}
Object testClass = result.getInstance();
WebDriver driver = ((Base) testClass).getDriver();
if(driver instanceof WebDriver) {
takeScreenshot(driver);
}
}
#Attachment
public byte[] takeScreenshot(WebDriver driver) {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}
public void onTestSkipped(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestStart(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestSuccess(ITestResult arg0) {
// TODO Auto-generated method stub
}
}
I have screenshot support attached here
In each test, the listener "#Listeners ({ListenersT.class})" has been added to the beginning.
#Listeners({ListenersT.class})
Still, I don't see screenshots in the generated report
Please help.

Related

How to Audit Spring data jpa #Query?

To Audit log all the DB changes , we have implemented Hibernate Interceptor(org.hibernate.Interceptor) .
We can able to log the audit for the query executed using JpaRepository
Interceptor We have used- Sample
import java.io.Serializable;
import java.util.Iterator;
import org.hibernate.CallbackException;
import org.hibernate.EntityMode;
import org.hibernate.Interceptor;
import org.hibernate.Transaction;
import org.hibernate.type.Type;
public class TestInterceptor implements Interceptor {
#Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
return false;
}
#Override
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void preFlush(Iterator entities) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public void postFlush(Iterator entities) throws CallbackException {
// TODO Auto-generated method stub
}
#Override
public Boolean isTransient(Object entity) {
// TODO Auto-generated method stub
return null;
}
#Override
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) {
// TODO Auto-generated method stub
return null;
}
#Override
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public String getEntityName(Object object) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getEntity(String entityName, Serializable id) throws CallbackException {
// TODO Auto-generated method stub
return null;
}
#Override
public void afterTransactionBegin(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public void beforeTransactionCompletion(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public void afterTransactionCompletion(Transaction tx) {
// TODO Auto-generated method stub
}
#Override
public String onPrepareStatement(String sql) {
// TODO Auto-generated method stub
return null;
}
}
But if we run the query via org.springframework.data.jpa.repository.Query that interceptor is not getting called.
Is this possible to Audit/Intercept the Query Executed using org.springframework.data.jpa.repository.Query
i.e I have the following Query in my Repository, this is not triggering Hibernate Interceptor
#Transactional
#Modifying
#Query("DELETE from MyEntity my where my.id =?1")
void deleteById(Long id);
To intercept spring data queries add this prop:
spring.jpa.properties.hibernate.session_factory.interceptor=com.yourpacakge.TestInterceptor
I used an interceptor class that extends from EmptyInterceptor just for simplicity.
public class MyInterceptor extends EmptyInterceptor {
#Override
public String onPrepareStatement(String sql) {
System.out.println("Query intercepted: " + sql);
return super.onPrepareStatement(sql);
}
}
DOCS: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-session-events

Spring Aspect: surround entire method with try catch

How can I create a Spring Aspect (annotation driven e.g. #ExceptionTranslation) surrounding an entire method and put this method in a try...catch method?
#ExceptionTranslation
public void method() {
// do some stuff here...
}
so logically it does:
public void method() {
try {
// do some stuff here ...
} catch( Exception ex ) {
}
}
Below you can find a sample implementation of AfterThrows advice solving your problem.
CustomException.java
package com.yourpackage;
public class CustomException extends Exception {
public CustomException(final Throwable cause) {
super(cause);
}
}
ErrorBean.java
package com.yourpackage;
public class ErrorBean {
#ExceptionTranslation
public void translatedException() throws Exception {
throw new Exception("Foo");
}
public void notTranslatedException() throws Exception {
throw new Exception("Bar");
}
}
ExceptionTranslation.java
package com.yourpackage;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface ExceptionTranslation {
}
SimpleThrowsAdvice.java
package com.yourpackage;
import org.springframework.aop.Advisor;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
public class SimpleThrowsAdvice implements ThrowsAdvice {
public static void main(String[] args) throws Exception {
ErrorBean errorBean = new ErrorBean();
AnnotationMatchingPointcut pc = AnnotationMatchingPointcut.forMethodAnnotation(ExceptionTranslation.class);
SimpleThrowsAdvice advice = new SimpleThrowsAdvice();
Advisor advisor = new DefaultPointcutAdvisor(pc, advice);
ProxyFactory pf = new ProxyFactory();
pf.setTarget(errorBean);
pf.addAdvisor(advisor);
ErrorBean proxy = (ErrorBean) pf.getProxy();
try {
proxy.translatedException();
} catch (CustomException ex) {
System.out.println("CustomException caught");
} catch (Exception ex) {
System.out.println("Exception caught");
}
try {
proxy.notTranslatedException();
} catch (CustomException ex) {
System.out.println("CustomException caught");
} catch (Exception ex) {
System.out.println("Exception caught");
}
}
public void afterThrowing(Exception ex) throws Throwable {
System.out.println("***");
System.out.println("Generic Exception Capture");
System.out.println("Caught: " + ex.getClass().getName());
System.out.println("***\n");
throw new CustomException(ex);
}
}

Apache flume custom interceptor - HDFS file in binary and strange

I am relatively new to the flume interceptors concept and facing an issue where before applying the interceptor the file sinked is normal text file and after applying the interceptor everything turns really bad.
My interceptor code as below -
package com.flume;
import org.apache.flume.*;
import org.apache.flume.interceptor.*;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class CustomHostInterceptor implements Interceptor {
private String hostValue;
private String hostHeader;
public CustomHostInterceptor(String hostHeader){
this.hostHeader = hostHeader;
}
#Override
public void initialize() {
// At interceptor start up
try {
hostValue =
InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
throw new FlumeException("Cannot get Hostname", e);
}
}
#Override
public Event intercept(Event event) {
// This is the event's body
String body = new String(event.getBody());
if(body.toLowerCase().contains("text")){
try {
event.setBody("hadoop".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// These are the event's headers
Map<String, String> headers = event.getHeaders();
// Enrich header with hostname
headers.put(hostHeader, hostValue);
// Let the enriched event go
return event;
}
#Override
public List<Event> intercept(List<Event> events) {
List<Event> interceptedEvents =
new ArrayList<Event>(events.size());
for (Event event : events) {
// Intercept any event
Event interceptedEvent = intercept(event);
interceptedEvents.add(interceptedEvent);
}
return interceptedEvents;
}
#Override
public void close() {
// At interceptor shutdown
}
public static class Builder
implements Interceptor.Builder {
private String hostHeader;
#Override
public void configure(Context context) {
// Retrieve property from flume conf
hostHeader = context.getString("hostHeader");
}
#Override
public Interceptor build() {
return new CustomHostInterceptor(hostHeader);
}
}
}
Flume conf is -
agent.sources=exec-source
agent.sinks=hdfs-sink
agent.channels=ch1
agent.sources.exec-source.type=exec
agent.sources.exec-source.command=tail -F /home/cloudera/Desktop/app.log
agent.sources.exec-source.interceptors = i1
agent.sources.exec-source.interceptors.i1.type = com.flume.CustomHostInterceptor$Builder
agent.sources.exec-source.interceptors.i1.hostHeader = hostname
agent.sinks.hdfs-sink.type=hdfs
agent.sinks.hdfs-sink.hdfs.path= hdfs://localhost:8020/bosch/flume/applogs
agent.sinks.hdfs-sink.hdfs.filePrefix=logs
agent.sinks.hdfs-sink.hdfs.rollInterval=60
agent.sinks.hdfs-sink.hdfs.rollSize=0
agent.channels.ch1.type=memory
agent.channels.ch1.capacity=1000
agent.sources.exec-source.channels=ch1
agent.sinks.hdfs-sink.channel=ch1
on doing a cat on the file created in HDFS -
SEQ!org.apache.hadoop.io.LongWritable"org.apache.hadoop.io.BytesWritable���*q�CJv�/ESmP�ź
some textP�żc
some more textP���K
textP��ߌangels and deamonsP��%�
text bla blaP��1�angels and deamonsP��1�
testP��1�hmmmP��1�anything
Any suggestions?
Thanks
Looks like nothing Wrong with Interceptor.
In your Flume Agent config.
You are not specifying this property (hdfs.fileType) so it is taking this as a default SequenceFile
Try adding this line to your HDFS SINK and let me know if this works.
agent.sinks.hdfs-sink.hdfs.fileType=DataStream

mouseClicked doesn't work while mouseMoved work

So I have a new project I work which I move in a room (panoramic picture). Now I want to open something on mouseClick. But when I try even to print something to the console in the mouseClick event it doesn't work.
package noam;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class room extends JPanel{
ImageIcon img;
int locationX=0,locationY=0;
int cp=0,cr=0,c=0;//cp clickpresed cr clickreleased c clicked
public room()
{
addMouseMotionListener(new MML());
//addMouseMotionListener(new ML());
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
img =new ImageIcon("VRpano.jpg");
Image s=img.getImage();
g.drawImage(s, locationX,locationY,img.getIconWidth(),img.getIconHeight(), null);
}
class MML extends MouseAdapter{
/*public void mousePressed(MouseEvent e) {
}*/
public void mouseMoved(MouseEvent e) {
if(e.getX()>1100){
if(locationX>-6350)
locationX-=20;
if(locationX<=-6350)
locationX=0;
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(e.getX()<200){
if(locationX<0)
locationX+=20;
if(locationX>=0)
locationX=-6300;
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
//System.out.println("x="+e.getX()+" y="+e.getY());
}
#Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
System.out.println("click!");
c++;
System.out.println(c);
}
#Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
super.mousePressed(e);
System.out.println("Pressed!");
cp++;
System.out.println(cp);
}
#Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseReleased(e);
System.out.println("Released!");
cr++;
System.out.println(cr);
}
}
/*public class ML extends MouseAdapter{
public void MOUSE_ENTERED(MouseEvent me){
System.out.println("click!");
}
}
#Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame("Asteroids MS Ver 1 (c) 2014");
room bp=new room();
f.add(bp);
f.setSize(1650,1080);
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
f.setVisible(true);
}
}

OSGI expose An "ClassNotFoundException: org.w3c.dom.***" Error when release

I only wrote the following codes in Activator.start() function
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Node node = new Node() {
#Override
public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
// TODO Auto-generated method stub
return null;
}
#Override
public void setTextContent(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setPrefix(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setNodeValue(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node removeChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public void normalize() {
// TODO Auto-generated method stub
System.out.println("normalize 方法调用");
}
#Override
public String lookupPrefix(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String lookupNamespaceURI(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean isSupported(String arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isSameNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isEqualNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isDefaultNamespace(String arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean hasChildNodes() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean hasAttributes() {
// TODO Auto-generated method stub
return false;
}
#Override
public Object getUserData(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getTextContent() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getPreviousSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getParentNode() {
// TODO Auto-generated method stub
return null;
}
#Override
public Document getOwnerDocument() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNodeValue() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public short getNodeType() {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getNodeName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getNextSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespaceURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getLastChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getFirstChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getFeature(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
#Override
public NodeList getChildNodes() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getBaseURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public NamedNodeMap getAttributes() {
// TODO Auto-generated method stub
return null;
}
#Override
public short compareDocumentPosition(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return 0;
}
#Override
public Node cloneNode(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public Node appendChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
};
node.normalize();
}
Everything goes well when run in eclipse environment, but, when release the product, ERRORS in log when runs:
Root exception:
java.lang.NoClassDefFoundError: org/w3c/dom/Node
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node
Anyone can give some help?
OSGi gives access to system packages but only java.* packages by default, this does not include other packages like: javax.net , javax.xml , com.sun
Thus it is necessary to specify any of such packages for OSGi framework to export them through the system bundle making them accessible to other bundles that import them.
To do that you need to set a configuration property with the additional packages required by your bundles, try setting it as a system property before starting the OSGi framework such that it picks up this property when it first starts.
Assuming you are on OSGi 4.2, that property would be configured like:
org.osgi.framework.system.packages.extra=org.w3c.dom
You may want to check the Apache Felix Framework Configuration Properties for more details, though this property is part of the OSGi spec and thus should be available in other implementations as well
Please update your question to include the bundle's MANIFEST.MF
It looks like org.w3c.dom is not implicitly provided in your production. Check the Import-Package header, may be you don't have Import-Package: org.w3c.dom
If you are using Equinox, you can edit the config.ini and add "org.w3c.dom" to org.osgi.framework.system.packages key and import the same packages in your MANIFEST.MF
in my case adding
org.osgi.framework.bootdelegation=xx...xxx,org.w3c.dom
solved my problem.

Resources