Selenium webdriver and database testing - java

I was looking for the answer on the Internet and I haven't found one so... the thing is: I'm writing automated tests (in java) using selenium and the website that I'm testing has an option of phone number confirmation.
The user types his phone number, clicks save and to that phone number, we get confirmation code (with an SMS). My question is: how can I test it? Is there any option where I can create a database only for tests or something?

There is no way of knowing if your phone has just received a text from a specific number, without your phone being involved in the process.
To cascade test cases like this:
assertThat(phoneNoEntered);
assertThat(smsReceived);
You need to work with the gateway being used to send SMS. Because honestly, your test scope should be limited from "phoneNo entered" to "Gateway Fired an sms to that number". You don't wanna waste time on deciding if the Phone Subscription service honored your gateway's request, often it depends on user's subscription service.
So find out about the getway, find out if it provides a REST api, and then automate test like this: assertThat(gatewaySmsId == SOME_IDENTIFIER);

Related

Right strategy for checks made in #AfterTest method

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?

How to specify that user has shared my app x number of times or not?

I am working on android app that asking users to share this app to ten users to get a bonus. App can be shared via any app appearing in dialog. Now the problem is, I cannot determine that user has successfully shared my app to x number of users.
The simple code that I am using to share app is following.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "playstore link");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_app_text));
startActivity(Intent.createChooser(sharingIntent, "Share app via"));
I think the best you could get is: find a way to understand whether that "sharing" was actually succesfull (which could basically mean: in the end, the user clicked some OK button).
Then, persist that information.
In other words: you basically need a counter that gets stored, for example using Android's shared preferences (see here for a simple example).
The real problem might be that the "sharing" could be tricked easily. You know, like simply sharing to the same person on Facebook 10 times.
So, if you want something that is less easy to trick, you probably should count something else, like: you create a specific URL on a server of yours, and you count how many times that is visited (from different IPs for example).
Use UTM source.
1) Embade a UTM key unique to a particular user to the redirection URL.
2) when the user clicks on the share button, open that URL.
3) Host an HTML page at the server which opens from the aforesaid URL which will read that UTM code, create a mapping for that install and will redirect the user to the play-store URL.
If you actually want to track if users installed an app after they received a shared link, you should give Firebase Invites a try. This is probably the most elegant way if you don't want to develop this functionality on your own.

How to get total number of authenticated web hits?

I am using Google Analytic API in java to get Google data for one of the website where my Google account is registered. I am able to get total number of hits between two specific dates, But I want to retrieve total number of authenticated web hits. I am not getting any proper way to get this data using Google Analytic.
The function that I have written for getting for number of hits is:
private static GaData getWebHitsByMonth(Analytics analytics, String profileId) throws IOException
{
return analytics.data().ga().get(profileId, "2013-07-01", currentDate, "ga:hits")
.setDimensions("ga:yearMonth")
.execute();
}
Can someone give me an idea about this?
Since Google Analytics has no way of knowing whether or not a user is authenticated, you have to tell it. There are two ways to approach sending this information to Google Analytics: the first (easier) is with a custom dimension, and the second (more involved, but more useful) is by using the User ID feature.
If you go the route of using a custom dimension, you'll basically just have to set that on your tracker object as soon as you know that a user is logged in. Assuming this is the first custom dimension you've made, the code might look like this.
// Set that the user is logged in.
ga('set', 'dimension1', true);
Now all subsequent hits sent to GA will include this value. (Note: you'll want to set it to false if the user logs out.)
To report on that data, you can use a filter to limit the returned results to only authenticated hits. It might look something like this: filter=ga:dimension1==true.
The second option is to use the User ID feature. The User ID is another dimension, and it allows you to track logged in users across multiple devices.
The main catch with using User ID is you are not allowed to send any personally identifiable information (PII), so it may require a bit more development work to create the User ID; however, if you're able to do that, it's probably the better route to go.
Here are some developer guides to help get you started with the implementation:
https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

How to send a broadcast message with SmackAPI?

We're developing special devices that uses XMPP to talk to each other. A new API i am developing now, should talk to these devices too. The problem i am facing - all these devices are building little groups - for each customer we have... so we will have a chat-room for each group of devices, or, for each of our customer with his bunch of devices ;)
But now.. the api should be able to talk to every device that is connected. I don't need a real broadcast-mechanism - in the end, i will send a message only to one specific device..
But i don't want to login to each chat-room either - running a product with over 40k customers and much more devices, will end in a funny api, that is opening over 40k chat-rooms at startup... even if don't tried this yet, i can't imagine that an app like this will run well... even though we can have millions of customers in a few years.. i don't like solutions that will grow linear with the amount of customers, if you know what i mean :/
Now, basically i'm thinking of a solution, where i just can use the basic XMPPConnection to do my stuff.
MyCustomMessage msg = new MyCustomMessage();
msg.setTo("*"); // don't know what to address, i want to send it to "all"
msg.setFrom("ThatAPI"); // just a string telling that is sent from my java api ;)
msg.setEvent(event); // stuff that is coming through the parameters of the method where this code is inside
msg.setCustomStanza(data); // same here
connection.sendPacket(msg); // my try to send it to all till now..
Somewhere in the Ignite Realtime Forums i have read of one guy who "solved" it, but everything he says is "it's working now, i push my message through the sendPacket of Connection"... ok nice, my attempt of this seems not to work :(
Any better ideas/real implementations how this will work fine?
Basically i start to think that XMPP will not be the best technology to achieve something like this at all - i wish i could have a real/basic socket-implementation where something like this would be piece of cake.. But i can't choose - the third-party-system has implemented XMPP already... not enough time to change all of this... Just if you're wondering why we try this on XMPP..
You seem to have some conflicting requirements in that you want to send to all devices now, but only 1 specific device later. Are both models required at the same time, or do you plan on switching? How either is done would be different solutions.
As for your current approach, I think pubsub would make more sense than your chatroom approach, as that is oriented to generic message passing to subscribers.
You could set up a pubsub node per customer to send messages to all
of their devices.
As for a broadcast to all, you can make all devices
subscribe to a single pubsub node.
Thus you control broadcast and group messages by sending to the appropriate pubsub node.
For sending to a specific device, that is just a sendPacket to the specific entity, nothing really special there.

How to automate a text message?

I have a group that needs to send out announcements and current events via phone text message. I want to have a central phone number that when it receives a text message, it rebroadcasts that message to a growing list of subscribers. I'm hoping to use a Google Voice number to avoid buying an actual phone number.
Any ideas? I've thought about some type of Java/HTMLunit that continually parses the GVoice html inbox, but I just have that computer-gut feeling that there is a more intuitive way. I haven't been able to find a GVoice API, as I imagine that would be the trick.
Thanks
I've used a different approach. There's a number of E-mail to SMS services out there. So you send an e-mail (using standard JavaMail) to a specific address that is then associated with mobile phone numbers. I use TextMagic, but there are also other similar services out there. They also have API support, if thats what you'd prefer.

Categories

Resources