Adding video in Allure Report using Allure jenkins plugin - protractor

I was trying various ways to embed a test run video in Allure Report plugin with Protractor.
we can do it if we add a video Folder inside the Allure Report folder and add the video path in the allure description . So then Allure displays and play the video in description part.
However, i wanted to achieve the same using the Allure Jenkins plugin. Can you please let me know if there is any way to embed and play the video in allure report generated using allure jenkins plugin.
I saw the Video on you tube where they are running video inside the Allure report in jenkins. But not sure how they have setup. Please help?
https://www.youtube.com/watch?v=74zD5q9DKTw

seems has no business of "jenkins plugin", you could rewrite the testngListener , and add the vedios with "Attachement"
#Override
public void onTestFailure(ITestResult result) {
super.onTestFailure(result);
String mp4 = store + "\\" + sessionId + ".mp4";
File file = new File(mp4);
if (file.exists()) {
attachRecord(mp4);
}
}
#Attachment(value = "record screen", type = "video/mp4")
private byte[] attachRecord(String mp4) {
System.out.println("mp4 -->" + mp4);
Path content = Paths.get(mp4);
InputStream is = null;
try {
is = Files.newInputStream(content);
} catch (IOException e) {
e.printStackTrace();
}
return is2ByeteArray(is);
}
public static byte[] is2ByeteArray(InputStream is) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while (true) {
try {
if (!((rc = is.read(buff, 0, 100)) > 0)) break;
} catch (IOException e) {
e.printStackTrace();
}
baos.write(buff, 0, rc);
}
return baos.toByteArray();
}

Related

Save and Load file in HoloLens using Unity editer

I'm trying to Save and Load Vector3 Coordinates in HoloLens App the program works on my laptop using unity but it will not save or load a file in the HoloLens.
Here is the program I am using to create the path for saving and loading. Any help would be appreciated.
public GameData Load()
{
string fullPath = Path.Combine(dataDirPath, dataFileName);
GameData loadedData = null;
if (File.Exists(fullPath))
{
try
{
string dataToLoad = "";
using (FileStream stream = new FileStream(fullPath, FileMode.Open))
{
using (StreamReader reader = new StreamReader(stream))
{
dataToLoad = reader.ReadToEnd();
}
}
loadedData = JsonUtility.FromJson<GameData>(dataToLoad);
}
catch (Exception e)
{
UnityEngine.Debug.LogError("Error occured when trying to load data from filr: " + fullPath + "\n" + e);
}
}
return loadedData;
}
public void Save (GameData data)
{
string fullPath = Path.Combine(dataDirPath, dataFileName);
try
{
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
string dataToStore = JsonUtility.ToJson(data, true);
using (FileStream stream = new FileStream(fullPath, FileMode.Create))
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(dataToStore);
}
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError("Error occured when trying to save data to file: " + fullPath + "\n" + e);
}
}
}
If I understand this correctly, you're debugging remotely. To clarify, your application cannot access files on HoloLens until you deploy it to HoloLens. And for how to access files on HoloLens, you can refer Create, write, and read a file - UWP applications | Microsoft Learn and Working with File on Hololens 2 (UWP to .NET).

Android 8 - FileProvider Uri opens a blank screen

I have the following code and it's only working on Android 7 and below. Android 8 only shows a blank file, I opened the pdf manually and works fine.
I have the following code and this is the repo:
private static final String SHARED_PROVIDER_AUTHORITY = BuildConfig.APPLICATION_ID + ".myfileprovider";
private static final String PDF_FOLDER = "pdf";
Bitmap bitmap = myCanvasView.getBitmap();
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(bitmap.getWidth(), bitmap.getHeight(), 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
Canvas canvas = page.getCanvas();
Paint paint = new Paint();
paint.setColor(Color.parseColor("#ffffff"));
canvas.drawPaint(paint);
bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), true);
document.finishPage(page);
// write the document content
File file = null;
try {
file = createFile();
document.writeTo(new FileOutputStream(file));
} catch (IOException e) {
e.printStackTrace();
showToast("Something wrong: " + e.toString());
}
// close the document
document.close();
Uri uri = getUriFrom(file);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(uri,"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
Where:
#NonNull
private Uri getUriFrom(File file){
if(Build.VERSION.SDK_INT >= 26) {
return FileProvider.getUriForFile(getApplicationContext(), SHARED_PROVIDER_AUTHORITY, file);
}
else{
return Uri.fromFile(file);
}
}
#NonNull
private File createFile() throws IOException {
if(Build.VERSION.SDK_INT >= 26){
final File sharedFolder = new File(getFilesDir(), PDF_FOLDER);
sharedFolder.mkdirs();
final File sharedFile = File.createTempFile(getFilename(), ".pdf", sharedFolder);
sharedFile.createNewFile();
return sharedFile;
}
else{
return new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ getFilename());
}
}
I found a solution for you. Just add flag Intent.FLAG_GRANT_READ_URI_PERMISSION to your intent:
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(uri,"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
I just tested it with your repo on Pixel 2 XL with Android 8.1 and got rid of this issue:
And got things working:
Hope this could help you! :)

Maven - Eclipse - Project I am trying to add an image to database , The image doesn't appear in my JSP page until i refresh the image

