App works in debugging mode, failes when ran directly - java

I have a testing application written in java-selenium. This app tests e-shop whether it is possible to buy products and many other functionalities.
Few days ago, I added a new functionality that tests whether the payment was successful. In case the order was not successful, "#errorBox" is added into the URL, therefore I am checking whether the URL consists of this sequence:
public void paymentCheck() {
String URL = driver.getCurrentUrl();
if (URL.contains("#errorBox")) {
data.put("paymentFailed", "true");
} else {
data.put("paymentFailed", "false");
}
}
If there is "#errorBox", paymentFailed = true is added to the dataset. Then I check its presence:
.paymentCheck();
if (dataRow.get("paymentFailed").equals("true")) {
resultLine.addTestResultLineItem(
new TestResultLineItemMessage("ERROR: Payment declined, transaction was not accepted.").setResult(Result.FAIL)
);
driver.quit();
}
And the problem is: When debugging, the check works just fine. When the app is ran directly, test fails because the application skips setting result as FAILED and does not kill the driver either.
Any ideas what is wrong here?
Any help is appreciated,
Thanks

When in debug model, some latency insert between each step, when run directly, we should add some sleep/wait before driver.getCurrentUrl() too.
From my experience, generally payment take little long time.

The script is working fine in debug mode and is failing in normal run. This is a clear indication of latency. Include Thread.sleep(seconds) in your code. Though it is not recommended to use thread.sleep(), it is a better option, since we don't know the nature of the application. Else you can try Implicit wait or explicit wait condition in your code.

Related

Selenium: Is it a good practice to kill and reopen browser after every test case

I have a test suite as follows
Filename: LoginTest.java
#Test(description = "send invalid username")
void loginWithIncorrectUsername(){}
#Test(description = "send invalid password")
void loginWithIncorrectPassword(){}
#Test(description = "send valid credentials")
void loginWithCorrectCredentials(){}
Should I create one browser and run all the above test cases or I should quit the browser and reopen it for every single test case?
I am trying with reopening the browser
Restarting the browser every time might use a lot of time, so reusing the session would be the better solution.
Althought, you might mind if the website recogises you (cookies), means you'll need to clear the cookies after a test case. For that, have a look at the offical documentation.

How to get latest logs on Azure Function after deployment

I am running an Azure Function on Java with EventHub trigger. Now the function receives 1000s of messages per min. It is becoming difficult to track your changes after deployment as the logs are showing one day old content. Now even though I have commented out certain lines and added other lines to verify my changes, after deployment it still shows the commented lines. When I observed it, those were old logs. Is there any way to change that? As I have to wait a long time to see my changes on kudu console.
Where do I change the settings, so that my changes will reflect on basis of current changes?
Update:
I am using below setup in host.json. So may be because of the property "initialOffsetOptions/type" my function is processing already processed events after each deployment. I have got this link Slow down EventHubTrigger in Azure Function but I am yet to test it. Any suggestion on this is welcome.
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"extensions": {
"eventHubs": {
"batchCheckpointFrequency": 5,
"eventProcessorOptions": {
"maxBatchSize": 256,
"prefetchCount": 512
},
"initialOffsetOptions": {
"type": "fromStart",
"enqueuedTimeUtc": ""
}
}
}
}
Now even though I have commented out certain lines and added other lines to verify my changes, after deployment it still shows the commented lines.
Make sure you check your deployment is done. And check for the Deployment history and last modified details of deployments in an Activity Log. (Resource Group -> Deployments -> Activity Log)
Is there any way to change that? As I have to wait a long time to see my changes on kudu console. Where do I change the settings, so that my changes will reflect on basis of current changes?
If you are using Consumption Plan, make sure you have to wait till your Function app restarts after deployment. After Deployment the Consumption Plan will take some time to sync the function trigger operation.
To avoid the problems, you can use the Premium App Service plan or enable Always On feature in your app service plan.

Connection problems with H2 when starting from Java and usage of dbunit

