html5 local database access with selenium - java

I been asked to make a selenium test that checks the local database of html5 and verify that the information in there matches what's being displayed on the screen. This is for a mobile application that can be used on chrome I have everything working as far as selenium working with chrome.Now I am just stuck on trying to find a method that can be used for with selenium that will access the local database storage. There's a interface in selenium html5 packages that DatabaseStorage however I can not figure out how that works or how to use it. The test cases are being written in Java. Thank you all for any help you can provide on this.
I have tried to create a new object of the database storage. which dident work i tried creating a new object of result set also tried doing implements database storage. in the API for database storage it says it a interface but it dose not list a constructor. i not sure how to access a method when there's no constructor for the interface.

// Database Storage
private ResultSet executeQuery(String statement, String... param) {
String databaseName = "'HTML5', '1.0',"
+" 'Offline document storage', 100*1024";
return ((DatabaseStorage) driver).executeSQL(databaseName, statement, (Object[]) param);
}
see Selenium's HTML5 test for more details.

Related

Play Framework - How to build a web page with multiple MySQL queries

I've created my first Play Framework Website with Java using the official documentation. It has a single page where I display a list of items that can be filtered or modified.
I have a Controller class with a method:
public CompletionStage<Result> feedpostslist(String domain, String date, String state, int page, int resnum, String search) {
return feedRepository.getArticleList(domain, date, state, page, resnum, search).thenApplyAsync(articles -> {
FeedArticle[] list = new FeedArticle[articles.size()];
articles.toArray(list);
return ok(views.html.feedpostslist.render(list));
}, ec.current());
}
This method does a query to the DB (through feedRepository) and then display the result using the view feedpostslist.
Everything is fine but now I need to get other data from the DB to be used in the same web page (so multiple queries). How do I do this in Play Framework? I don't understand what is the best way to do that.
Should I do multiple DB request inside the method showed before (through feedRepository) and then pass all these informations to my view? I don't want to do a mess or even something too heavy to handle.
If the second query doesn't depend on the first one you can run them in parallel using combineAsync. This is a good example on how to do that:
https://github.com/playframework/play-samples/blob/2.8.x/play-java-ebean-example/app/controllers/HomeController.java#L85
If the second query depends on results on the first then there's nothing you can do but to wait for the first one to complete and run the second one.

How do I scrape data being a login screen for different login names?

