NSTokenField completion list style - objective-c

I'm a beginner in OSX development so I hope my question will find a solution here.
I have an NSTokenField in my app and I implemented the tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: method.
Everything works fine but the present result look like this :
What I would like is to make it look like this: (similar to the completion in the Mail app)
Which means that I would like the completion list to take all the NSTokenField width.
Using the Accessibility Inspector, I can see that the hierarchy corresponding to the first sreenshot is:
AXScrollArea -> AXList -> AXTextField
while the one corresponding to the second screenshot is:
AXScrollArea -> AXTable -> AXRow:AXTableRow -> AXTextField
So I suppose I have to use an NSTableView to display the completion list, but I don't know how to achieve this. Does anybody know how is that possible?
Thanks in advance for your help.
EDIT
At least 2 people suggested that I implement the tokenField:menuForRepresentedObject: method and define the menu width with the appropriate NSMenu property. But this method is used to define a menu for a given token and I already implemented it:
def tokenField(tokenField, menuForRepresentedObject:representedObject)
theMenu = NSMenu.alloc.initWithTitle("Email address context menu")
item_0 = theMenu.insertItemWithTitle('add_to_address_book'.localized, action:'add_to_address_book', keyEquivalent:"", atIndex:0)
item_0.setTarget(self)
item_1 = theMenu.insertItemWithTitle('new_message'.localized, action:'new_message', keyEquivalent:"", atIndex:1)
item_1.setTarget(self)
theMenu
end
Which gives me something like this:
Something great but not what I am asking here.

Related

Keyboard shortcuts on Flutter web

I'm adding keyboard shortcuts to a Flutter web application.
I have a form within a custom FocusableActionDetector where the shortcut has form like this:
SingleActivator(LogicalKeyboardKey.digit2)
and action is like:
CustomActivateIntent: CallbackAction<CustomActivateIntent>(
onInvoke: (intent) { provider.value = "2"; },)
In the same form I have a couple of numeric TextFormFields. To permit writing the character "2" I have to put these text fields inside some new FocusableActionDetector, otherwise the previous detector catches the command and the text field loses the "2" character, and this is already quite weird... Moreover, after writing in any of the text fields the form focus detector doesn't work anymore.
I think this could be related to the focus system, which is yet not that clear to me.
Can anyone help find a clean solution?
I found a workaround: the FocusableActionDetector is now preceded by an if statement. The code looks like the following:
// I extract the form to a widget to make it clearer
var searchWidget = SearchWidget();
child: textEditingInProgress
? searchWidget
: FocusableActionDetector(
child: searchWidget,
...,
),
The textEditingInProgress bool is a field in a provider and is controlled by the FocusNodes belonging to the TextControllers.
Still this is not a perfect solution, in particular I'd like to understand why the previous approach was not working.

Karate UI automation, is it possible to make locators dynamic

