I have a x.groovy and a y.groovy file in jenkins shared library under vars.
I need to use the output of a function in x.groovy as an input to a function y.groovy.
x.groovy looks somethins like this :
void testM(String msg) {
int paddingLen = 100
String bottomLine = '└'.padRight(paddingLen, '─') + '┘\n'
String topLine = '┌'.padRight(paddingLen, '─') + '┐\n'
String pM = topLine +
"|"+ msg.padRight(200) + "|\n" +
bottomLine
printf(pM)
}
def display(message) {
loadColors()
echo "${GREEN}[INFO] - $message ${NC}"
}
In the jenkinsfile I need to use it as display.testM("print something here").
How shall I do it.Please advice
Related
When using remote-webdriver instance of BrowserStack, only when ran in Jenkins, the failed screenshot is not attached to the report. please help. folder structure is ExtentReport\Screenshots
I tried Extent Report: Not able to see the screenshots on other machine
this but it's not resolve the issue.
public void onTestFailure(ITestResult result) {
testMap.get().fail(result.getThrowable());
//add screenshot for failed test.
WebDriver driver= WebDriverFactory.getDriver();
//experimental to get screenshot
driver = new Augmenter().augment(driver);
String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String destination = System.getProperty("user.dir") + "/ExtentReport/" + "/Screenshots/" + result.getMethod().getMethodName() + dateName + ".png";
File finalDestination = new File(destination);
try {
FileUtils.copyFile(source, finalDestination);
} catch (IOException e) {
e.printStackTrace();
}
testMap.get().addScreenCaptureFromPath(destination,result.getMethod().getMethodName());
}
Different operating systems use different characters as file and path separators. When our application has to run on multiple platforms, we need to handle these correctly.
To handle this issue Java provide File.separator.
So, instead of
String destination = System.getProperty("user.dir") + "/ExtentReport/" + "/Screenshots/" + result.getMethod().getMethodName() + dateName + ".png";
Try this:
String destination = System.getProperty("user.dir") + File.separator + "ExtentReport" + File.separator +"Screenshots" + File.separator + result.getMethod().getMethodName() + dateName + ".png";
To use it you will have to add this import
import java.io.File;
Based on the answer of ravi creed,
HTML : Unable to view the base64 image in html report
String base64Screenshot ="data:image/png;base64," + ((TakesScreenshot) Objects.requireNonNull(driver)).getScreenshotAs(OutputType.BASE64);
testMap.get().addScreenCaptureFromBase64String(base64Screenshot).getModel().getMedia().get(0);
I managed to solve this using above code.Once click on base64 img, it opens the actual screenshot.
I need to help with command "Ant clean all". I will try build one application of SAP Hybris, but, one class return de errors in to lines:
BOLDWEIGHT_BOLD cannot be resolved or is not a field
method with error:
#Override
public HSSFWorkbook createMDDExportFile(final List<JnJProductModel> products, final String fileName)
{
final String METHOD_NAME = "createMDDExportFile()";
LOGGER.info("JnJGTProductService" + Logging.HYPHEN + METHOD_NAME + Logging.HYPHEN + "Start of the method");
catalogVersionService.setSessionCatalogVersion(Jnjb2bCoreConstants.MDD_CATALOG_ID, Jnjb2bCoreConstants.ONLINE);
final String sheetName = "MDD_Products_Sheet_0";
final HSSFWorkbook excelWorkBook = new HSSFWorkbook();
final HSSFFont font = excelWorkBook.createFont();
ERROR=> font.setBoldweight(Font.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = excelWorkBook.createCellStyle();
style.setFont(font);
final HSSFSheet sheet = excelWorkBook.createSheet(sheetName);
sheet.autoSizeColumn(0);
final HSSFRow downloadDateHeader = sheet.createRow(0);
downloadDateHeader.createCell(0).setCellValue("Download date");
downloadDateHeader.getCell(0).setCellStyle(style);
final String currentTime = new Date().toString();
downloadDateHeader.createCell(1).setCellValue(currentTime);
/*
* final HSSFRow globalAccounHeader = sheet.createRow(1);
* globalAccounHeader.createCell(0).setCellValue("Global Account Name");
* globalAccounHeader.getCell(0).setCellStyle(style);
* globalAccounHeader.createCell(1).setCellValue(currentAccount);
*/
try
{
final String filepath = Config.getParameter(Jnjb2bCoreConstants.EXPORT_EMAIL_ATTACHMENT_PATH_KEY) + File.separator
+ fileName;
createMDDExcelFile(products, sheet, excelWorkBook, style, filepath);
final File file = new File(filepath);
createMedia(file);
}
catch (final Exception exception)
{
LOGGER.error("There was an error while trying to create the excel file for the catalog export", exception);
}
LOGGER.info("JnJGTProductService" + Logging.HYPHEN + METHOD_NAME + Logging.HYPHEN + "End of the method");
return excelWorkBook;
}
Your maven version having issue with the one Font interface you are accessing. You imported the wrong path of Font interface.
Check your Font interface contains BOLDWEIGHT_BOLD attribute or not ?
I have my Font interface at org.apache.poi.ss.usermodel.Font location.
I have used following code for file reading and writing.
private void StorePuzzleData ()
{
FileInfo fileInfo = new FileInfo (Application.persistentDataPath + "\\" + difficultyLevel + puzzleId + ".txt");
if (fileInfo.Exists)
fileInfo.Delete ();
string fileData = string.Empty;
foreach (CellInformation cellInfo in cellInfoList)
fileData += cellInfo.RowIndex + "#" + cellInfo.ColIndex + "#" + cellInfo.number + "#" + cellInfo.CellColor + "#" + cellInfo.CellDisplayColor + "#" + (cellInfo.IsGroupComplete ? 1 : 0) + ",";
StreamWriter streamWriter = fileInfo.CreateText ();
streamWriter.WriteLine (fileData);
streamWriter.Close ();
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
}
private void ReadPuzzleData ()
{
// format: rownumber, colnumber, number, cellcolor, celldisplaycolor, isgroupcomplete
StreamReader streamReader = File.OpenText (Application.persistentDataPath + "\\" + difficultyLevel + puzzleId + ".txt");
string fileData = streamReader.ReadLine ();
}
But I am getting following error in actual iOS device running. This code working correct in iMac as well in android device.
Please give me some suggestion what changes I need to do to make this correct.
It seems you're using Windows-style paths in a Unix-like (Apple Mac OS) environment. Notice that on windows you have paths with a backslash like
C:\Users\Maxi\Desktop
On Unix-like system however something like
/var/mobile/Containers
You notice that in your faulty path you have mixed forward and backward slashes, which makes the path invalid.
/var/mobile/Containers/Data/Application/2.....\debutan1.txt
The correct way to always generate the correct path is to use the Path.Combine(string, string) function. This will combine two paths using the correct directory path seperator, which can also be seperatly accessed through Path.DirectorySeparatorChar.
So, in order to make your code correct, you would do
using System.IO; /* must be imported */
private void StorePuzzleData ()
{
FileInfo fileInfo = new FileInfo (Path.Combine(Application.persistentDataPath, difficultyLevel + puzzleId + ".txt"));
if (fileInfo.Exists)
fileInfo.Delete ();
string fileData = string.Empty;
foreach (CellInformation cellInfo in cellInfoList)
fileData += cellInfo.RowIndex + "#" + cellInfo.ColIndex + "#" + cellInfo.number + "#" + cellInfo.CellColor + "#" + cellInfo.CellDisplayColor + "#" + (cellInfo.IsGroupComplete ? 1 : 0) + ",";
StreamWriter streamWriter = fileInfo.CreateText ();
streamWriter.WriteLine (fileData);
streamWriter.Close ();
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
}
private void ReadPuzzleData ()
{
// format: rownumber, colnumber, number, cellcolor, celldisplaycolor, isgroupcomplete
StreamReader streamReader = File.OpenText (Path.Combine(Application.persistentDataPath, difficultyLevel + puzzleId + ".txt"));
string fileData = streamReader.ReadLine ();
}
If this still gives an "Access denied" error it must be because of filepermissions. Post the output of ls -la <thatpath> then.
new to actionscript and looking at the GeolocationEvent.UPDATE examples, having some unexpected results with .appendText() and an array.push --I didn't know whether they might both be just the phone not keeping up with the updates?
first, the text problem is that it's overwriting rather than replacing the last write, so after a couple minutes of the app running on the phone, you can't read the numbers any more. --using this.removeChild() and then addChild() was about trying to get it to remove the last write before writing again.
and then second, the problem with the array is that it's outputting random .length numbers in the trace() --the length looks to occasionally reset to 2 before counting up again, and counts up to seemingly random numbers. I know that I don't want the overhead of an array in the final version, but I'm trying to learn from why it's not working.
I've commented out the different things I've tried --sorry if I've missed something basic here
var format:TextFormat = new TextFormat();
format.color = 0xff0066;
format.font = "Lucida Console";
format.size = 20;
var fl_GeolocationDisplay:TextField = new TextField();
fl_GeolocationDisplay.defaultTextFormat = format;
fl_GeolocationDisplay.x = 10;
fl_GeolocationDisplay.y = 20;
fl_GeolocationDisplay.selectable = false;
fl_GeolocationDisplay.autoSize = TextFieldAutoSize.LEFT;
//fl_GeolocationDisplay.text = "Geolocation is not responding. Verify the device's location settings.";
fl_GeolocationDisplay.text = " ";
addChild(fl_GeolocationDisplay);
var gpsArray:Array = [42.09646417];
if(!Geolocation.isSupported)
{
fl_GeolocationDisplay.text = "Geolocation is not supported on this device.";
}
else
{
var fl_Geolocation:Geolocation = new Geolocation();
fl_Geolocation.setRequestedUpdateInterval(60000); //android overrides setRequestedUpdateInterval()
fl_Geolocation.addEventListener(GeolocationEvent.UPDATE, fl_UpdateGeolocation);
fl_Geolocation.addEventListener(StatusEvent.STATUS, gpsStatusHandler);
}
function fl_UpdateGeolocation(event:GeolocationEvent):void
{
//gpsArray.push(event.latitude);
//gpsArray[gpsArray.length] = event.latitude;
gpsArray.unshift(event.latitude);
var speed:Number = event.speed * 2.23693629;
if (gpsArray[gpsArray.length - 2] != gpsArray[gpsArray.length - 1])
{
trace(gpsArray.length + "|" + gpsArray[gpsArray.length - 2] + "|" + gpsArray[gpsArray.length - 1]);
trace(gpsArray[1] + "|" + gpsArray[0]);
trace(gpsArray[gpsArray.length - 2] - gpsArray[gpsArray.length - 1]);
}
//this.removeChild(fl_GeolocationDisplay);
fl_GeolocationDisplay.parent.removeChild(fl_GeolocationDisplay);
//fl_GeolocationDisplay = null; //TypeError: Error #2007: Parameter child must be non-null.
addChild(fl_GeolocationDisplay);
fl_GeolocationDisplay.text = (event.latitude.toString() + " | " + event.timestamp.toString());
//fl_GeolocationDisplay.text = (event.latitude.toString() + "\n");
//fl_GeolocationDisplay.appendText(event.latitude.toString() + "\n");
//fl_GeolocationDisplay.appendText(event.longitude.toString() + "\n");
}
function gpsStatusHandler(event:StatusEvent):void {
if (fl_Geolocation.muted) {
fl_GeolocationDisplay.text = "Please verify the device's location settings.";
}
}
I really can't understand what it is that you are trying to do, I mean you say one thing but your code seem to say something different.
There is also a serious issue about where the different code snippets are located? It Seems like the top part is inside a constructor. And then the bottom part are their own functions? If that is the case, make sure that the constructor is not run multiple times (which seems to be the issue and explaining why items are "overwritten" on top of each other.
Also your question states something about appendText but it seems like you want to replace the text inside the textfield? AppendText will add extra text inside that text field.
Anyways, I did an implementation from your code that gets the "longitude|lattitude" from the update event and then appends these to the textfield on a new line. Maybe this is what you wanted to do? I commented out the gps-array since I had no idea what it was that you tried to achieve by doing this:
package {
import flash.events.GeolocationEvent;
import flash.events.StatusEvent;
import flash.sensors.Geolocation;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class Foobar extends MovieClip {
var gpsArray:Array = [42.09646417];
var format:TextFormat = new TextFormat();
var fl_GeolocationDisplay:TextField = new TextField();
var fl_Geolocation:Geolocation = new Geolocation();
public function Foobar() {
format.color = 0xff0066;
format.font = "Lucida Console";
format.size = 20;
fl_GeolocationDisplay.defaultTextFormat = format;
fl_GeolocationDisplay.x = 10;
fl_GeolocationDisplay.y = 20;
fl_GeolocationDisplay.selectable = false;
fl_GeolocationDisplay.autoSize = TextFieldAutoSize.LEFT;
//fl_GeolocationDisplay.text = "Geolocation is not responding. Verify the device's location settings.";
fl_GeolocationDisplay.text = " ";
addChild(fl_GeolocationDisplay);
if(!Geolocation.isSupported) {
trace("unsupported");
fl_GeolocationDisplay.text = "Geolocation is not supported on this device.";
} else {
trace("supported");
fl_Geolocation.setRequestedUpdateInterval(500); //android overrides setRequestedUpdateInterval()
fl_Geolocation.addEventListener(GeolocationEvent.UPDATE, fl_UpdateGeolocation);
fl_Geolocation.addEventListener(StatusEvent.STATUS, gpsStatusHandler);
}
}
function fl_UpdateGeolocation(event:GeolocationEvent):void {
/*gpsArray.unshift(event.latitude);
var speed:Number = event.speed * 2.23693629;
if (gpsArray[gpsArray.length - 2] != gpsArray[gpsArray.length - 1]) {
trace(gpsArray.length + "|" + gpsArray[gpsArray.length - 2] + "|" + gpsArray[gpsArray.length - 1]);
trace(gpsArray[1] + "|" + gpsArray[0]);
trace(gpsArray[gpsArray.length - 2] - gpsArray[gpsArray.length - 1]);
}*/
fl_GeolocationDisplay.appendText(event.latitude.toString() + "|" + event.longitude.toString() + "\n");
}
function gpsStatusHandler(event:StatusEvent):void {
if (fl_Geolocation.muted) {
fl_GeolocationDisplay.text = "Please verify the device's location settings.";
}
}
}
}
I'm trying to add a frame script via:
private function addFrameScript(mc:MovieClip, label:String, func:Function, arg:*):void {
var labels:Array = mc.currentLabels;
var i:int = labels.length;
while (--i > -1) {
if (FrameLabel(labels[i]).name == label) {
mc.addFrameScript(FrameLabel(labels[i]).frame-1, func(arg));
return;
}
}
trace("WARNING: The label '" + label + "' does not exist in the MovieClip '" + mc.name + "'");
}
private function dispatchFrameEvent(labelName:String):void {
dispatchEvent(new Event(labelName, true));
}
addFrameScript(instanceName, "end", dispatchFrameEvent, "end");
But it doesn't seem to be adding and I can't figure out why. Normally I add Frame scripts to the main timeline, but not to an instance on the timeline (as in the example above).
Clearly there's something I'm missing...is there a way to trace out my frame script to see if it's even being added?
The problem here is that addFrameScript functions being added take no arguments. so whatever func you are passing in must must return a function with no arguments
so your dispatchFrameEvent should look like this
private function dispatchFrameEvent(labelName:String):Function {
return function func():void{
dispatchEvent(new Event(labelName, true));
}
}