cucumber hook scenario.embed always create screenshot at project root - cucumber

In cucumber hook scenario.embed always create screenshot at my project root directory. I need it to create it different location
scenario.embed(screenshot, "image/png");
I create below code still no wayout:
File screenShot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// extracting date for folder name.
SimpleDateFormat dateFormatForFoldername = new SimpleDateFormat("yyyy-MM-dd");//dd/MM/yyyy
Date currentDate = new Date();
String folderDateFormat = dateFormatForFoldername.format(currentDate);
// extracting date and time for snapshot file
SimpleDateFormat dateFormatForFileName = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//dd/MM/yyyy
String fileDateFormet = dateFormatForFileName.format(currentDate);
String filefolder="./ScreenShots"+"/FailCase/"+folderDateFormat+"/";
// Creating folders and files
File screenshot = new File(filefolder+fileDateFormet+".jpeg");
FileUtils.copyFile(screenShot, new File(screenshot.getPath()));
byte[] fileContent = Files.readAllBytes(screenshot.toPath());
scenario.embed(fileContent, "image/png");
How to pass a directory path to embed funtion or override it?

#mpkorstanje - he is rightly pointed about it
As per his comment:
Use OutputType.BYTES and send the bytes directly to scenario.embed and write them directly to the screenshot file
But my issue was I am using mkolisnyk package and when I am using #AfterSuite annotation of it, it creating fail file images over root folder. seems bug in mkolisnyk package.
Mixing AfterSuite of testng and #ExtendedCucumberOptions of mkolisnyk works for me

Related

How to create an image import job using KTA SDK?

I am trying to create a job using SDK. Simple job with send email activity work like a charm!
But when I try to create a job with variables input folder to import few images it doesn't work at all. Am I missing very trivial settings ?
My process has classification activity & extraction activities
Variables : DefaultImportFolder
FYI : My process works fine if I set import settings -> import sources. That tells me there is no issue with my process process Smile. But when I try to run through console app with dynamic variables, it doesn't work.
Following is my sample code. Any help?
ProcessIdentity processIdentity = new ProcessIdentity
{
Name = "SDK TestProcess"
};
var jobService = new TotalAgility.Sdk.JobService();
JobInitialization jobInitialization = new JobInitialization();
InputVariableCollection variablesCollections = new InputVariableCollection();
InputVariable inputVariable = new InputVariable
{
Id = "DefaultImportFolder",
Value = #"\\FolderPath",
};
variablesCollections.Add(inputVariable);
inputVariable = new InputVariable
{
Id = "ExportSuccess",
Value = "true"
};
variablesCollections.Add(inputVariable);
var createJobAndProgress = jobService.CreateJob(sessionId, processIdentity, jobInitialization);
Console.WriteLine($"Job ID {createJobAndProgress.Id}");
As Suggested by Steve, tried with WithDocuments method Still no luck .....
JobWithDocumentsInitialization jobWithDocsInitialization = new JobWithDocumentsInitialization();
Agility.Sdk.Model.Capture.RuntimeDocumentCollection documentsCollection = new Agility.Sdk.Model.Capture.RuntimeDocumentCollection();
Agility.Sdk.Model.Capture.RuntimeDocument runtimeDoc = new Agility.Sdk.Model.Capture.RuntimeDocument
{
FilePath = #"FolderPath\abc.tif",
};
documentsCollection.Add(runtimeDoc);
jobWithDocsInitialization.Documents = documentsCollection;
var jobIdentity = jobService.CreateJobWithDocuments(sessionId, processIdentity, jobWithDocsInitialization);
Console.WriteLine($"Job ID {jobIdentity.Id}");
A folder variable represents a reference to a folder that already exists in the KTA database, so you can't just set a file path to the variable. When you create a job via an import source, it is creating the folder and documents as part of creating the job.
To do the same in your code, you would use one of the "WithDocuments" APIs such as CreateJobWithDocuments which has parammeters specific to importing documents into the process, including by file path.
As discussed in this other answer (Kofax TotalAgility Send a PDF Document to Jobs Queue (KTA)), you may want to look at the sample code that is included with the product (that most people don't realize is available), and also look at other API functions for more context on the parameters needed for the "WithDocuments" APIs mentioned above.

Accessing Local Resource (local directory- outside project) in Vaadin 14/RapidclipseX IMG component

How to access the local image file from my hard drive (outside project folder) in the image component (to make an image gallery)? How to write the path of the file? in Vaadin 14/RapidclipseX.
It only takes either path from the project or URL. In my project users have to upload the images and I want to make a gallery that will show the images.
I tried all the below way but didn't work:
D:\\Canavans\\Reports\\256456\\424599_320943657950832_475095338_n.jpg
D:\Canavans\Reports\256456\424599_320943657950832_475095338_n.jpg
code (Tried this way as well):
for(final File file: files)
{
System.out.println(file.getName());
this.log.info(file.getName());
this.log.info(file.getAbsolutePath());
final String path = "file:\\\\" + file.getAbsolutePath().replace("\\", "\\\\");
this.log.info(path);
final Image img = new Image();
img.setWidth("300px");
img.setHeight("300px");
img.setSrc("file:\\\\D:\\\\Canavans\\\\Reports\\\\256456\\\\IMG20171002142508.jpg");
this.flexLayout.add(img);
}
Please Help! Thanks in advance. Or is there any other way to create an image gallery?
Hmm as far as I know if you want to access resources outside the resource folder you can create a StreamResource and initialize the image with that. If you want to use the images "src" property then the file has to be inside one of Vaadin's resource folders (for example the 'webapp' folder).
Here is a simple example on how to create the image with a StreamResource:
final StreamResource imageResource = new StreamResource("MyResourceName", () -> {
try
{
return new FileInputStream(new File("C:\\Users\\Test\\Desktop\\test.png"));
}
catch(final FileNotFoundException e)
{
e.printStackTrace();
return null;
}
});
this.add(new Image(imageResource, "Couldn't load image :("));
Hope this helps :)