Thanks Peter for API,Perf karate framework.
Now I am trying UI automation and it looks perfect as of now.
I have below question:
I have a menu bar with 15 items in it. they are named as following:
-Home
-Account
-groups
-settings
etc etc.
Locator for each one is like this "a[name=Home]" , "a[name=Account]", "a[name=groups]" . So ony the part after name= is something that is dynamic in nature. So my question is that is it possible to somehow make this dynamic locator?
I have written a called feature in which i have written steps to login and select a menu item. and I want to pass the menu item from calling feature in json like below:
if I want to click on Account menu
* call read(menuItem.feature) {menuItem: Account}
menuItem.feature looks something like below:
Given url 'xyz'
And input (username, userID)
And input (password, password)
And click("button[name=login]")
And click("a[name=Home]")
Here I want to make Home as dynamic in last click step on menuItem.feature so that I can pass other menu items and reuse all above steps/feature file to login everytime with different menu items passed from calling feature file in json{.
Again its just a query. I have currently written multiple scenarios to click on menu item and then in calling feature I call the called feature with tags like #Home,#account etc. and this works perfectly fine.
Also if there is any other better way to achieve this then please suggest
Yes. Let me put it this way, the things you see such as input('foo', 'bar') is pure JS behind the scenes. So normal programming-language rules apply. For example:
* def dynamic = 'foo'
* def locator = 'a[name=' + dynamic + ']'
* input(locator, 'some value')

How to locate an element by both class name and accessibility ID?

I am automating a windows application through a desktop session using Appium and Windows Application Driver. Certain elements I want to interact with don't have unique accessibility IDs but the combination of their class names and IDs does seem to be unique.
How can I first get a list of elements by their class name and then fetch one of them with certain ID?
I am aware that the second line of code provided is not correct, I'm just showing it to demonstrate what behavior I need.
Below is through class name:
class_elements = driver.find_elements_by_class_name("some_class_name")
Below is through an accessibility id:
specific_element = class_elements.find_element_by_accessibility_id("some_id")
specific_element.click()
Is there a way to put both of these together in a loop?
Thank you #Moshe Slavin for your suggestion
I tried the following piece of code
#pytest.mark.trial
def test_trial():
className = "UIProperty"
class_elements = ds.find_elements_by_class_name("UIProperty")
for elm in class_elements:
print(elm.get_attribute('id'))
if elm.get_attribute('id') == "System.ItemNameDisplay":
elm.click()
I decided to print the IDs as well. I got the following results:
None
None
None
...
I'm quite confused as to why this is happening. I'm using the Windows Inspect tool from SDK to gather properties of the UI elements and there definitely is and element present that matches both the class name and the ID.
It should look something like:
class_elements = driver.find_elements_by_class_name("some_class_name")
for elm in class_elements:
if elm.get_attribute('accesibilityID') == "some_id":
elm.click()
EDIT:
As #Bill Hileman has pointed out the attribute OP was looking for is accesibilityID not just id.
Thanks Bill
Hope this helps you!
Moshe Slavin answer works, but you can try like this also.
Suppose you have some class name and you are storing it in some variable like below :
className = "some class name"
then you can get all the matching class names using the below line and you are aware of that :
driver.find_elements_by_class_name(className)
Instead of finding all the elements and storing the values, store the accessibility id that you want to check in some variable like below :
accessibilityID = "some accessibility id"
Then you can search for an element which contains both the class name and accessibility id(is just for an indicative purpose, so use app related attribute which identifies required field) using the below xpath without performing any looping :
element = driver.find_element_by_xpath("//*[#class='"+className+"' and #accesibilityID='"+accessibilityID +"']");
I hope it works too...

QTP - Checking dynamic pages

I'm trying to check if a value is contained in the innertext of a webelement but I'm having a little problem: frames seem to change at every refresh of the pages.
These are the steps I've recorded:
Browser("SystemPage").Page("SystemP").Frame("dme2_header").Image("Gestione Anagrafiche").Click<br>
Browser("SystemPage").Page("SystemP").Frame("dme2_appl").WebEdit("pdrBean.pdrPod").Set parameter("POD")<br>
Browser("SystemPage").Page("SystemP").Frame("dme2_appl").WebButton("Cerca").Click
Browser("SystemPage").Page("SystemP").Frame("dme2_appl_2").Image("show_files").Click
Browser("SystemPage").Page("SystemP").Frame("dme2_appl_6").Image("Lente").Click
cctype = Browser("SystemPage").Page("SystemP").Frame("dme2_appl_7").WebElement("arrow_down").GetROProperty("innertext")<br>
DataAct = Browser("SystemPage").Page("SystemP").Frame("dme2_appl_7").WebElement("arrow_down_2").GetROProperty("innertext")<br>
Browser("SystemPage").Page("SystemP").Frame("dme2_header").Image("Gestione Anagrafiche").Click
The frames "dme2_appl6" and "dme2_appl7" changes at every refresh of the two pages.
The question is simple: how can I rewrite these two actions to make them universal?
I've tried to do something like:
Set objFrame = Frame("title:=dme2_appl_.")
and then
Browser("SystemPage").Page("SystemP").objFrame.Image("Lente").Click
But QTP gives me an error in return: "property or method not supported by the object"
Please try using the below code
Browser("SystemPage").Page("SystemP").Image("Lente").Click
Avoid using the "Frame" and if you really want to use it, put regex for name property of Frame.
Go to Object Properties--> Click on the Frame object --> Mandatory Properties--> Change name property as
like iFrame_213123123 to i.*
Hope this will solve your problem.
I don't think you can use a frame object that way. When you write Page().Frame() UFT sets the frame's parent in different way than if you first create the Frame.
Think of Frame() as a function that behaves differently when called on a Page or as a free function.
Try:
Browser("SystemPage").Page("SystemP").Frame("title:=dme2_appl_.")

NSTokenField click completion list item

I have an NSTokenField in my application and I implemented the tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: method in which I specify the receiver’s tokenizing character set with the setTokenizingCharacterSet: method:
def tokenField(tokenField, completionsForSubstring:substring, indexOfToken:tokenIndex, indexOfSelectedItem:selectedIndex)
tokenField.setTokenizingCharacterSet(NSCharacterSet.whitespaceAndNewlineCharacterSet)
end
It works as expected when I click on the space bar or the enter button. I would also like to have the same behavior when I click on one of the item of the completion list with my mouse.
How is that possible?
Thanks for your help.
I don't know if it's possible to have this behaviour with a NSTokenField.
But you should take a look at MTTokenField which do what you want out of the box.
To do so, you will have to:
1.Create an Xcode Project as a Static Library(Do not enable ARC).
2.Save your project to vendor/MTTokenField
3.Drag and drop all the files of MTTokenField located in the subdirectory 'MTTokenField' to your new XCode project. Choose to copy the files.
4.Add this to your rakefile in order to compile and link the library with your Rubymotion project.
app.vendor_project("vendor/MTTokenField/", :xcode, :xcodeproj => "MTTokenField.xcodeproj", :target => "MTTokenField", :products => ["libMTTokenField.a"], :headers_dir => "MTTokenField")
5.In Interface Builder change the class of your NSTokenField to NSTextField and then set its custom class to MTTokenField, and also change the custom class of the cell: MTTokenFieldCell instead of NSTextFieldCell.
6.Then you have to set the delegate of your MTTokenField to a class which has to respond to :
def tokenField(tokenField, completionsForSubstring: substring )
# your have to return an array containing your results matching substring.
end
And that's it. It should work.
Hope it helps !
I found another solution using NSTokenField instead of MTTokenField.
In the delegate of my NSTokenField, I used the controlTextDidChange method of NSControl which is called anytime I write a character in my token field. In this method I check if there is a NSLeftMouseUp event which is triggered, and if it's the case, I simulate a click on Return. And that's it.
def controlTextDidChange(aNotification)
application = NSApplication.sharedApplication
event = application.currentEvent
if event.type == NSLeftMouseUp
e1 = CGEventCreateKeyboardEvent(nil, 0x24, true)
CGEventPost(KCGSessionEventTap, e1)
end
end
There is one more thing to do to make it properly work: the issue here is that if I have a completion list with 3 items for instance, one of them will be selected by default, let's say the first one. In this case, the solution will work as expected if I click the second or the third item but I will have to double click the first item to make it work.
To fix this, turn off the autocompletion and only display the suggestion box, i.e add this line to the tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: method:
selectedIndex[0] = -1