android emulator hangs while running selenium script - android

I am using selenium to test an android web app. My test is running fine initially but hangs at particular point. It selects the first text field on the web page and writes the values while in zoom-in mode but it hangs at this point and does not select the second text field. Where am I going wrong?
My code is as follows:
public void testRegister() throws Exception
{
driver.get("file:///android_asset/www/aboutus.html");
driver.findElement(By.xpath("html/body/div/div/ul/li[2]")).click();
List<WebElement> w1=driver.findElements(By.tagName("input"));
System.out.println(w1.size());
for(int i=0;i<w1.size();i++)
{
System.out.println("************");
System.out.println(i + w1.get(i).getAttribute("id") +"*****" + w1.get(i).getAttribute("name"));
}
for(WebElement option:w1)
{
String str=option.getAttribute("id");
if(str.equals("name"))
{
option.click();
option.sendKeys("Vaishali");
}
else if(str.equals("dateofbirth"))
{
option.click();
option.sendKeys("28-09-1991");
}
else if(str.equals("club"))
{
option.click();
option.sendKeys("Manchester United");
}
else if(str.equals("username"))
{
option.click();
option.sendKeys("vishchan");
}
else if(str.equals("password"))
{
option.click();
option.sendKeys("vishchan");
}
else if(str.equals("sendbutton"))
{
option.click();
}
}

the id can be '' and it'l return null value
in the list of elements can be hidden element with the same id
for more reasons please post stack trace.
Best Regards Taras

Related

OnPartialResult (Speechrecognition capacitor)

I am having a problem understanding how to change the OnPartialResults function inside of the android code (in speechrecognition) to only return the new work every time a word is detected instead of the whole array of words
For example if i am saying (test) the result returned while session is remaining active is [test] but if i then proceed to say (test) again the returned result (onpartial) is now including the word found earlier [test, test], and i am only needing it to return the newly found word.
Current code
#Override
public void onPartialResults(Bundle partialResults) {
ArrayList<String> matches = partialResults.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION
);
JSArray matchesJSON = new JSArray(matches);
try {
if (
matches != null &&
matches.size() > 0 &&
!previousPartialResults.equals(matchesJSON)
) {
previousPartialResults = matchesJSON;
}
} catch (Exception ex) {}
}

Read content of another app through my app

