I'm looking for a way to set status on test steps and then on Scenarios that will be displayed in an HTML report using extent report. I'm using now Cucumber Java TestNG & Extent Reports and I set the status using Assertions:
Assert.fail(msg)
the issue for assert is that he throws Assertion Exceptions and I didn't found a way to suppress exceptions so I would like to set the status using extent like:
extentTest.log(Status.FAIL, msg);
The issue here is that you need to create the feature/scenario/test and I didn't found any documentation on this.
Hope you are looking for some methods which would print messages based on your requirement in HTML Reports generated by Extent. If so, then you would need to customize or write down method as per your need. I am attaching screen shot of HTML also a piece of code to give you vision how shall you proceed.
Like below method would add screen and message as well based on test failure. You can simply change testReport.get().fail to pass or warning based on your need.
public static synchronized void logFailed(String message) {
try {
testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "Exception Occured : Click on the link to see message"
+ "</font>" + "</b >" + "</summary>" + "<br>" + "<h6>" + "<b>" + BasePage.returnLocator(message) + "</b>"+ "</h6>" + "</br>" + message.replaceAll(",", "<br>")+"</details>"+" \n");
addScreenShotsOnFailure();
}
catch(Exception e) {
}
}
Related
I'm attempting to write a (very simple) Forge mod that watches for and alerts on chicken spawns, but the code refuses to work. Instead, it throws a NoSuchMethodException when I attempt to read the entity name.
My code is as follows:
#SubscribeEvent
public void OnEntityJoinWorld(EntityJoinWorldEvent event) {
if (!(event.getEntity() instanceof EntityChicken)) {
return;
}
Entity chicken = event.getEntity();
String message = "Chicken named " + chicken.getName() + " spawned at " + chicken.posX
+ "," + chicken.posY
+ "," + chicken.posZ
+ ".";
Minecraft.getMinecraft().thePlayer.addChatMessage(new TextComponentString(message));
LOGGER.info(message);
}
The specific error is:
java.lang.NoSuchMethodError: net.minecraft.entity.Entity.getName()Ljava/lang/String;
Both the Forge and Minecraft versions being used are the same, so either I'm overlooking something very simple, or this just isn't how I'm supposed to do what I'm trying to do. How can I fix this issue?
Be sure to compile your project using the Gradle build option as opposed to the jar option.
When using just jar, Gradle will not re-obfuscate all of Minecraft's code. In turn, this will cause it (obviously) not to be able to find the non-obfuscated methods and names.
Shouln't you use:
EntityChicken chicken = event.getEntity();
And then import EntityChicken?
EDIT:
your error is becouse when you do chicken.getName(), it wants to get the name of event.getEntity() and the type of event.getEntity() is set to Entity which gives the error. What you should do is change the type of event.getEntity() to EntityChicken, as said above
So I'm having trouble formulating the correct syntax for selecting this element from a webpage. Here is what the path looks like on the Inspect Element Interface on Firefox
And here's what my current code looks like:
Element prices = doc.select("body[class =en page-type-search page-type-group-shelf og ress] " +
"div#wrap " +
"div#main-wrap " +
"div#jalapeno-template " +
"div[class=zone zone3 wgrid-10of12 wgrid-6of8 wgrid-4of4] " +
"section#shelf-page " +
"div#shelf-thumbs " +
"div.shelf-thumbs " +
"div.price-current " +
"span.product-price-analytics").first();
String priceOne = prices.attr("data-analytics-value");
And just to be incredibly clear, the attribute that I'm wanting is the 'data-analytics-value' because it gives an exact price.
I think that I have all the correct syntax so what am I doing wrong? When I run the program it gives me a nullPointerException. Any help is appreciated!
[Update] I changed princeOne to doc.toString() and its saying the the web browser is not running javascript and that JavaScript is required to view the walmart website, any work arounds?
After trying with no luck using Android's WebView, I accidentally found a solution in setting my userAgent, all I did was change the
Jsoup.connect(url).get();
line to
Jsoup.connect(url).userAgent("YOUR_USER_AGENT_HERE").get();
and it worked like a charm. Thanks for the reply anyway Fred!
On Eclipse Luna, I need to programmatically build java projects and then retrieve the Problems View's records. I use the following code
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResource resource = workspace.getRoot();
IMarker[] markers = resource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
for (IMarker m : markers) {
System.out.println("Id: " + m.getId());
System.out.println("Message: " + m.getAttribute(IMarker.MESSAGE));
System.out.println("Source ID: " + m.getAttribute(IMarker.SOURCE_ID));
System.out.println("Location: " + m.getAttribute(IMarker.LOCATION));
System.out.println("Line Number: " + m.getAttribute(IMarker.LINE_NUMBER));
System.out.println("Marker: " + m.getAttribute(IMarker.MARKER));
}
The message and line number are printed correctly. But IMarker.SOURCE_ID returns "JDT" and IMarker.LOCATION is always null.
Anybody knows how can I get the data shown as "Resource" and "Path" on the Problems View? I cannot create any custom Marker view using MarkerSupportView. I need to access the existing Problems View in a programmatic way. Thank you for any suggestion.
Got it. Use getResource() instead of getAttribute().
The markers API is pretty flexible, you should read the documentation.
Long story short, there will be other attributes that you're not looking at. Try calling getAttributes and dumping them out.
I am dealing with the log forging issue for the code :
log.error("Request: " + req.getRequestURL() + " raised " + exception);
This element’s value (req.getRequestURL()) flows through the code without being properly
sanitized or validated, and is eventually used in writing an audit log in handleError
I tried to remove the \n\r characters but with no success.
I have gone through different sites searching for the same but did not find the helpful content.
Can anyone please explain the solution for this or a small guide to fix it.
Thanks
Use ESAPI library to protect log forging attack. Refer to
http://www.jtmelton.com/2010/09/21/preventing-log-forging-in-java/ for code reference.
String clean = message.replace( '\n', '_' ).replace( '\r', '_' );
if ( ESAPI.securityConfiguration().getLogEncodingRequired() ) {
clean = ESAPI.encoder().encodeForHTML(message);
if (!message.equals(clean)) {
clean += " (Encoded)";
}
}
I tried to get a multi-line message when there's an assert. e.g. I have the following code:
errLog = "ERROR! Account Name not found in result \n Expected Result: " + acctName + "\n" + "Actual Result: " + output + "\n";
assertTrue(errLog, output.contains(accountType));
Where output is retrieved from the application during runtime and acctName is some data got passed in.
The result I got is:
ERROR! Account Name not found in result Expected Result: Name123 Actual Result: My name is Name456 type:junit.framework.AssertionFailedError
The result I expected is:
ERROR! Account Name not found in result
Expected Result: Name123
Actual Result: My name is Name456
type:junit.framework.AssertionFailedError
I've looked up everywhere online but it seemed like every example I read is only for output single line message. So, is it not possible to do multi-line messages using the existing assert functions? I know I can probably rewrite the assert function to accomodate what I need but as a newbie in JUnit, I guess it doesn't hurt to ask around first. Thanks in advance
I suspect this might come down to your IDE - I just ran the following in IntelliJ IDEA 12:
#Test
public void testABC() {
assertTrue("This\nis\na\ntest", false);
}
and got back:
java.lang.AssertionError: This
is
a
test
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.assertTrue(Assert.java:43)
The simplest (and more readble) way would be to write a function which extracts the account type from output, and use that in an assert:
assertEquals(acctName, extractAccountNameFromOutput(output));
which would give you a standard JUnit output if the test fails. When a test fails, you want the output to be immediately understandable, so it's probably better not to change the default output style provided by JUnit.