How to call a click on the Google Maps Marker marker in UI Automator? - google-maps-markers

In UIAutomator Viewer can see that the markers do not have anything unique except the index.
I tried to simulate a click on a specific marker in the following way:
UiObject gMap = mDevice.findObject(new UiSelector().descriptionContains("Google Map"));
UiObject marker = mDevice.findObject(gMap.getSelector().index(1));
marker.clickAndWaitForNewWindow();
But the click did not happen. How can I simulate clicking on the markers?

Don't use gMap.getSelector(). You should use childSelector to search markers inside map view
UiObject marker = mDevice.findObject(UiSelector()
.descriptionContains("Google Map")
.childSelector(UiSelector().instance(1))
)
And try to use marker.waitForExists(5000) before clicking. Usually they appear not immediately on map

Using CulebraTester and a sample map application (as shown)
which has 3 markers: the 2 red have title and snippet and the blue doesn't, you can see how the generated code differ.
mDevice.findObject(By.desc("title_of_marker1. snippet_of_marker1.").clazz("android.view.View").text(Pattern.compile("")).pkg("com.example.diego.mymapapplication")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.desc("title_of_marker2. snippet_of_marker2.").clazz("android.view.View").text(Pattern.compile("")).pkg("com.example.diego.mymapapplication")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.desc("Google Map").clazz("android.view.View").text(Pattern.compile("")).pkg("com.example.diego.mymapapplication")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
the 3rd selector is too broad and ambiguous.
I guess if you add title and/or snippet you'll have no problem clicking on them.

Related

How can I determine what part of text in a scroll view is visible on screen from an Xcode UI test?

I'm new to the Xcode User Interface testing framework. I can successfully manipulate the screen elements, but cannot work out how to produce a meaningful assertion about what text is visible in a scrolling view.
The test I would like to write would go as follows: launch the app, type lots of text into a text view (enough that the first line scrolls out of view), assert that the first line of text is not visible, scroll the view back up to the top, then assert that the first line is now visible. Note that the purpose of this test is to ensure my app has wired things up correctly, not to test Apple's code.
XCUIApplication allows me to type into my NSTextView instance, and also allows me to scroll the associated NSScrollView. But how do I assert whether the first line of text is currently visible? The value attribute on XCUIElement provides the entire text content of the view, whether or not it is currently displayed.
The accessibilityRange(forLine:) and accessibilityString(for:) methods on NSTextView would be ideal, but I can't see how to access them as the UI test only has access to an XCUIElement, not the underlying NSTextView.
Have I missed something, or is there a better way to approach this?
If you set the accessibility identifier in the storyboard or in code for the text view you can get the text view via (assuming you gave it the id "textview1" and the window it's in has the default accessibility identifier of "Window"):
let textview1TextView = app.windows["Window"].textViews["textview1"]
but that won't actually get you what you need.
Instead, set the accessibility identifier of the scrollview and get that:
let scrollview = app.windows["Window"].scrollViews["scrollview1"]
Then use that to get the scrollbars (you should only have one in this case; you can use scrollbars.count to check.
let scrollbars = scrollview.scrollBars
print("scrollbars count: \(scrollbars.count)")
Then you can use the value attribute of the scrollbar to get it's value:
(you're converting a XCUIElemenTypeQueryProvider into an XCUIElement so you can get it's value):
let val = scrollbars.element.value
it will be 0 at the top and a floating point value when scrolled (one line of text in my test code showed a value of {{0.02409638554216868}}.
Documentation that will help you explore further:
XCUIElementTypeQueryProvider
XCUIElementAttributes
Note that you can put a breakpoint in the middle of your test, run it and then use the debugger console to examine things:
(lldb) po scrollbars.element.value
t = 749.66s Find the ScrollBar ▿ Optional<Any>
- some : 0
(lldb) po scrollbars.element.value
t = 758.17s Find the ScrollBar ▿ Optional<Any>
- some : 0.05421686746987952
and while in the debugger you can even interact with your app's window to scroll it manually (which is what I did between typing in those two po calls), or perhaps add text and so on.
OK OP now noted that they're interested in the specific text showing or not rather than the first line in view or not (which is what I previously answered above).
Here's a bit of a hack, but I think it'll work:
Use XCUICoordinate's click(forDuration:, thenDragTo:) method to select the first line of text (use the view frame to calculate coordinates) and then use the typeKey( modifierFlags:) to invoke the edit menu "copy" command. Then use NSPasteboard methods to get the pasteboard contents and check the text.
Here's a quick test I did to validate the approach (selecting the first line of text using XCUICoordinate as noted above is left as an exercise for the reader):
NSPasteboard.general.clearContents()
// stopped at break point on next line and I manually selected the text of the first line of text in my test app and then hit continue in the debugger
textview1TextView.typeKey("c", modifierFlags:.command)
print( NSPasteboard.general.pasteboardItems?.first?.string(forType: NSPasteboard.PasteboardType.string) ?? "none" );
-> "the text of the first line" was printed to the console.
Note that you can scroll the selection off screen so you have to not scroll after doing the select or you won't be getting the answer you want.

Qtruby ListWidgetItem has blank icon after adding data

I am working on a GUI using qtruby. I have a ListWidget that I am filling with ListWidgetItems. So far these have just contained the text that I wanted to display and everything worked fine. I wanted these items to also hold some hidden data to use when they are clicked on. I used ListWidgetItem.setData() to set the data and I can get the data from it when it is clicked just fine. However once I add the data the text being displayed is now shifted over to the right about 4 spaces. When I click on it a little dotted box appears around the text but not the space that was added. It looks like it is a space for an icon but I have not set any icon and I don't want one. How do I get rid of this extra space so that items containing data are lined up with everything?
The code is very straight forward:
item = Qt::ListWidgetItem.new( #grain_strings[index] )
item.setFont( #font )
# TODO this is causing the text to be indented, removing it removes the indent
item.setData( 1, Qt::Variant.from_value( grain.type ) )
#item_list.insertItem( #end_of_grains+1, item )
The first argument to setData is the role number and for some reason you chose to set it to 1. The documentation says: "The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap)". So you are telling Qt to display an icon but you are not giving it a valid icon object.
Try setting the role to Qt::UserRole, which is "The first role that can be used for application-specific purposes." I am not sure how to access that constant from Ruby. If it is not provided by the qtruby gem, you could use 0x100 I suppose.

Change the colour of WinJS.UI.BackButton (Win 8.1 back button)

I'm getting started with Windows 8 App development using WinJS. I'm using the Light UI theme but I have set up a darker area on the left of the page (where the black back button is) and the issue is: you can't see the button.
I've trawled through the MSDN pages and the most I could find is how to style a button which doesn't actually explain how to change the colour of an actual asset.
http://msdn.microsoft.com/en-us/library/windows/apps/jj835822.aspx
I've also tried adding: win-ui-light and win-ui-dark classes to the button with no success.
I wondered if someone could point me in the right direction?
Many thanks for your time
Chris
First of all you have to delete the link tag that contain UI css by default and add it to document head , Dynamically.see below code :
var uistyle;
// call when your app load or resume.
function onappopen(){
uistyle = document.createElement('link');
uistyle.href = "//Microsoft.WinJS.2.0/css/ui-dark.css";
uistyle.rel = "stylesheet";
uistyle.id = "UIstyle";
document.head.appendChild(uistyle);}
// call when you want to change UI Style.
function UIstyle(UIbool){
if(UIbool=='light'){ uistyle.href = "//Microsoft.WinJS.2.0/css/ui-light.css";}
else {uistyle.href = "//Microsoft.WinJS.2.0/css/ui-dark.css";}}
Like: UIstyle('light'); for light UI in Windows 8 or "UIstyle()" for dark;
I used the DOM Explorer to find the buttons default values and overwrite them. It was the child element that needed to be overwritten: .win-back

Google places autocomplete with Selenium IDE test

I'm trying to make test in Selenium IDE (from Firefox addon) for autocomplete place (given from google places). I need type in input place name and get the first location.
Sequence for place "Rzeszów, Polska":
i.stack.imgur.com/gqRMd.png
Firstly I've tried mouseOver and Click action - elements exists but didn't make a click on autocomplete. Next I've tried two another sequences (with clickAt and KeyDown), but also didn't make a click, despite the fact that Selenium can find correct locator.
i.stack.imgur.com/F13q7.png
I was trying my solution for jQuery autocomplete -> jqueryui.com/autocomplete/ and it worked fine there.
I think, problem is connected with html structure, with bold in place name:
i.stack.imgur.com/BfLyE.png
You can test it on: jsfiddle.net/dodger/pbbhH/
My sequence in Selenium IDE (shown above) doesn't work for google places, could anyone solved this problem with autocomplete?
//Moderator: Please add photos and create links to my post and delete this line. Thanks.
To force the places autocompletion list to appear I had to send single keydown and keyup events to the input field. Like this:
selenium.focus(LOCATOR);
selenium.type(LOCATOR, ""); // clear the field
for (int i=0; i<value.length(); i++) {
String c = String.valueOf(value.charAt(i));
selenium.keyDown(LOCATOR, c.toUpperCase());
selenium.keyPress(LOCATOR, c);
selenium.keyUp(LOCATOR, c.toUpperCase());
}
Finally, to select an entry of the list, I've got it working by simulating keyboard events (since I also had no luck with mouse events).
keyDown with the arrow down key: selenium.keyDown(LOCATOR, "\u0028");
blur on the input field (optional I think): selenium.fireEvent(LOCATOR, "blur");
LOCATOR is the locator for your input field. \u0028 is the key code for arrow down (hex 28 or dec 40)
Hope this helps.

How do you add UI inside cells in a google spreadsheet using app script?

I'd like to add buttons to specific cells in Google docs spreadsheet. The apps script UI documentation talks about how to add a new panel, but it's not clear how UI in that panel could be attached to specific rows or cells.
Is it possible to add UI to particular cells, or are we limited to adding new panels?
The apps UI only works for panels.
The best you can do is to draw a button yourself and put that into your spreadsheet. Than you can add a macro to it.
Go into "Insert > Drawing...", Draw a button and add it to the spreadsheet.
Than click it and click "assign Macro...", then insert the name of the function you wish to execute there. The function must be defined in a script in the spreadsheet.
Alternatively you can also draw the button somewhere else and insert it as an image.
More info: https://developers.google.com/apps-script/guides/menus
Status 2018:
There seems to be no way to place buttons (drawings, images) within cells in a way that would allow them to be linked to Apps Script functions.
This being said, there are some things that you can indeed do:
You can...
You can place images within cells using IMAGE(URL), but they cannot be linked to Apps Script functions.
You can place images within cells and link them to URLs using:
=HYPERLINK("http://example.com"; IMAGE("http://example.com/myimage.png"; 1))
You can create drawings as described in the answer of #Eduardo and they can be linked to Apps Script functions, but they will be stand-alone items that float freely "above" the spreadsheet and cannot be positioned in cells. They cannot be copied from cell to cell and they do not have a row or col position that the script function could read.
Use checkboxes(say, in F1) instead of buttons/Images. This is a intermediate to a full ui inside cells. Then hook your function, that is supposed to run on button click to onEdit() trigger function.
Sample script:
function onEdit(e){
const rg = e.range;
if(rg.getA1Notation() === "F1" && rg.isChecked() && rg.getSheet().getName() === "Sheet1"){
callFunctionAttachedToImage();
rg.uncheck();
}
}
References:
Class Range
Event Objects
Buttons can be added to frozen rows as images. Assigning a function within the attached script to the button makes it possible to run the function. The comment which says you can not is of course a very old comment, possibly things have changed now.
There is a silly trick to do something that might help you :
You can make the drawing object as tall as your sheet (To appear to every row in the sheet).
You can make the script affects the current cell value by the following code:
SpreadsheetApp.getActiveSpreadsheet().getActiveCell().setValue(cellValue);

Resources