XCUIElement always exist - xcode7

I try UI Testing on xcode 7 beta.
After an XCUIElement dismissed, its .exists property still remains YES.
e.g.
XCUIElement *button = app.sheets[#"Sample sheet"].buttons[#"Sample button"];
[button tap]; // Tapping will dismiss UIActionSheet and its button will no longer exist.
XCTAssertFalse(button.exists); // -> Error here.
Is there any way to detect an XCUIElement not exists after being dismissed?

XCUIElement has an exists method which returns BOOL.
In your code:
if (button.exists) {
[button tap];
}

Best way is to check an XCUIElement exists and hitable or not before fire a tap event
In your code:
if (button.exists && button.isHitable) {
[button tap];
}

You can check for app.sheets.count

Related

"onDropDownClose" event is getting triggered all time even if I click any where else other than the drop down in ng-multiselect-dropdown

I am using ng-multiselect-dropdown,and I have to load the data based on the selected list.
Hence,I am using "onDropDownClose" event to get all the selected values and load the other data based on the selected multiple values.
<ng-multiselect-dropdown
[placeholder]="'Select Project'"
[settings]="dropdownSettings"
[data]="projects"
[required]='requiredField'
[(ngModel)]="selectedItems"
name="projectName"
[ngClass]='setClass()'
#projectName="ngModel"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
(onDropDownClose)="saveFunction($event)">
But the close event is triggering all the time even I click outside the dropdown always.
Is there any alternate approach it? Please help.
This should be fixed at their end but until then you can use this trick:
In addition to (onDropDownClose), listen to a click event on ng-multiselect-dropdown
// this act as a differentiator between other calls(bug) and an intended call
(click)="dropDownSelect = true".
In your component, declare your variable and use it like this:
dropDownSelect = false;
saveFunction($event) {
if (this.dropDownSelect) {
// close the opening to subsequent actions
this.dropDownSelect = false;
// Perform action;
};
}

After Input goes Invalid in HTML5 set error message and prevent default error message from kendo in a grid

I stuck with the inline validation in the kendo grid.
I don't want to validate after losing focus. I want to validate immediately after typing. So I start using the HTML validator. It works pretty well but the problem is I cant answer these two questions:
which event set the input from valid to invalid.
which event displays the error message.
My Current work: https://dojo.telerik.com/OSONo/56
which event set the input from valid to invalid.
...
which event displays the error message.
Just run your kendoValidator with validator.validate();
The error messages are also set with validate().
Something like this should work:
$(document).on('input propertychange', function() {
validator.validate();
});
The warning seems to be hidden behind some elements, so you can also add the folowing errorTemplate to your kendoValidator:
errorTemplate: '<div class="k-widget k-tooltip k-tooltip-validation" style="margin: 0.5em; display: block;"><span class="k-icon k-i-warning"></span>#=message#<div class="k-callout k-callout-n"></div></div>'
And the whole solution:
https://dojo.telerik.com/OSONo/66
Solved my Problem on my Own. I will edit the post so you can see what i mean but first i just give the dojo projcet.
https://dojo.telerik.com/OSONo/64
my edit:
I am sorry for my previous anwser, i just want to give him my solution i mention in my comment.
In my solution i created an event listener, how listen to all input elements. When something has changed it, saves the current cursor position (its import for ie support) and after this it trigger my "change" event. The "change" event check if it is valid or invalid. If it is invalid the kendo validator shows imidently the error-message (not as default by a blur event).
var ValidierungCheckClass = (function () {
return {
AllDOMElements: function () {
$('body').on('input', function () {
var myActiveElement = $(':focus');
if ((myActiveElement) && (myActiveElement.context.activeElement.nodeName.toLowerCase() !== "body")) {
var myActiveDOMElement = myActiveElement[0],
start = myActiveDOMElement.selectionStart, //just for IE Support
end = myActiveDOMElement.selectionEnd; //just for IE Support
myActiveElement.trigger("change");
myActiveDOMElement.setSelectionRange(start, end); //just for IE Support
}
})
}
}
});
The change event is allready created from kendo so you dont have to write your own.
At least you have to call the method when creating the website.
<script>
ValidierungCheckClass().AllDOMElements();
</script>
This is my Solution to my problem.
best regards.

Can't close Kendo UI Window from AngularJS Controller?

In my controller I'm using this to open my Kendo UI Core window:
$scope.winQuestion.setOptions($scope.DlgOptions);
$scope.winQuestion.open();
This is the code in my html:
div kendo-window="winQuestion" k-title="'Question 1'" k-position="{ top: 60, left: 100 }"
k-width="730" k-height="300" k-visible="false"
k-content="{ url: 'questions.html' }"
k-on-open="winQuestion = true" k-on-close="winQuestion = false" style="background-color:#ffffff;"></div>
Now inside that questions.html I have a button that I try to trigger this in the same controller thats inside of another function where I process a cancel click:
$scope.winQuestion.close();
This call which in my search for answers on StackOverflow is supposed to work just returns:
TypeError: $scope.winQuestion.close is not a function
I suspect that its a scope issue but not sure why because I get into the
$scope.closeWindow = function(){
$scope.winQuestion.close();
};
Sorry I don't have a plunker for this but couldn't get kendo core ui to work there, only locally.
I have not tested it but from what it looks like you are overriding the variable of the window, with true/false in the k-on-open and k-on-close events.
When you open the window with $scope.winQuestion.open(); the on-open event will set $scope.winQuestion = true;.
So all subsequent method calls on $scope.winQuestion are no longer made on the reference of that window, but instead on a boolean value (which does not implement an open() function)

How to get object referece of UIPickerView when it create through html select tag

I have a UIWebview contains a html "select" tag, which is shown as a on the screen.
When I click the dropdown, the UIWebview brings up a UIWebSelectSinglePicker View automatically, which is shown as .
I want to change the picker view background color and text color. How can I achieve this goal?
I tried to listen on UIKeyboardWillShowNotification event, but at that moment, this view has not been created.
Thanks in advance for any helps.
I managed to resolve the issue myself.
If someone also want to change the UIPickView on the fly, please take a look:
First, add a listener on UIKeyboardWillShowNotification event.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(_pickerViewWillBeShown:) name:UIKeyboardWillShowNotification object:nil];
Second, when notification fired, call change background color method after delay. <-- This is very important, if call method without delay, the pickview does not exist at that moment.
- (void)_pickerViewWillBeShown:(NSNotification*)aNotification {
[self performSelector:#selector(_resetPickerViewBackgroundAfterDelay) withObject:nil afterDelay:0];
}
Third, go through the UIApplication windows and find out pickerView. And you can change what ever you want for pickerView.
-(void)_resetPickerViewBackgroundAfterDelay
{
UIPickerView *pickerView = nil;
for (UIWindow *uiWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *uiView in [uiWindow subviews]) {
pickerView = [self _findPickerView:uiView];
}
}
if (pickerView){
[pickerView setBackgroundColor:UIColorFromRGB(0x00FF00)];
}
}
(UIPickerView *) _findPickerView:(UIView *)uiView {
if ([uiView isKindOfClass:[UIPickerView class]] ){
return (UIPickerView*) uiView;
}
if ([uiView subviews].count > 0) {
for (UIView *subview in [uiView subviews]){
UIPickerView* view = [self _findPickerView:subview];
if (view)
return view;
}
}
return nil;
}
Hope it will help.
I believe I've come up with an alternate solution to this problem. There are certain circumstances with the other solution proposed where the label colours appear incorrect (using the system default instead of the overridden colour). This happens while scrolling the list of items.
In order to prevent this from happening, we can make use of method swizzling to fix the label colours at their source (rather than patching them after they're already created).
The UIWebSelectSinglePicker is shown (as you've stated) which implements the UIPickerViewDelegate protocol. This protocol takes care of providing the NSAttributedString instances which are shown in the picker view via the - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component method. By swizzling the implementation with our own, we can override what the labels look like.
To do this, I defined a category on UIPickerView:
#implementation UIPickerView (LabelColourOverride)
- (NSAttributedString *)overridePickerView:(UIPickerView *)pickerView
attributedTitleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
// Get the original title
NSMutableAttributedString* title =
(NSMutableAttributedString*)[self overridePickerView:pickerView
attributedTitleForRow:row
forComponent:component];
// Modify any attributes you like. The following changes the text colour.
[title setAttributes:#{NSForegroundColorAttributeName : [UIColor redColor]}
range:NSMakeRange(0, title.length)];
// You can also conveniently change the background of the picker as well.
// Multiple calls to set backgroundColor doesn't seem to slow the use of
// the picker, but you could just as easily do a check before setting the
// colour to see if it's needed.
pickerView.backgroundColor = [UIColor yellowColor];
return title;
}
#end
Then using method swizzling (see this answer for reference) we swap the implementations:
[Swizzle swizzleClass:NSClassFromString(#"UIWebSelectSinglePicker")
method:#selector(pickerView:attributedTitleForRow:forComponent:)
forClass:[UIPickerView class]
method:#selector(overridePickerView:attributedTitleForRow:forComponent:)];
This is the Swizzle implementation I developed based off the link above.
#implementation Swizzle
+ (void)swizzleClass:(Class)originalClass
method:(SEL)originalSelector
forClass:(Class)overrideClass
method:(SEL)overrideSelector
{
Method originalMethod = class_getInstanceMethod(originalClass, originalSelector);
Method overrideMethod = class_getInstanceMethod(overrideClass, overrideSelector);
if (class_addMethod(originalClass,
originalSelector,
method_getImplementation(overrideMethod),
method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(originalClass,
overrideSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
}
else {
method_exchangeImplementations(originalMethod, overrideMethod);
}
}
#end
The result of this is that when a label is requested, our override function is called, which calls the original function, which conveniently happens to return us a mutable NSAttributedString that we can modify in anyway we want. We could completely replace the return value if we wanted to and just keep the text. Find the list of attributes you can change here.
This solution allows you to globally change all the Picker views in the app with a single call removing the need to register notifications for every view controller where this code is needed (or defining a base class to do the same).

Can you get the parent GTK window from a widget?

I have a custom widget and it needs to launch a MessageDialog and in order for me to put that message dialog on top of the window my widget is in then I need access to the parent gtk.window. Is there a way to get the parent GTK window? Thanks
The GTK docs suggest:
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
{
/* Perform action on toplevel. */
}
get_toplevel will return the topmost widget you're inside, whether or not it's a window, thus the is_toplevel check. Yeah something is mis-named since the code above does a "get_toplevel()" then an immediate "is_toplevel()" (most likely, get_toplevel() should be called something else).
In pygtk, you can get the toplevel like toplevel = mywidget.get_toplevel() then feed toplevel directly to gtk.MessageDialog()
Though gtk_widget_get_toplevel should work, you may also give a try to the code below. It should get the parent gtk window for the given widget and print it's title.
GdkWindow *gtk_window = gtk_widget_get_parent_window(widget);
GtkWindow *parent = NULL;
gdk_window_get_user_data(gtk_window, (gpointer *)&parent);
g_print("%s\n", gtk_window_get_title(parent));
hope this helps, regards
For GTK4, the gtk_widget_get_toplevel() method on GtkWidget has been deprecated. Instead, you can use the gtk_widget_get_root() method or the Widget:root property, which returns a GtkRoot. That GtkRoot can then be cast to a GtkApplicationWindow() or GtkWindow().
Here's an example in C
GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (widget));
GtkWindow *window = GTK_WINDOW (root);
Here's an example in Rust
let window: Window = widget
.root()
.unwrap()
.downcast::<Window>()
.unwrap();