This is the Controller page in which i have added my Image Upload Section .
When I add the product image to my database using a multi-part file and when i am listing it , the product thumbnail appears , once i refresh the resources - only then the image is displayed when i list it .
let me know what i should do .
#RequestMapping(value="/saveProd", method=RequestMethod.POST)
public ModelAndView gotoSave(#ModelAttribute("prod")Product prod,ModelMap m, Model a)
{
MultipartFile file = prod.getFile();
String fileName = "";
String image="";
if(!file.isEmpty())
{
try
{
System.out.println("inside try");
fileName = file.getOriginalFilename();
byte[] filesize=file.getBytes();
BufferedOutputStream bout=new BufferedOutputStream(new FileOutputStream(new File("\\C:\\Users\\GOOD\\workspace\\fionazcosmetics\\src\\main\\webapp\\resources\\images\\" + fileName)));
bout.write(filesize);
bout.close();
image="/resources/images/"+fileName;
//r.setAttribute("img" ,image);
m.addAttribute("img", image);
System.out.println("upload sucess.."+image);
}
catch (IOException e) {
System.out.println("upload failed..");
e.printStackTrace();
}
}
List<Supplier> x = supplierservice.getList();
a.addAttribute("sList",x);
List<Category> abc = categoryservice.getList();
a.addAttribute("cList",abc);
productDAOservice.insertRow(prod,image);
List ls=productDAOservice.getList();
return new ModelAndView("productadd","listProd",ls);
}

File corrupted after uploading on server in GWT

I'm using gwtupload.client.MultiUploader to upload zip files on the server in GWT. Then on the server I transform zip file to array of bytes to insert into database. As the result 50% of files in database are corrupted. Here a little bit of my code.
#UiField(provided = true)
MultiUploader muplDef;
public MyClass(){
muplDef = new MultiUploader();
muplDef.setValidExtensions("zip");
muplDef.addOnFinishUploadHandler(onFinishUploaderHandler);
muplDef.addOnCancelUploadHandler(onCancelUploaderHander);
}
private final IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
#SuppressWarnings("incomplete-switch")
#Override
public void onFinish(IUploader uploader) {
switch (uploader.getStatus()) {
case SUCCESS:
attachZip = true;
}
}
};
private final IUploader.OnCancelUploaderHandler onCancelUploaderHander = new IUploader.OnCancelUploaderHandler() {
#Override
public void onCancel(IUploader uploader) {
attachZip = false;
}
};
Byte Array
String fileName = "D:\1.zip";
File f = new File(fileName);
byte[] edocBinary = new byte[(int) f.length()];
RandomAccessFile ff;
try {
ff = new RandomAccessFile(f, "r");
ff.readFully(edocBinary);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
My questions are: Files can be correpted even if I have OnFinishUploaderHandler and case:SUCCESS? There are other cases like ERROR, maybe this case will check the file? Or the problem is with the transformation to byte array? Can you provide me some advices, thanks.
As you said, you had two steps :
1- Uploading the zip file
2- Inserting the zip file in the database
If the step 1 is done correctly, you're gonna get a success showing that the file is transfered correcly from client to the server, what you do after that is not managed by GwtUpload.
So I guess the corruption happened when you try to insert the file in the database. If you are using MySQL Try this http://www.codejava.net/java-se/jdbc/insert-file-data-into-mysql-database-using-jdbc

GWT displaying image specified from servlet

I use a servlet to access a folder outside the web container to load some graphics to web application by using GWT. I use the following snippet in servlet to test the idea:
String s = null;
File inputFile = new File("C:\\Documents and Settings\\User\\My Documents\\My Pictures\\megan-fox.jpg");
FileInputStream fin = null;
try {
fin = new FileInputStream(inputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte c[] = new byte[(int) inputFile.length()];
try {
fin.read(c);
} catch (IOException e) {
e.printStackTrace();
}
try {
fin.close();
} catch (IOException e1) {
e1.printStackTrace();
}
String imgFolderPath = getServletContext().getRealPath("/")+"img";
File imgFolder = new File(imgFolderPath);
imgFolder.mkdir();
File newImage = new File("megan-fox.jpg");
FileOutputStream fout = null;
try {
fout = new FileOutputStream(newImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fout.write(c);
} catch (IOException e) {
e.printStackTrace();
}
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
boolean success = newImage.renameTo(new File(imgFolderPath, newImage.getName()));
The code in servlet reads the image file from the specified folder in hard disk, creates a new folder called 'img' in war folder and copies to it the jpg file. Then it returns to the client the path to the image (for now hardcoded as) '/img/megan-fox.jpg'.
The client then uses the Image class in GWT with the returned path-string to display the image, like in the following snippet:
public void onSuccess(String result) {
String myImage = result;
image = new Image(myImage);
RootPanel.get().add(image);
closeButton.setFocus(true);
}
I need to know if there is a way to achieve the same result without using the 'intermediate' step of creating a folder in the web container root (optional) and copying the file there in order to access it with Image GWT class and display it?
updated: The original servlet class.
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
// This method is called by the servlet container to process a GET request.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Get the absolute path of the image
ServletContext sc = getServletContext();
// i want to load the image in the specified folder (outside the web container)
String filename = sc.getRealPath("C:\\Documents and Settings\\User\\My Documents\\My Pictures\\megan-fox.jpg");
// Get the MIME type of the image
String mimeType = sc.getMimeType(filename);
if (mimeType == null) {
sc.log("Could not get MIME type of "+filename);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// Set content type
resp.setContentType(mimeType);
// Set content size
File file = new File(filename);
resp.setContentLength((int)file.length());
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = resp.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
// This is the method that is called from the client using GWT-RPC
public String greetServer(String input) throws IllegalArgumentException {
HttpServletRequest req = this.getThreadLocalRequest();
HttpServletResponse res = this.getThreadLocalResponse();
try {
doGet(req, res);
} catch (IOException e) {
e.printStackTrace();
}
// actually i dont know what that means but i thought i would have to returned something like the image's url?
return res.encodeURL("/img/image0.png");
}
}
I logically misused the method that was proposed to solve my problem. What is the correct way?
Sure, just have your servlet serve the image directly:
Set the Content-Type header to image/jpeg.
Write out image file contents to servlet response writer.
Here is an example.