I'm trying to compile the results of my class from my college's results page (exam.msrit.edu).
The USNs for my class are from 1MS16CS001-100
Is there any way that I could go about writing a scraper program to enter different values in the USN box and gather data?
I am quite new to scraping but have decent enough exposure to Python and java
Any advice is much appreciated :)
Not necessarily a scrape, but you can use Selenium Web Driver to browse to the page and input everything for you. Selenium Web Driver can be found here.
Essentially, once it is installed you only need to instantiate the driver and then loop through a list of values inputting them as you go.
from selenium import webdriver
# V sets up browser. If you want to use chrome addtional setup required
browser = webdriver.Firefox()
for i in len(100): #loops to arbitrary amount
browser.get("http://exam.msrit.edu/") #HTTP GET Request to page
elem = browser.find_element_by_id('id') #This is an html id. Could also use name, xpath, etc.
elem.send_keys("your string {}".format(i)) #sends up keys
elem. browser.find_element_by_id('id) #id for search button
elem.click() #clicks that element
The documentation on selenium is pretty good. http://selenium-python.readthedocs.io/navigating.html
This will open a actual browser and will take some time to load so it will not be the quickest way to do it but it will work. You can even take screenshots.

Android SDK, Check if device is Amazon-FireTV

I am trying to write a simple piece of code that will execute some other code if true. What I want to do is check if my app is running on the 'Amazon Fire-TV (BOX, not the Fire-TV stick)' I think it would not be that hard to do but I am guessing it would be something like this?
String osName = android.getSystemOS();
if(!osName.equals("AMAZON FIRE-TV")){
Toast.makeText(MainActivity.class, "This app may not be compatible with your device..., Toast.LENGTH_LONG").show();
...
}
You can check any device name specifically using:
boolean isFireTV = Build.MODEL.equalsIgnoreCase("AFTB");
(see this page for FireTV model strings, and this one for Fire Tablets)
I'd also check out this answer for a more generic test to help you determine if your app is running on an Amazond device, or installed via the Amazon AppStore (eg on a Blackberry device)
the following function:
public static boolean isTV() {
return android.os.Build.MODEL.contains("AFT");
}
should detect either firetv or fire tv stick
see
https://developer.amazon.com/public/solutions/devices/fire-tv/docs/amazon-fire-tv-sdk-frequently-asked-questions
for details

Using Selenium to access a commercial database with HTTPS security

Half year before. I already accessed to Factva.com(A NEWS DATABASE WITH ACCESS CONTROL) by Selenium driver,searching news automatically. However, two months ago, Factiva updates its access protocol from HTTP to HTTPS, which disables my program.
Under HTTP, my program can switch to a new URL within the same Chrome(EVEN a new tab). I did this by using the function: chrome.get(URL) where the URL is a direct search link. I even access the new search request by this method. You know, under HTTP search, you can just combine some key words and logic operator to produce a new URL. And I use chrome.get(URL) to switch to the new search results.
However, under HTPPS, I cannot use the above method anymore. When I use the method, Factiva shows the infos that I was in the off-login status( I should login again. Even though if I click the backforward button with my mouse, I can go back to the Factiva webpage and need not login)
My question is: Why my old method didn't work UNDER HTTPS? How can I let Factiva know, even I use the old method, I am already in the access and need not login again!
My old method under HTTP:
Class SearchTXT{
public String getSearchUrl(String keyword, String startTime, String endTime){
String f0=”http://global.factiva.com.***.uk/zhcn/du/headlines.asp?napc=S&searchText=”
String f2="&dateRangeMenu=custom&dateFormat=dmy&dateFrom=";
String f4="&dateTo=";
String f6="&sortBy=y&currentSources=";
String f7=”Wall Street Journal”;
String f8="&searchLanguage=custom&searchLang=EN&dedupe=0&srchuiver=2&accountid=9MEM000300&namespace=16";
Return f0+keyword+f2+startTime+f4+endTime+f6+f7+f8;
}
}
AFTER login the FACTIVA database by Selenium Driver, I got a chrome with the access to FACTIVA.
Then: I use this:
SearchTXT st = new SearchTXT():
String searchURL= st.geSearchUrl(“DELL”, “2011-11-10”, “2014-10-10”);
chrome.get(searchURL);
String pageSource=chrome.getPageSource();
Then I can use Jsoup.jar to Parser and collect the search results.
But this method never works after the updating from HTTP to HTTPS. These days I am so annoying about this problem.
Are there some alternative methods that can access the data under HTTPS? Maybe there are some tricks that can make my old method work again. Otherwise, I have to totally modify my whole key program and use JavascriptExecutor to deal with this problem. That means a heavy work. The worst is that the javascript code on FACTIVA website is very complicated. Some key javascript codes and functions are even not shown on the FACTIVA page source directly.
Thanks a LOT!

Cannot insert object in Parse.com with parse4j API in JAVA

I am using Parse.com for communicating with iOS application and Web Browser. I have registered in parse.com and created an application. Now I have an iOS application ready to insert an object in that application which is working fine. Now comes the backend part, I am using JAVA for web application. Now,
https://parse.com/docs/api_libraries
According to this link, I can see the API/ Libraries I can use in JAVA is
Almonds
mobile-parse-api
Parse4j
ParseFacade
Among this 4, I have selected Parse4j to build web application with.
I am using Eclipse, I have installed GWT plugin, created a web application. Now I am adding this parse4j.jar file to that project, Added it to the build path also. And then I try to write this code
try {
Parse.initialize("my app id", "my rest app id");
ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.save();
return "OK";
} catch(IllegalArgumentException e){
e.printStackTrace();
return "KO";
}
catch(ParseException e){
e.printStackTrace();
return "KO";
}
It doesn't insert the object to parse cloud. Please help why isn't working? Am I missing anything to write?
As far as I see, the code is correct. However, if Parse4j does not save the entry
this means that you write wrong the attribute name or class name. Just check the names
and class name then reply back.
Regards.
One way to validate is the do a Query, get the object and print all the attributes / data types. Then store these as static class level constants and use them throughout your class for setting values in new objects to persist.
If the get query doesn't work (without any filters), which means your class name is incorrect.
Good Luck!

Categories