i want to start from my JUnit test an in memory db and fill it with data.
When i start the server via the h2.bat everything works fine for my JUnit test app.
But when i try to start the server form Java i get some sort of connection problems
(when i try to connect to the db by the webinterface i get the gui, but its functionallity is missing/wrong)
code to start the server in the #BeforeClass setup:
args = new String[] { "-tcpPort", "8082","-tcpAllowOthers"};
h2Server = Server.createTcpServer(args).start();
// i also tried the createWebServer but it didn't make any difference
code to open connection once:
String url = "jdbc:h2:tcp://localhost:8082/mem:db1";
h2Connection = DriverManager.getConnection(url,"SA","");
For some reason i either have no connection to the db but more likely there is some sort of connection but, like said i get some undefiend connection problems.
How could i try to achieve the same functionality as when running the h2.bat from cmdline?
Do i use wrong parameters on createserver?
Update 1:
I found the problem. It seems that the usage of dbUnit to inject my testdata closed my h2connection unexpectetly (still wondering why this did not happen when running the h2.bat cmdline).
I will try now to run the full in memory mode, if it works i will delete this question or write down the problems and solutions for other users.
Update 2:
It works now in full memory mode, i am not sure but for me the core problem seemed to be (which i did not expect) calling:
IDatabaseConnection dBUnitConnection = new DatabaseConnection(h2Connection);
....
dbUnitConnection.close()
also closed my h2connection.
Like said, this did not happen when i run the h2server from cmdline.

Inconsistent Results from javax.print library

I have a section of code within a Web App, running in Tomcat 5.0, that makes a call to the javax.print.PrintServiceLookup method lookupPrintServices(null, null). Previously, this code returned an array of substantial size, listing all the printers on the server as expected. Rather suddenly one day recently, it started behaving differently, now returning a zero-size array of no printers instead. Checking rather thoroughly, I was not able to determine what might have changed to cause this method to behave differently now than it did before.
I made a small, stand-alone test program that contained this same method call.
PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null);
System.out.println("Java Version: " + System.getProperty("java.version"));
System.out.println("Printers found:");
if (printers != null) {
for (PrintService printer : printers) {
if (printer != null) {
System.out.println(" " + printer.toString());
}
}
}
System.out.println("End");
Running this program, it reacted differently, returning the full list of printers. Double-checking, I put the same code (using logging statements instead of System.print statements) in the context initialization method of the Web App, and it still returns zero printers. The method returns different results depending on whether it is run from the web app war or the stand-alone jar.
Some of my colleagues suggested that it might have to do with the Security Manager, and indeed, the documentation for the PrintService class says that certain properties of a Security Manager can alter results from the method call. However, after adding some code to my test to retrieve and view the Security Manager, it appears that there is none in either case.
try {
if (sec != null) {
System.out.println(sec.toString());
sec.checkPrintJobAccess();
}
System.out.println("*-*-*-*-*Printer Access allowed!!");
}
catch (SecurityException e) {
System.out.println("*-*-*-*-*Printer NOT Access allowed!!");
}
The result is that the Security Manager is null in both cases.
Trying it on a different server, both the web app and the stand-alone jar versions of doing things return no printers. There is no consistency that I can find.
What is going on here? What is causing this javax method call to return different results in different situations? What could have changed about the web app to alter its behavior between one day and the next?
Try starting the server with this option -DUseSunHttpHandler=true to initiate the HTTP URL Connection with JDK API instead of server API.
Hope this works for you too.

setLocation() from UI.init() method

Is it possible to use getPage().setLocation(...) from the init() method of UI. I have to redirect user to external site, under certain conditions. So far, it does not work (Vaadin 7.0.2).
Here is the code example:
#Override
public void init(VaadinRequest request) {
if (myCondition)
getPage().setLocation("http://www.externalsite.com");
else {
....
}
}
That's strange that it isn't working for you... setLocation is all you need. Here is a working version: VaadinLocationRedirect. mvn package will build the widgetset, mvn jetty:run will host it. Let us know what the problem was if you figure it out.
Found my problem. I used old version of WidgetSet, which was left from 6.X times, and was not re-compiled with Vaadin 7. After I fixed it - it works fine.
Looks like you can call the open( URL ) method of the Window object to open another URL in the same or a new browser window to achieve the redirection to an external site.
As an alternative you can set the exit URL for the application via application.setExitUrl() call and then close the application by calling application.close() - your application session will be closed and browser redirected to the specified address.

Categories

Resources