How to download images from mobile application using webdriver\appium? - java

How to download images from mobile application using webdriver\appium?
for example: whatsapp, amazon

If the sole purpose of your task is to download some images that are coming in through a Native app like Amazon or Whatsapp, you don't need a high level framework like Appium or web driver. You can accomplish that task through network layer.
To start with, While browsing through the images that you are interested in hook up Fiddler or Charles proxy, enable SSL proxying, install root cert etc. to see what are the HTTP requests that are giving the images.
You can mimic the exact same thing using network requests in your favorite programming language.

I suggest you look at HtmlUnit library.
After you added the library, the code will looks like:
File fileToSaveImage = new File(dirToSave, normalizedName);
HtmlImage elementHtmlImage = (HtmlImage) pageWithImage.<HtmlImage>getFirstByXPath(X_PATH_FOR_IMAGE);
elementHtmlImage.saveAs(fileToSaveImage);
Of course you have to care about X_PATH_FOR_IMAGE, but I am sure it can be generalized by some site-specific pattern.

Related

Sending Dynamic Emails through a Java Cron Job using Microsoft Graph

I have a java (Spring boot) web service which does not have any UI.
I want to send a dynamic Email (created using Thymeleaf and injecting values from a database) using my web service on a daily Cron schedule, using Microsoft Graph and O365 APIs.
Right now I use SMTP to send emails, but I cannot use it anymore as that is no longer going to be supported by the O365 account that I am using.
I found the SendMail APIs on the Graph Documentation which looks pretty straightforward.
But, using the Graph AIPs requires you to create an Azure AD project first and use their Microsoft Identity platform - which I created.
Now, the problem is that most of the flows also require a user to manually login from a login window.
This is where things get complicated.
I do not have a place to show a Login window to any user from my web service, because it is just a backend service there is no UI. I intend to use a service account for sending the emails through the Application.
I found a Daemon support as well, but it seems to only support Python or .Net code.
Migrating my code from Java to either of those platforms just to be able to send emails
does not feel like a good solution.
And, I'm not even sure if they even offer similar capabilities of sending dynamic emails like Java+Thylemeaf do?
Is there a way to be able to continue doing this using my existing code in Java?
If not, then as the worst case scenario, are there any libraries in Python which can allow me to send dynamic emails like thymeleaf does in Java?
As you don't want to manually login from a login window, you can use the client credential flow.
Here is the guide regarding how to access graph api without user.
Reference:
msgraph-sdk-java-auth (You can choose to use Client credential provider)

How to fetch mails in Android using IMAP/POP3 protocols

I want to develop an Android application similar to Typeapp . I want to know the algorithm behind it. Basically it would be a customised inbox with all IMPS/POP3 emails in a one application. If we have to configure this in java/Android to connect with IMAP server how can I achieve this.
K-9 is an open-sourced email-client, if the license fits your project's requirements, then you can start from that code, and build on top of it:
See: https://k9mail.github.io/

How to return Google Drive authorization code from browser window automatically using Java?

I'm attempting to create an application for both PC (Java) and Android that utilizes Google Drive. I've been messing around with the examples to figure out how OAuth 2.0 works, and I can't find a good method of automatically returning the authorization code to my program once the user has allowed the application to access their data. The Google Drive Quickstart example uses a simple copy/paste mechanism that requires user input, but this is not convenient for the user.
It seems there are several suggested ways to retrieve the authorization code without bothering the user (running a local web server, monitoring the browser window launched for authentication, etc...), but Google doesn't strongly recommend any solution nor do they provide examples of how these solutions would work beyond basic descriptions. The following guide gives a few suggestions in Section 4 (Note: I tried to quote the section but SO wouldn't let me with the number of links/images present):
https://developers.google.com/youtube/v3/guides/authentication#installed-apps
Has anybody implemented something similar in the past, or are there best practices to do this? If possible I'd prefer a solution that would work on multiple platforms (i.e. not using any platform specific libraries).
I suppose it's not a huge deal if the user had to do this once (as I'll be storing a refresh token and using that from then on), but it'd be good to have a way around it.
In Oauth2 protocol, you have two ways of getting the authorization code : via a redirect to an url you have control over (could be pointing to a serve you own or localhost) or via copy pasting.
The first way is what you want, presumably with localhost as redirect uri, as you lauch the flow from you desktop app on the user's machine. You'll have no choice but to make your app spawn a little http server that can handle the code url parameter. However, you'll have to be hackish : how do you launch a web browser from your app, for any OS it can run on ? how do you the case where the user's machine is configured to refuse inbound http connection ?
IMO, best course of action is to go for the copy pasting : user knows what happen
I just implemented an oAuth2 solution for Google Drive. I ended up creating a service account via Google App Engine. Here is a good link to get started:
https://developers.google.com/drive/service-accounts
There is a Dr. Edit example that will work you through editing drive objects like spreadsheets.
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountUser(ACCESS_DOMAIN_IMPERSONATE) // <-- set user email here
.build();
There are a few things you need to do in your Google domain admin console/cpanel for your domain.
Check the following SO answer I posted a day or so ago:
OAuth Google API for Java unable to impersonate user

Host a streaming webcam on website with VLC/Red5 or whatever

I currently have a website that i am running at my home based on Java/SpringMVC web server.
I want to stream my webcam to my website so i can connect to it where ever i am from a browser and see my room.
Does anyone know an easy solution/server to use to do this and how to capture this in HTML.
Maybe a guide or sample project or something. I cant find anything useful/straight forward on Google.
I have already tried Red5/VLC as a media server but have had no luck so far capturing the video on a webpage. (using html5 video tags on chrome.)
I need to have this embedded in my home website. So it has to be browser based
I have decent Enterprise Java skills but streaming video is kind of new to me.
Thanks
Yes, you can stream a webcam to a website via multiple ways.
use Windows media Server/ Flash media Server. Push your webcam to the server by Windows Media Encoder or flash media encoder, and use the server live link to link with your website via any suitable player (like jwplayer).
Use Windows Media Encoder to stream your webcam to anyone without a server involved. when your encoder starts, you will get a URL to view your stream, which you can use to publish in your site.
use third party streaming services, where they give you a publishing point to publish your webcam stream, and use the link provided by them to show it on your website. (check with brighcove or Mogulus by LiveStream
Hope this helps.

Facebook OAuth login with Java (desktop only)

How do I login into Facebook and get a accesstoken in Java with a desktop application only?
I found a api http://restfb.com that lets you call methods but you have to get the token yourself. So is there a way to do this using only a desktop app? Maybe embed a browser to a window popup?
I already know the process in getting a token explained here http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens so my question doesnt involve that. I need a way for the user to login into facebook using some kind of GUI.
As in the facebook document
Our OAuth 2.0 implementation does not include explicit support for application built for desktop operating systems. However, if your app can embed a web browser (most desktop frameworks such as .NET, AIR and Cocoa support embedding browsers), you can use the client-side flow with one modification: a specific redirect_uri. Rather than requiring desktop apps to host a web server and populate the Site URL in the Developer App, we provide a specific URL you can use with desktop apps: https://www.facebook.com/connect/login_success.html.
I think you are right about embed web browser.
And I suggest you to move to Graph API instead of Rest, Because It's deprecating.
see more abount Facebook Authentication
Deprecating the REST API

Categories

Resources