How to manage failed tests in JUnit5 - webdriver

I'm migrating to JUnit5 and I'd like to know if there is an easy way in JUnit5 to know when a test failed or not, just like we had in JUnit4 with TestWatcher.
I did some research and found similar, but open questions, like this one:
https://github.com/junit-team/junit5/issues/542
Since most of them are quite old, I'm asking just in case there is a recent solution.
The idea is to be able to do a screenshot or add some message into my log. So, is there a listener or extension or something that quickly allows me to manage the webdriver test's failure/pass/skip?
Thanks in advance!

OK, thanks glytching.
It was harder than I expected, but finally made it. As you pointed me, we need to create an external class (e.g. WatcherExtension) implementing BeforeTestExecutionCallback and AfterTestExecutionCallback and then evaluate the exceptions using the context given by the extension.
In this class we can add something like this:
#Override
public void afterTestExecution(ExtensionContext extensionContext) throws Exception {
Method testMethod = extensionContext.getRequiredTestMethod();
Boolean testFailed = extensionContext.getExecutionException().isPresent();
if (testFailed) {
if (!TESTDATA.excluded.contains(testMethod.getName())) {
takeScreenshot(testMethod);
logErrorMessage("Test " + testMethod.getName() + " failed on " + getAppVersion() + " using " + TESTDATA.browser);
} else {
logInfoMessage("Test " + testMethod.getName() + " was skipped on " + getAppVersion() + " using " + TESTDATA.browser);
}
} else {
logInfoMessage(testMethod.getName() + " was successfully executed on " + getAppVersion() + " using " + TESTDATA.browser);
}
Finally, you need to add this annotation to your test classes:
#ExtendWith(WatcherExtension.class)
public class MyTest extends TestFactory {
#Test
public void testMyTest() { //whatever }
}
Personally, I think this is something really basic and should be directly implemented by JUnit5 in future versions.
Thanks!

Related

Offline routing is not working

I'd like to use the offline routing feature so I downloaded the MapPackage of my region. I know the download went well because I can zoom on towns in the region offline and all details are shown).
But when I try to compute a route on this region, it does not work, and I get no error message. The onCalculateRouteFinished callback is just never called.
I'm using RouteManager#calculateRoute method (as for online calculation). Should I be using something else to make it work ?
I'm using an evaluation license, is it related ?
Thank you
edit to answer marco's comment:
I'm using "bretagne" region in france/europe.
RouteOptions ro = new RouteOptions();
ro.setTransportMode(RouteOptions.TransportMode.TRUCK);
ro.setRouteType(RouteOptions.Type.FASTEST);
RoutePlan routePlan = new RoutePlan();
routePlan.setRouteOptions(ro);
-- addWaypoint (coord) called several times. all coords are in the bretagne region --
RouteManager routeManager = new RouteManager();
routeManager.calculateRoute(routePlan, new RouteManager.Listener(){
#Override
public void onProgress(int i) {
//Log.d(TAG, "progress " + index + ": " + i);
}
#Override
public void onCalculateRouteFinished(RouteManager.Error error, List<RouteResult> list) {
if (error != RouteManager.Error.NONE) {
Log.e(TAG, "Could not calculate route: " + error.name());
return;
}
if (list != null && list.size() > 0) {
-- do something with result --
}
}
Using TransportMode.CAR instead of TRUCK fixed the problem. As stated by marco in the comments, offline routing is only available for cars.

Consume a QAAWS with Visual Studio 2010

I been given a QAAWS and I need to pull out the data from it. For privacy issues I cannot give you the QAAWS but it is the same as this one.
I added the wsdl as a service reference, but I am not sure how to get the data since I have to enter the login and password. I can use SOAPUI and obtain an XML file that I can use but I want to make the process more automatic where I use the QAAWS with my website.
I haven't had any luck searching any good tutorials or guides. Has anyone dealt with these services before?
You can do the following:
In Visual Studio 10 create a new Console Application
Next add a web reference and use the web service WSDL URL given to you.
On the program.cs file write the following code (TestWeb here is the name of your Web Reference.):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using
ConsoleApplication1.TestWeb;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ConsoleApplication1.TestWeb.TestService test1 = new
ConsoleApplication1.TestWeb.TestService();
String message, creatorname, creationdateformatted, description, universe;
DateTime creationdate;
int queryruntime, fetchedrows;
ConsoleApplication1.TestWeb.Row[] row = test1.runQueryAsAService("<cms username>", "<password>", out message, out creatorname, out creationdate, out creationdateformatted, out description, out universe, out queryruntime , out fetchedrows);
int resultCount = row.Length;
Console.WriteLine("Message = " + message);
Console.WriteLine("Creator Name = " + creatorname);
Console.WriteLine("Creation Date = " + creationdate.ToString());
Console.WriteLine("Creation Date Formatted = " + creationdateformatted);
Console.WriteLine("Description = " + description);
Console.WriteLine("Universe = " + universe);
Console.WriteLine("Query Run Time = " + queryruntime);
Console.WriteLine("Fetched Rows = " + fetchedrows);
for (int i = 0; i < resultCount; i++)
{
Console.WriteLine(row[i].ShipperID + " " + row[i].CompanyName + " " + row[i].Phone);
}
Console.Read();
}
}
}
The username and the password can be written into the code if you want. This is originally from this page. I tested it against my own Web Service and it worked.

verification if record posts to multiple tables

i hope i have another simple question for someone out there.
im currently working on a website where i am having a user post information to the server and upon posting they are taken to a verification page that tells them if it successfully was stored on the .mbd table or not. I have had no problems with doing this for a single table but i seem to be running into a issue when wanting to verifing the information stored on multiple tables.
HERE is the code that im using THAT IS WORKING for posting to a SINGLE table
protected void Page_Load(object sender, EventArgs e)
{
txtVerifiedInfo.Text = Session["txtUserFirstName"].ToString() +
"\n" + Session["txtUserLastName"].ToString() +
"\n" + Session["txtUserName"].ToString() +
"\n" + Session["txtUserPassword"].ToString() +
;
// Check if the record is successfully saved in the tblUserLogin Table and prints the appropriate message in the text box txtVerifiedInfo
if (clsDataLayer.SavePersonnel(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["txtUserFirstName"].ToString(),
Session["txtUserLastName"].ToString(),
Session["txtUserName"].ToString(),
Session["txtUserPassword"].ToString(),
))
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was successfully saved!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe information was NOT saved.";
}
}
}
Here is what i have attempted with not much luck at all
if (clsDataLayer.Saveneworder(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["txtfirstName"].ToString(),
Session["txtlastName"].ToString(),
Session["txtstreetAddress"].ToString(),
Session["txtcity"].ToString(),
Session["txtzipCode"].ToString()))
&& if (clsDataLayer.Savenewitem(Server.MapPath("App_Data\\WSC_DB.mdb"),
Session["jobType"].ToString() +
Session["txtmediaContent"].ToString()))
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe Order successfully submitted!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you.";
}
}
}
I Imagine im not that close to doing this correctly but hopefully in the ball park.
any help with this would be great.
Thank you for your time
To simplify, this is roughly what you have now:
var path = Server.MapPath("App_Data\\WSC_DB.mdb");
if (clsDataLayer.Saveorder(path, [order parameters]
&& clsDataLayer.Saveitem(path, [item parameters])
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\nThe Order successfully submitted!";
}
else
{
txtVerifiedInfo.Text = txtVerifiedInfo.Text +
"\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you.";
}
The code you've presented is not well structured, in that there is an unnecessary call to Server.MapPath and the call may be better placed as part of an argument to the constructor of your datalayer class.
What you may not be aware of is the && is a shortcut operator - the second part of the argument will not be called if the first part fails. Is this the behaviour you want?
I suspect you want Saveorder AND Saveitem to succeed or fail together, as part of one transaction. That being the case, you might be better off writing a new method in your datalayer class that does exactly that.
I'm assuming the .mdb in your filename indicates you're using MS Access? I'm not sure if it deals with transactions as well as SQL server (for instance), so you might need to write your own code to remove the order if its item cannot be saved (or whatever on-failure behaviour you need).

Get all atributes names of an object

Let's say I have a class which looks like this :
public class MyClass
{
public var attribute1;
public var attribute2;
}
and I'd like to get attribute1 and attribute2 as strings. I tried this :
var test:MyClass = new MyClass();
for (var key:String in test)
{
trace(test[key]);
}
but it does not work, it never goes in the loop. How can I do what I want to do ?
Thanks
A for..in loop enumerates only dynamically added properties. Declared variables and methods of classes are not enumerated in for..in loops. This means that most classes in the ActionScript API will not display any properties in a for..in loop.
For a solution read:
http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_8.html
You'll need to use AS reflection/introspection.
The native way is using describeType function, like this:
public function getDetails():void {
var classInfo:XML = describeType(button1);
// List the class name.
ta1.text = "Class " + classInfo.#name.toString() + "\n";
// List the object's variables, their values, and their types.
for each (var v:XML in classInfo..variable) {
ta1.text += "Variable " + v.#name + "=" + button1[v.#name] +
" (" + v.#type + ")\n";
}
}
(from flex doc: http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_8.html)
I'm not sure but I think the class mx.utils.ObjectUtil can make it simpler. And it's still native way.
Another option is using a library to make it easier.
Look this one: http://www.as3commons.org/as3-commons-reflect/introduction.html

file cannot be deleted used by another process

when ever i try to delete this files some times i get this message
file cannot be deleted used by another process
even though file is not used by any other user
the code what i am using
try
{
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}
catch (FileNotFoundException ex) {
lblStatus.Text += ex.Message;
}
is there way we can assign a boolean value
here if true means i can display an message tellingfile is deleted successfully
boolean value is false
here if false means i can display an message telling file used by another process
can i write that condition here
File.Delete(MapPath(".") + "\\" + txtFile.Text);
any help would be great thank you
Based on my experience, if it says the file is being used by another process, the file is being used by another process, whatever you think...
Download ProcessExplorer to find out who the culprit is...
You can use the
FileInfo.Delete
method. If the file does not exist, this method does nothing.
Note
Also check for any other file handles that has locked this file, close them before deleting the file.
A bit late to the party I know, but hopefully these comments will help others out ->
The issue is not happening in Chrome, but is in IE6/7/8 and FF. This method is working for me now in those latter browsers:
try
{
System.IO.File.Delete(basePath + assetImage.Path);
}
catch
{
System.IO.File.Move(basePath + assetImage.Path, basePath + #"DELETE\ " + assetImage.Path);
}
Why don't you try
if (TheFile.Exists) {
TheFile.Delete();
}
?
If the Indexing Service is turned on, make sure this folder is excluded from the Index list.
If you want a method which just returns true if the file was deleted successfully, and false otherwise, I'd go with:
public bool DeleteFile(string fullPath) {
bool fileDeleted = false;
if (System.IO.File.Exists(fullPath))
{
try
{
System.IO.File.Delete(fullPath);
fileDeleted = true;
}
catch (UnauthorizedAccessException)
{
// File is open **or read only**
}
}
else
{
// File does not exist
}
return fileDeleted;
}

Resources