Right strategy for checks made in #AfterTest method - java

I'm not sure if this is a suitable title for the problem. Please suggest.
We have end-to-end payments tests being run in several threads. (It is a mobile testing: Java, Appium, and TestNg) There are many countries and for each of them different payment methods need to be test.
Each test consists of:
logging in under a specific email address associated with a specific payment method and country
adding products to cart
choosing payment method
proceeding to payment and payment itself
Afterwards a page with total amount and order number info appears.
Then we go to inbox and compare the data from the page with the data in the email.
Delay to get email is about 30-60 sec. So each test need to wait for such amount of time. That doesn't make us happy.
So the idea is to collect all info (email-orderNumber-totalInfo) somewhere and check data match after all tests passed. As there are several threads being run so we come up with next ideas:
1.Adding specific ThreadContext for each thread in #BeforeTest method and then at the end of each test (when total info appears) save data to file name as ThreadContext.json
And then in #AfterTest method read data and check all emails at once per each thread.
But we faced with a problem that we need to keep json valid we need firstly read file then add new JsonObject and save altogether. Problem was with reading/writing to files. Sometimes exceptions occurred so some checks skipped.
Then we try to save it to csv files. But again exceptions appeared from time to time.
Now there is an idea to use ThreadLocals for keeping data and then use at the end. But I am not sure for stability and performance.
Could you please give your point of view which solution would be the best?

Related

My users are not logging out in Jmeter and only one user which has logged in at the end perform all the transaction

I was trying to write a load testing script, I have created one as well but the users I am passing are all not performing the transactions, I have used correlation to capture the UUID of users and have passed this UUID in all of the samplers, now when we are logged in the last user that comes from the login only that iser execute the transactions for 'n' number of times. Please can anyone tell me why this is happening and what can be the solution.
Your question is not very clear hence I can only provide a generic piece of advice:
Run your test with 2 virtual users and 2 iterations and inspect request and response details using View Results Tree listener, this way you will be able to ensure that your test is doing what it is supposed to be doing and if not - identify where the problem is
Check that all correlated/parameterized variables have their anticipated values using Debug Sampler
Check that there are no any suspicious entries in jmeter.log file
If after all you will still experience issues include comprehensive details into your question covering:
JMeter configuration
Expected behaviour (preferably with request/response details from the network tab of the real browser)
Actual behaviour (preferably with request/response details from the View Results Tree listener)

Java Cucumber: creating scenario outlines with dynamic examples

We have a test where basically we need to input a specific value in a web site and make sure another value comes out. The data of the input-output for this is stored in an XML file.
Now we can create a single Scenario that runs once and loops through, submitting each value however we run into some reporting problems, if 2 out of 100 pairs fail we want to know which ones and not just have an assertion error for the whole scenario.
We would get much clearer reporting using a Scenario Outline where all the values are in the examples table. then the scenario itself runs repeatedly and we can fail an individual set as an assertion error and have that kick back clearly in a report.
Problem: we do not want to hard code all the values from the xml into the .feature. it's noisy but also if the values change it's slow to update. we would rather just provide the XML parse it and go, if things change we just drop in an updated XML.
Is there a way to create dynamic examples where we can run the scenario repeatedly, one for each data case, without explicitly defining it in the examples table ?
Using Cucumber for this is a bad idea. You should test this functionality lower down your stack with a unit test.
At some point in your code, after the user has input their value, the value will be passed to a method/function that will return your answer. This is the place to do this sort of testing.
A cucumber test going through the whole stack will upwards of 3 orders of magnitude slower than a well written unit tests. So you could test thousands of pairs of values in your unit test in the time it takes to run one single cuke.
If you do this sort of testing in Cucumber you will quickly end up with a test suite that takes far too long to run, or that can only be run quickly at great expense. This is very damaging to a project.
Cuking should be about one happy path (The user can enter a value and see the result) and maybe a sad path (the user enters a bad value and sees an error/explanation). Anything else needs to be pushed down to unit tests.
The NoraUi framework does exactly what you want to do in your project. The NoraUi code is open source. If you have questions about this framework, you can post an issue with the tag "Question"

Sync AWS glacier storage changes with RDS