I have been searching the same problem for days. But unable to get any hint for that.
I need to create an app like voodoo app, which shows its custom layout only on specific pages of different apps like flipkart,etc.
Now, till this time, i have found options of using AccessebilityService and MediaProjection classes for the same. But i am stuck, how can i know programmatically, that Flipkart's Product Detail Page is visible so that i can display my app's custom view over it like Voodoo app does.
Any suggestions?
What you want to do is the following.
Using accessibility services track incoming events. Then you want to track TYPE_WINDOW_CONTENT_CHANGED events, and detect when the window content matches what you'd expect.
#Override
public void onAccessibilityEvent(AccessibilityEvent e) {
switch (e.getEventType()) {
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: {
if (isFlipkartProdcutDetailPage(getRootInActiveWindow()) {
doStuff()
}
}
}
}
public boolean isFlipkartProductDetailPage(AccessibilityNodeInfo nodeInfo) {
//Use the node info tree to identify the proper content.
//For now we'll just log it to logcat.
Log.w("TAG", toStringHierarchy(nodeInfo, 0));
}
private String toStringHierarchy(AccessibilityNodeInfo info, int depth) {
if (info == null) return "";
String result = "|";
for (int i = 0; i < depth; i++) {
result += " ";
}
result += info.toString();
for (int i = 0; i < info.getChildCount(); i++) {
result += "\n" + toStringHierarchy(info.getChild(i), depth + 1);
}
return result;
}

Games.RealtimeMultiplayer.getWaitingRoomIntent null pointer exception

I create a room and it gets successfully made. And my onRoomCreated method gets called...
#Override
public void onRoomCreated(int statusCode, Room room) {
mRoomId = room.getRoomId();
Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(gApiClient, room, 2);
startActivityForResult(i, RC_WAITING_ROOM);
}
Then in my onActivityResult...
Room r = data.getExtras().getParcelable(Multiplayer.EXTRA_ROOM);
ArrayList<String> invitees = new ArrayList<String>();
for (Participant p : r.getParticipants()) {
invitees.add(p.getPlayer().getPlayerId()); //<---NULL POINTER!
}
I get that null pointer. Why?
EDIT: The android docs say this about the getPlayer() method...
Returns the Player that this participant represents. Note that this may be null if the identity of the player is unknown. This occurs in automatching scenarios where some players are not permitted to see the real identity of others.
That is why I am getting null, because my room is through auto-matching.
Now the question is. How can I create a turnbasedgame using only participant IDs? Not Player IDs
Now that I see what you are asking more clearly (my fault, not yours), here is how I do it:
(for clarification I use LibGDX, so may be some interface stuff you don't need, and I am still using GamesClient not the new API methods, but is for all intents the same)
First, the final call I look to start my game is onRoomConnected
#Override
public void onRoomConnected(int statusCode, Room room) {
//dLog("onRoomConnected");
mRoomCurrent = room;
mParticipants = room.getParticipants();
mMyID = room.getParticipantId(aHelper.getGamesClient().getCurrentPlayerId());
//dLog("The id is " + mMyID);
try {
bWaitRoomDismissedFromCode = true;
finishActivity(RC_WAITING_ROOM);
} catch (Exception e) {
//dLog("would have errored out in waiting room");
}
//tell the Game the room is connected
if (statusCode == GamesClient.STATUS_OK) {
theGameInterface.onRoomConnected(room.getParticipantIds(), mMyID, room.getCreationTimestamp() );
} else {
leaveRoom();
}
}
So, now have all the participantIDs.. now in my Game code (where I sent that List of Ids), I sort the list of IDs so that in determining Player order, it is the same methodology for all Players. First I build my opponents.
private void buildOpponents() {
// this creates a new opponent with a View on the Stage()
//sort the participants the same for all players
sortParticipantIDs();
for (String s : mParticipantIds) {
if(s.contains(mMyID) || mMyID.contains(s)) continue;
newOpponentWindow ow = new newOpponentWindow(s, MyAssetManager.getMySkin(), getStage());
Opponent o = new Opponent(this, s);
mapOpponents.put(s, o);
o.setWindow(ow);
getStage().addActor(ow);
}
setOpponentWindowPositions();
}
Then after some more setup I start Play and my first Time through, I have chosen that whoever is the top ID gets the honor of starting (I find this randomizes play enough, without having to do another method.. .but you can let the top ID do another method, and send that out to the other Players) Note this checks over my Opponents to determine Starting Player if someone leaves the room later in the game as well.
private boolean determineIfStartingBidder() {
Collections.sort(mParticipantIds);
// now look thru list
// if the number is mine then return true
// if the number is not mine.. and opponent is not Out of Game or Disconnected.. then return false
for (String s : mParticipantIds) {
if(s.contains(mMyID) || mMyID.contains(s)){
return true;
}
if(mapOpponents.get(s).getCurrentState() == currentState.DISCONNECTED || mapOpponents.get(s).getCurrentState() == currentState.OUTOFGAME ||
mapOpponents.get(s).getCurrentState() == currentState.LOSTGAME) {
continue;
}
return false;
}
return false;
}
Then in your game logic, just go through your ParticipantID list in whatever manner makes sense to pass the baton around! This works well, since all the calls for passing messages require the ParticipantID, and are there for easy grab n go!
Prior Answer Below ------------------------------------------------
try
data.getParcelableExtra(Multiplayer.EXTRA_ROOM);
no need for the getExtras

phonegap + drupalgap + jquerymobile how to debug?

Here is a function get the node of a webservice of drupal in ssets\www\modules\node\node.js of the android project. When i click content and try to retrieve a node in the apps in android emulator, there is an error message "node_page_view reference error:nid is not defined", the apps seems can read the node/%, so i want to debug the function, see the alert(node); in the following code. But i re-run the program, there is nothing happen, any ideas?
function node_page_view(node) {
alert(node);
try {
if (drupalgap.settings.debug) {
console.log('node_page_view()');
console.log(JSON.stringify(arguments));
}
if (node) {
var build = {
'theme':'node',
'node':node, // TODO - is this line of code doing anything?
'title':{'markup':node.title}, // TODO - this is a core field and should probably by fetched from entity.js
'content':{'markup':node.content},
};
// If the comments are hidden, do nothing.
if (node.comment == 0) { }
// If the comments are closed or open, show the comments.
else if (node.comment == 1 || node.comment == 2) {
// Build an empty list for the comments
build.comments = {
'theme':'jqm_item_list',
'title':'Comments',
'items':[],
'attributes':{'id':'comment_listing_items'},
};
// If the comments are open, show the comment form.
if (node.comment == 2) {
build.comments_form = {
'markup':
'<h2>Add comment</h2>' +
drupalgap_get_form('comment_edit', {'nid':node.nid})
};
}
}
return build;
}
else {
alert('node_page_view - failed to load node (' + nid + ')');
}
}
catch (error) {
alert('node_page_view - ' + error);
}
}
Have you tried weinre?
http://people.apache.org/~pmuellr/weinre/docs/latest/
or Medic:
https://github.com/filmaj/medic

Android Map Shows Direction Images in ListView

My android application uses android mapView.It shows location map and driving direction in an listview like google map.Now i want to show images corresponding to directions in lisview. ie, if the direction is to left,then i want to s*how an image which indicate to turn left in the listview*.
How can i solve this?
Thanks in Advance
I did this using String operations, but it is not stable, give 90% accuracy. See the code below:
Drawable draw;
if(direction.contains("Slight right"))
{
draw=getResources().getDrawable(R.drawable.slightright);
}
else if(direction.contains("Slight left"))
{
draw=getResources().getDrawable(R.drawable.slightleft);
}
else if(direction.contains("right"))
{
if(direction.contains("left"))
{
int index = direction.indexOf("right");
int index2 = direction.indexOf("left");
if(index<index2)
{
draw=getResources().getDrawable(R.drawable.turnright);
}
else
{
draw=getResources().getDrawable(R.drawable.turnleft);
}
}
else
{
draw=getResources().getDrawable(R.drawable.turnright);
}
}
else if(direction.contains("left"))
{
draw=getResources().getDrawable(R.drawable.turnleft);
}
else if(direction.contains("roundabout") && direction.contains("exit"))
{
draw=getResources().getDrawable(R.drawable.roundabout);
}
else if(direction.contains("Continue"))
{
draw=getResources().getDrawable(R.drawable.straight);
}
else if(direction.contains("U-turn"))
{
draw=getResources().getDrawable(R.drawable.uturn);
}
else
{
draw=null;
}
//then set the drawable to your ImageView
You can play around with the code if you see something missing or you have more images.
These are the images I used:

Categories

Resources