Detail Hudson test reports - testing

Is there any way to force Hudson to give me more detailed test results - e.g. I'm comparing two strings and I want to know where they differ.
Is there any way to do this?
Thank you for help.

You should not hope Hudson give the detail information, it just shows the testing messages generated by junit.
You could show the expected string and actual string when failing asserting equals between those two strings.
For example,
protected void compareFiles(File newFile, String referenceLocation, boolean lineNumberMatters) {
BufferedReader reader = null;
BufferedReader referenceReader = null;
List<String> expectedLines = new ArrayList<String>();
try {
referenceReader = new BufferedReader(new InputStreamReader(FileLocator.openStream(Activator.getDefault().getBundle(), new Path("data/regression/" + referenceLocation), false))); //$NON-NLS-1$
expectedLines = getLinesFromReader(referenceReader);
} catch (Exception e) {
assertFalse("Exception occured during reading reference data: " + e, true); //$NON-NLS-1$
}
List<String>foundLines = new ArrayList<String>();
try {
reader = new BufferedReader(new FileReader(newFile));
foundLines = getLinesFromReader(reader);
} catch (Exception e) {
assertFalse("Exception occured during reading file: " + e, true); //$NON-NLS-1$
}
boolean throwException = expectedLines.size() != foundLines.size();
if (throwException) {
StringBuffer buffer = new StringBuffer("\n" + newFile.toString()); //$NON-NLS-1$
for (String line: foundLines)
buffer.append(line + "\n"); //$NON-NLS-1$
assertEquals("The number of lines in the reference(" + referenceLocation + ") and new output(" + newFile.getAbsolutePath()+ ") did not match!" + buffer, expectedLines.size(), foundLines.size()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
if (!lineNumberMatters) {
Collections.sort(expectedLines);
Collections.sort(foundLines);
}
/** Either the line matches character by character or it matches regex-wise, in that order */
for (int i=0;i<expectedLines.size(); i++)
assertTrue("Found errors in file (" + newFile + ")! " + foundLines.get(i) + " vs. " + expectedLines.get(i), foundLines.get(i).equals(expectedLines.get(i)) || foundLines.get(i).matches(expectedLines.get(i))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

Hudson supports JUnit directly. On your job configuration page, near the end, should be an option to "Publish JUnit test results report".
I'm not too familiar with JUnit itself, but I guess it produces (or has the ability to produce) and put results in an xml file. You just need to put the path of to the xml file (relative to the workspace) in the text box.
Once you do that, and create a build, you'll have a detailed report on your project page. You should then be able to click your way through the results for each test.

Related

Getting 3rd party software disturbance in selenium automation

I am using selenium to automate. I have also integrated Asprise OCR in my automation to scan texts and this is my code
{
Ocr.setUp();
Ocr ocr = new Ocr();
ocr.startEngine("eng", Ocr.SPEED_FASTEST); // English
String path = "C:\\Users\\Vishalpatel\\Desktop\\screen\\captcha.png";
String text = ocr.recognize(new File[] { new File(path) },Ocr.RECOGNIZE_TYPE_TEXT, Ocr.OUTPUT_FORMAT_PLAINTEXT);
System.out.println(text+" my code");
text = text.replace("x", " ");
text = text.replace(" ", "");
CharSequence str1= text.subSequence(0, 1);
CharSequence str2= text.subSequence(2, text.length()-1);
int x = Integer.parseInt((String) str1) + Integer.parseInt((String) str2);
ocr.stopEngine(); // Stop OCR engine
return x+"";
}
My scipt get stuck on this dialog and I have to handle it manually. Any idea to handle such issue? Thank you in advance

Plc4x addressing system

I am discovering the Plc4x java implementation which seems to be of great interest in our field. But the youth of the project and the documentation makes us hesitate. I have been able to implement the basic hello world for reading out of our PLCs, but I was unable to write. I could not find how the addresses are handled and what the maskwrite, andMask and orMask fields mean.
Please can somebody explain to me the following example and detail how the addresses should be used?
#Test
void testWriteToPlc() {
// Establish a connection to the plc using the url provided as first argument
try( PlcConnection plcConnection = new PlcDriverManager().getConnection( "modbus:tcp://1.1.2.1" ) ){
// Create a new read request:
// - Give the single item requested the alias name "value"
var builder = plcConnection.writeRequestBuilder();
builder.addItem( "value-" + 1, "maskwrite:1[1]/2/3", 2 );
var writeRequest = builder.build();
LOGGER.info( "Synchronous request ..." );
var syncResponse = writeRequest.execute().get();
}catch(Exception e){
e.printStackTrace();
}
}
I have used PLC4x for writing using the modbus driver with success. Here is some sample code I am using:
public static void writePlc4x(ProtocolConnection connection, String registerName, byte[] writeRegister, int offset)
throws InterruptedException {
// modbus write works ok writing one record per request/item
int size = 1;
PlcWriteRequest.Builder writeBuilder = connection.writeRequestBuilder();
if (writeRegister.length == 2) {
writeBuilder.addItem(registerName, "register:" + offset + "[" + size + "]", writeRegister);
}
...
PlcWriteRequest request = writeBuilder.build();
request.execute().whenComplete((writeResponse, error) -> {
assertNotNull(writeResponse);
});
Thread.sleep((long) (sleepWait4Write * writeRegister.length * 1000));
}
In the case of modbus writing there is an issue regarding the return of the writer Future, but the write is done. In the modbus use case I don't need any mask stuff.

Is it possible to run commands in Katalon?

Katalon is popular in automation testing. I have already used it in our project and it works amazingly.
Now, What I want to achieve is to create a test case where it opens a terminal (using mac) and type in some commands to run it like for example:
cd /documents/pem/key.pem
connect to -my server via SSH#method
sudo su
yum install php7
yum install mysql
You are not alone, and with custom keywords you can achieve what you want. Here is an example showing a test of a command line app. You could do the same thing to call any command line script you wish. Think of a runCmd keyword, or a runCmdWithOutput to grab the output and run various asserts on it.
#Keyword
def pdfMetadata(String input) {
KeywordUtil.logInfo("input: ${input}")
def csaHome = System.getenv("CSA_HOME")
def cmd = "cmd /c ${csaHome}/bin/csa -pdfmetadata -in \"${projectPath}${input}\"";
runCmd(cmd)
}
def runCmd(String cmd) {
KeywordUtil.logInfo("cmd: ${cmd}")
def proc = cmd.execute();
def outputStream = new StringBuffer();
def errStream = new StringBuffer()
proc.waitForProcessOutput(outputStream, errStream);
println(outputStream.toString());
println(errStream.toString())
if(proc.exitValue() != 0){
KeywordUtil.markFailed("Out:" + outputStream.toString() + ", Err: " + errStream.toString())
}
}
You can then use this in a test case:
CustomKeywords.'CSA.pdfMetadata'('/src/pdf/empty.pdf')
Here is another custom keyword! It is takes the file name and path, and if you don't give it a path, it search for the file in the project root directory. It export the batch file's output in a batch_reports folder in your project folder, you need to create that in advance.
#Keyword
def runPostmanBatch(String batchName , String batchPath){
// source: https://www.mkyong.com/java/how-to-execute-shell-command-from-java/
String firstParameter = "cmd /c " + batchName;
String secondParameter = batchPath;
if (batchPath == ""){
secondParameter = RunConfiguration.getProjectDir();
}
try {
KeywordUtil.logInfo("Executing " + firstParameter + " at " + secondParameter)
Process process = Runtime.getRuntime().exec(
firstParameter , null, new File(secondParameter));
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
int exitVal = process.waitFor();
Date atnow = new Date()
String now = atnow.format('yy-MM-dd HH-mm-ss')
String report_path = RunConfiguration.getProjectDir() + "/postman_reports/" + RunConfiguration.getExecutionSourceName() + "_" + now + ".txt"
BufferedWriter writer = new BufferedWriter(new FileWriter(report_path));
writer.write(output.toString());
writer.close();
KeywordUtil.logInfo("postman report at: " + report_path)
if (exitVal == 0) {
println("Success!");
println(output);
KeywordUtil.markPassed("Ran successfully")
} else {
KeywordUtil.markFailed("Something went wrong")
println(exitVal);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
I've done some research. I did not found any resources or any people that is looking for the same thing I am. I think this is officially, No. The answer to this is, it is not possible.
It is possible to run Katalon Studio from the command line.
There's a short tutorial here.
And it will be possible to override Profile Variables via command line execution mode from v5.10 (currently in beta).
An example given on Katalon forum is:
Simply pass the parameters in command line using: -g_XXX = XXX
Below is an example of override an URL variable:
-g_URL=http://demoaut.katalon.com

Converting XDP to PDF using Live Cycle replaces question marks(?) with space at multiple places. How can that be fixed?

I have been trying to convert XDP to PDF using Adobe Live Cycle. Most of my forms turn up good. But while converting some of them, I fine ??? replaced in place of blank spaces at certain places. Any suggestions to how can I rectify that?
Below is the code snippet that I am using:
public byte[] generatePDF(TextDocument xdpDocument) {
try {
Assert.notNull(xdpDocument, "XDP Document must be passed.");
Assert.hasLength(xdpDocument.getContent(), "XDPDocument content cannot be null");
// Create a ServiceClientFactory object
ServiceClientFactory myFactory = ServiceClientFactory.createInstance(createConnectionProperties());
// Create an OutputClient object
FormsServiceClient formsClient = new FormsServiceClient(myFactory);
formsClient.resetCache();
String text = xdpDocument.getContent();
String charSet = xdpDocument.getCharsetName();
if (charSet == null || charSet.trim().length() == 0) {
charSet = StandardCharsets.UTF_8.name();
}
byte[] bytes = text.getBytes();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Document inTemplate = new Document(byteArrayInputStream);
// Set PDF run-time options
// Set rendering run-time options
RenderOptionsSpec renderOptionsSpec = new RenderOptionsSpec();
renderOptionsSpec.setLinearizedPDF(true);
renderOptionsSpec.setAcrobatVersion(AcrobatVersion.Acrobat_9);
PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();
pdfFormRenderSpec.setGenerateServerAppearance(true);
pdfFormRenderSpec.setCharset("UTF8");
FormsResult formOut = formsClient.renderPDFForm2(inTemplate, null, pdfFormRenderSpec, null, null);
Document xfaPdfOutput = formOut.getOutputContent();
//If the input file is already static PDF, then below method will throw an exception - handle it
OutputClient outClient = new OutputClient(myFactory);
outClient.resetCache();
Document staticPdfOutput = outClient.transformPDF(xfaPdfOutput, TransformationFormat.PDF, null, null, null);
byte[] data = StreamIO.toBytes(staticPdfOutput.getInputStream());
return data;
} catch(IllegalArgumentException ex) {
logger.error("Input validation failed for generatePDF request " + ex.getMessage());
throw new EformsException(ErrorExceptionCode.INPUT_REQUIRED + " - " + ex.getMessage(), ErrorExceptionCode.INPUT_REQUIRED);
} catch (Exception e) {
logger.error("Exception occurred in Adobe Services while generating PDF from xdpDocument..", e);
throw new EformsException(ErrorExceptionCode.PDF_XDP_CONVERSION_EXCEPTION, e);
}
}
I suggest trying 2 things:
Check the font. Switch to something very common like Arial / Times New Roman and see if the characters are still lost
Check the character encoding. It might not be a simple question mark character you are using and if so the character encoding will be important. The easiest way is to make sure your question mark is ascii char 63 (decimal).
I hope that helps.

Podio java API how to download an Excel Spreadsheet

I am trying to download an Excel file from Podio space. I get access to space and get the files within space and the using fileAPI .
The problem is with the file that gets downloaded. I am not able to open it with Excel.
Here is the code:
List <File> aFileList = aFileAPI.getOnSpace(spaceId, null, null);
for (int i=0; i<aFileList.size(); i++){
File thisFile = aFileList.get(i);
MimeType thiFileMimeType = thisFile.getMimetype();
System.out.println("thisFile = " +thisFile.toString());
System.out.println("thisFile.getDescription() =" + thisFile.getDescription());
System.out.println("thisFile.getName() =" + thisFile.getName());
System.out.println("thisFile.getId() =" + thisFile.getId());
System.out.println("thisFile.getSize() =" + thisFile.getSize());
System.out.println("thisFile.getCreatedOn() =" + thisFile.getCreatedOn());
System.out.println("thisFile.getMimetype() =" + thisFile.getMimetype());
try {
aFileAPI.downloadFile(thisFile.getId(), new java.io.File("C:/Users/alisa/Desktop/"+ thisFile.getName()), null);
}
catch (IOException e) {
e.printStackTrace();
}
I think the API is creating the file without regard to MIME and I don't see anywhere to set it. Please help!!