I am using S3 Lifecycle Rule to move objects to Glacier. Since objects will be moved to glacier storage I need to make sure my application RDS is also
updated with similar details.
As per my discussion over this thread AWS Lambda for objects moved to glacier, there is no way currently to generate SQS notification to get notified about object being moved to glacier.
Also, as per my understanding currently Lifecycle rule will be evaluated once in a day, but there is not specific time when this will happen in a day. If there was i was planning to have a scheduler which will run after that and update status of archived objects in RDS.
Is there a way that you can suggest which will be close enough to sync this status changes between AWS & RDS?
Let me know your feedback or if you need more information on this to understand use case.
=== My Current approach is as per below.
Below is exact flow that I have implemented, please review and let me know if there is anything that could have been done in better way.
When object is uploaded to system I am marking it with status Tagged and also capturing creation date. My Lifecycle rule is configured with 30 days from creation. So, I have a scheduler which calculates difference between today's date and object creation date for all objects with status Tagged, and check if diff is greater than equal to 30. If so, it updates status to Archived.
If user performs any operation on object with status Archived, we explicitly check in s3 whether object is actually moved to glacier or not. If not we perform operation requested. If moved to glacier we initiate restore process and wait for restore to finish to initiate operation requred.
I appreciate your thoughts and would like to hear your inputs on above approach that i have taken.
Regards.
If I wanted to implement this, I would set the storage class of the object inside my database as "Glacier/Archived" at the beginning of the day it is supposed to transition.
You already know your lifecycle policies, and, as part of object metadata, you also know the creation time of each object. Then it becomes a simple query, which can be scheduled to run every night at 12:00 AM.
You could further enhance your application by defining an algorithm that checks if an object has transitioned to Glacier today, at the moment when object access is requested, it would go and explicitly check if it is actually transitioned or not. If it is marked as Glacier/Archive for more than a day, then checking is no longer required.
Of course, if for any reason, the above solution doesn't work for you, it is possible to write a scanner application to continuously check the status of those objects that are supposed to transition at "DateTime.Today" and are not marked as Glacier/Archive yet.

Jbehave: I could get an example of Jbehave running and I have few questions on this.

Here is the example that I could get working. http://ivanz.com/2011/05/25/java-bdd-with-jbehave-and-watij-in-eclipse-with-junit/
Questions:
This example has one story. If i need to have more than one story,
Can i write it in the same file or should I create a new .story file
for every story that I have?
One story can have more than one scenarios, how to handle this kind of scenario
Please help...
Generally speaking, a story contains one or more scenarios about a specific behaviour/feature of the software.
For example, a "Login Story" handles all cases of a user trying to log in, with valid data, expired accounts, already logged in, and so forth. Trying to cover the logout feature is, pun intended, a different story.
Hence, by convention, one story file contains only the scenarios of one story. The framework does not limit you to put in the logout scenarios into the same story file handling the login scenarios, but there's only one block of narrative available.
It furthermore allows you to separate the corresponding steps better; e.g. the necessary binding steps for logout do not need to be available during the login story.
As for adding further scenarios into a story file, simply separate them with a new line and start with the "Scenario: " keyword.
e.g.:
Scenario: Successfull login
Given ...
When ...
Then ...
Scenario: Login with no password
Given ...

Convert Large Switch to Hash (Or Other Recommendation)

I currently have an Android application that displays a schedule for a ferry boat. The application can display the full schedule (just a giant list), but the selling point in the application is it will display when the next two ferries are departing and how long from the current time that departure is.
I am relatively new to Java and currently use large Switch() statements in my code. Basically it gets the current phone time and compares it to all of the times in the schedule at which point it displays the next two departure times and then calculates the difference between current time and the departure times.
I am sure that a switch statement is not the best idea for speed purposes as well as code changing purposes. For example if one time changes its a bunch of lines of code to go in and fix for that one time change. Also if the entire schedule changes everyone has to update their app for the time change to take effect. My ideal situation would be to store a file somewhere on my webserver that could be downloaded and inserted into a hashmap (I think is the correct term) that would load the new schedule if there was a time change.
Not sure how confusing this is, but it would be greatly appreciated if someone could explain how I might use a hashmap or something else you might recommend to get this task accomplished. Currently the variables are the two ferry terminals as well as the day of the week since the schedule changes per day (monday, tues-friday, saturday, sunday).
Below is a screenshot of the application so you can understand it if my post wasn't clear. Thank you in advance.
Screenshot:
Store the schedule objects in a sorted array. You can then binary search the array for the first value greater than the current time. You'll probably use some parent array consisting of the location and applicable day of the week.
You can easily write that kind of data structure to a file that is read & parsed by the application for updates instead of being compiled into the code.
Details of this? First, understand resources in Android. If no updated schedule exists, fall back to the default resource.
Second, use an HTTP head request to check if a newer file exists. If it does, parse, download & save state. Saving Android Activity state using Save Instance State.
Finally, XML is handy for data distribution, even if it's not fast. Everybody understands it and it's easy to update or hand off.
<ferry location=0 time=2045>
<day>1</day>
<day>2</day>
<day>3</day>
<day>4</day>
<day>5</day>
</ferry>
<ferry location=0 time=0800>
<day>6</day>
</ferry>
You will need something like a database to hold the schedule data. That will help you to seperate code from data. I'm not familiar with Android but i think there is a interface to sqlite database on the device.
Further, as this is an application on a small device you may connect to the schedule database on a server thru the internet connection. That way you have to maintain schedule data only in one place (on the server) and clients will use always up to date data.

Categories

Resources