sopaui update wsdl from url using groovy

is it possible to update wsdl file dynamically from an url?
This code point to a path where there is a static wsdl file.
How can i modify the code at second line:
String projectName = "C:/Users/soapui-project.xml"
List<String> wsdlFiles = ["http://abc.zxc.io/wsdl/v1/?appname=abc version=1.0"]
UpdateWsdls updateWsdl = new UpdateWsdls(projectName)

Exception when open excel: File contains corrupted data

I am trying to read an excel with OpenXML.
What I did is simply as following:
private WorkbookPart wbPart = null;
private SpreadsheetDocument document = null;
public byte[] GetExcelReport()
{
byte[] original = File.ReadAllBytes(this.originalFilename);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(original, 0, original.Length);
using (SpreadsheetDocument excel = SpreadsheetDocument.Open(stream, true))
{
this.document = excel;
this.wbPart = document.WorkbookPart;
UpdateValue();
}
stream.Seek(0, SeekOrigin.Begin);
byte[] data = stream.ToArray();
return data;
}
}
I initialized this.originalFilename in the constructor. It is the filename ended with '.xlsx' which i created with excel 2010.
But this line of code
using (SpreadsheetDocument excel = SpreadsheetDocument.Open(stream, true))
gives the exception: Message: System.IO.FileFormatException: File contains corrupted data.
The StackTrace:
Does anyone know how to solve this problem? At the beginning, I didn't use the Stream, I just use SpreadsheetDocument.Open(filename, true). However, it turns out to be exactly the same exception.
I've tried to create a new .xlsx file, but it's still the same.
There is a MSDN page which describes the process of reading and writing Excel file using stream and open xml SDK.
http://msdn.microsoft.com/en-us/library/office/ff478410.aspx
Try extracting the document contents through zip application and check whether you are getting the standard folders inside like xl,docProps and _rels etc.,
This is a method to find whether the package is properly packaged as archive or not.
Hope this helps.

NetSuite SuiteScript to modify file in the file cabinet

We have files within the NetSuite file cabient which need to be updated (the url field has changed). I found the noted article on this site but there is no code example to perform the requested. It indicates to use the nlapiLoadFile and nlapiSubmitFile calls; would anyone be able to assist with a code example?
Link:
Can Netsuite Suitescript modify a file in the file cabinet?
Ya, it seems a bit odd. The only way I found is:
Load The File
Create a file handle with:
Set the file name to one that you intended.
Set the content to intended one
Set the folder and submit.
I have attached a code snippet
var file = nlapiLoadFile(file_id);
var content = file.getValue();
content = '...put your content...';
file = nlapiCreateFile(file.getName(), 'FILE TYPE', content);
file.setFolder(required_folder_id);
nlapiSubmitFile(file);
Hope this helps.
There is no special API function to edit an existing file, you could take the details of the existing file and create a new file with the same details but changing the data field only and deleting the old file.
var start = function(request, response)
{
var fileId = "107524";//get the existing file id
var file = nlapiLoadFile(fileId);
var data = file.getValue();
var name = file.getName();
var folderId = file.getFolder();
var fileType = file.getType();
nlapiDeleteFile(fileId);//delete the older file
data += ",this is the appended data";//change the data
var newFile = nlapiCreateFile(name, fileType, data);//create a new file with the same details
newFile.setFolder(folderId);
nlapiSubmitFile(newFile);//submit it
}
Do you mean file instead of field? If you use nlapiLoadFile(/path/file), you can then use getURL() to provide a link to that file.
NetSuite does not have a edit file kind of an API. You will have to load the original file, modify the contents as per your needs and then submit that data by creating a new file with same file name and inside the same folder. This simply overrides the existing file.
Here's the code sample:
var original = nlapiLoadFile(FILE_ID_OR_FILE_PATH_IN_FILE_CABINET);
var originalContent = original.getValue(); //Return the value (base64 encoded for binary types) of the file
var updated = nlapiCreateFile(original.getName(), FILE_TYPE, UPDATED_FILE_CONTENTS);
updated.setFolder(original.getFolder());
nlapiSubmitFile(updated);
I experienced a similar error when trying to modify a file using SuiteScript in Netsuite at the server-side. I was using the way explained in the documentation, where they say copying a new file through file.copy() with conflictResolution: file.ConflictResolution.OVERWRITE. However, that way didn't work for me as it neither created the file nor overwrote it. Finally, I use the following form to get it working:
...
let fileNew = file.create({
name: 'same_name_of_the_original_file',
fileType: file.Type.PLAINTEXT, // change it depending the file type you will create
contents: credentials.body,
});
fileNew.folder = folder_id;
let fileId = fileNew.save();
...
So, the key is to change the folder and saving it after the file is created. After that, saving the file would overwrite the original.

Resources