Hello People does anyone know how to implement Webdriverio's waitUntil (explicit wait) to see if an element is existing?
to check if an element is existing we have the following:
browser.waitForExist(selector, timeout)
which after timeout will return a true of false depending upon if the element existed in the dom.
By that logic:
browser.waitUntil( function(){
return browser.waitForExist(selector) == 'true')
},timeout,'element failed to exist')
should work right?
I have the below code to identify whether an element exist or not using waitUntil in wdio.
browser.waitUntil(function(){
return browser.elements(NAVIGATION_ICONS).value.length > 0;
}, 15000, 'The navigation icon are not there');
The variable NAVIGATION_ICONS is an xpath.
Hope this helps.
Thank you,
Naveen.
I would use isExisting()
browser.waitUntil( function(){
return selector.isExisting())
},timeout,'element failed to exist')
Related
I need to scroll programatically (in order to snap items to adjust symmetrically top and bottom) after scrolling or after a tap (click) in a lazy column. I also need to start at a specific item when app launches - starts.
I am using pointerInteropFilter to be able to run some code at these actions: down, move, up. The code runs ok when I tap but it does not trigger ACTION_UP after a move is done.
[this is the desired result as soon as I release the finger from the screen... that is... a "jump" or scroll to a value that in this cases is item 10 and some offset][1]
The code is working only for tap... but the coroutine is not working when Action_up
I read that we are adviced to "prefer pointerInput] and use this only for interoperation with
existing code that consumes [MotionEvent]s"
It also say that pointerinteropFilter try to make a seamless treatment between view and motion events... but I dont know if it is relevant.
Thanks.
Mauricio
#Composable
fun Greeting(name: String) {
val listState2 = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
LazyColumn(
state = listState2,
) {
items (50) {index ->
Text(
modifier = Modifier
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> {
Log.i(ContentValues.TAG, "down pressed")
false
}
MotionEvent.ACTION_MOVE -> {
Log.i(ContentValues.TAG, "moved done")
false
}
MotionEvent.ACTION_UP -> {
coroutineScope.launch {
listState2.scrollToItem(10, 28)
}
Log.i(ContentValues.TAG, "up detected")
}
MotionEvent.ACTION_CANCEL -> {
coroutineScope.launch {
listState2.scrollToItem(10, 28)
}
Log.i(ContentValues.TAG, "canceled chosen")
false
}
else ->
false
}
true
},
text = "item $index",
)
}
}
}```
[1]: https://i.stack.imgur.com/vSiCG.png
I've faced the same issues.
The onClick= function doesn't work for all descendants, that are placed in the same composable ConstraintLayout, if the layout uses .pointerInteropFilter and returns true as a result of catching ACTION_UP MotionEvent.
It's related to the fact that clickable logic under the hood expects PressInteraction.Press which value is a simple mapping from ACTION_UP. Thus ConstraintLayout by catching ACTION_UP MoutionEvent prevents passing of PressInteraction.Press to descendants.
If the ConstraintLayout will return false on ACTION_UP MoutionEvent, then the next MotionEvents won't be dispatched to it next time. Because of implementation under the hood.
So the root cause of the issue is misusing of the Modifier.pointerInteropFilter. The idea behind the function is filtering events, what it actually does.
In my case looks like it's required to rewrite Touch logic to Modifier.pointerInput.
Maybe this findings will help you as well
So I'm trying to figure out a way to get a value from the browser when a test is running with DalekJS. As far as I can tell, it's not currently possible. I even had a look at hacking the Dalek code, but since I know very, very little about CommonJS and NodeJS other than installing and running things, I figured I might actually ask around first.
What I'm trying to do is something like:
// Non-working example
module.exports = {
'My Test': function(test) {
var foo;
test
.open('http://localhost/mysite')
.execute(function(){
foo = document.getElementById('bar');
})
.type('#myField', foo)
.done();
}
}
Now I know why this code doesn't work: because the execute() function is executed in the context of the browser window (as though I was typing it into the console).
The question I'm asking is: is there a way I can retrieve a value to use in my test?
Context information: My use case is that I'm testing an E2E scenario where a form is submitted and a code is provided to the user. This code then needs to be entered on another page. I could potentially set up mock values for the purpose of testing, but then it's not a true scenario.
Thanks in advance!
Yes,
that is a usecase we haven't implemented yet, but until we haven't found a proper solution, you can use a workaround:
module.exports = {
'My Test': function(test) {
test
.open('http://localhost/mysite')
.execute(function(){
var foo = document.getElementById('bar').innerText;
document.getElementById('myField').setAttribute('value', foo);
})
.done();
}
};
This method has some problems, none of the eventhandlers like keyup, keydown etc. will be fired when adding the value to the field in this way.
If your code doesn't rely on them, you are good to go.
Else you would have to wait some weeks until the new version is out, which will provide a better solution for such scenarios.
Hope that helps.
Cheers
Sebastian
Based on the documented example of the .log.message function, you can do something like the following:
module.exports = {
'My Test': function(test) {
test
.open('http://localhost/mysite')
.execute(function(){
var foo = document.getElementById('bar').value;
this.data('foo', foo);
})
.type('#myField', test.data('foo'))
.done();
}
}
I have an object of message streams that looks like this:
ractive.data.messages:
{
stream_id1: {
some_stream_metadata: "foo",
stream: [
{id: "someid1", message: "message1"},
{id: "someid2", message: "message2"}
]
},
stream_id2: {
some_stream_metadata: "bar",
stream: [
{id: "someid3", message: "message3"},
{id: "someid4", message: "message4"}
]
}
}
main_template:
{{#messages[ current_stream_id ]}}
{{>render_message_stream}}
{{/messages[ current_stream_id ]}}
render_message_stream:
{{#stream}}
<div class="stream">
...someotherstuff...
{{>render_message}}
</div>
{{/stream}}
render_message:
<div class="message">
...someotherstuff...
{{message}}
</div>
I change "current_stream_id" to change the rendered stream of messages.
On updates, i change the contents of the message streams like this:
ractive.merge(
"messages.stream_id1.stream",
new_message_stream,
{
compare: function ( item ) { return item.id; }
});
I also tried the compare: true option instead of the function, with the same results:
Ractive always thinks that these two messages belong effectively to the same DOM element, even though they live in a completely different message stream:
ractive.data.messages[ "stream_id1" ].stream[1].message
ractive.data.messages[ "stream_id2" ].stream[1].message
Problems:
When there are intro/outro animations ractive animates always just the end of the messages stream, even when a message in the middle of the stream was deleted, i need help to make ractive understand which messages are identical.
When i change the current_stream_id, ractive does not rerender the complete {{>render_message_stream}} partial, but goes inside the existing dom and changes the {{message}} field in all existing messages, though this might be good for dom element reuse, this triggers a lot of animations that are wrong. (Eg. it triggers intro/outro animations for the last message in the stream if stream1 has one message more than stream2).
One of these issues has a straightforward answer; unfortunately the other one doesn't.
I'll start with the easy one - the fact that
ractive.data.messages[ "stream_id1" ].stream[1].message
ractive.data.messages[ "stream_id2" ].stream[1].message
belong to the same DOM element. You're correct in that Ractive updates the existing elements rather than removing them and creating new ones - this is a core part of its design. In this case that's undesirable behaviour, but you can work around it like so:
// instead of immediately switching to a new stream ID like this...
ractive.set( 'current_stream_id', 'stream_id2' );
// you can set it to a non-existent ID. That will cause the existing DOM
// to be removed. When you set it to an ID that *does* exist, new DOM
// will be created:
ractive.set( 'current_stream_id', null );
ractive.set( 'current_stream_id', 'stream_id2' );
// or, if you'd like the initial transitions to complete first...
ractive.set( 'current_stream_id', null ).then(function () {
ractive.set( 'current_stream_id', 'stream_id2' );
});
The other issue - that merge() isn't merging, but is instead behaving as though you were doing ractive.set('messages.stream_id1.stream', new_message_stream) - is tougher. The problem is that while you and I know that {{#messages[ current_stream_id ]}} equates to messages.stream_id1 when current_stream_id === 'stream_id1, Ractive doesn't.
What it does know is that we have an expression whose value is determined by messages and current_stream_id. When the value of either of those references changes, the expression is re-evaluated, and if that value changes, the DOM gets updated - but using a standard set(). When you do ractive.merge('messages.stream_id1.stream', ...), Ractive updates all the things that depend on keypaths that are 'upstream' or 'downstream' of messages.stream_id1.stream - which includes messages. So that's how the expression knows that it needs to re-evaluate.
It's possible that a future version of Ractive will be able to handle this case in a smarter fashion. Perhaps it could make a note of arrays that are subject to merge operations, and check evaluator results to see if they're identical to one of those arrays, and if so use merge() rather than set(). Perhaps it could analyse the function in some way to see if the {{#messages[ current_stream_id ]}} section should register itself as a dependant of messages.stream_id1 for as long as current_stream_id === 'stream_id1', rather than the internally-generated ${messages-current_stream_id-} keypath.
None of that helps you in the meantime though. The only way to use merge() in your current situation is to have a separate reference that doesn't use an expression, and a bit of magic with pattern observers:
main_template:
{{#current_messages}} <!-- rather than `messages[ current_stream_id ]` -->
{{>render_message_stream}}
{{/current_messages}}
render_message_stream:
{{#current_message_stream}} <!-- rather than `stream` -->
<div class="stream">
{{>render_message}}
</div>
{{/current_message_stream}}
code:
ractive.observe( 'current_stream_id', function ( id ) {
var current_messages = this.get( 'messages.' + id );
this.set( 'current_messages', current_messages );
// hide existing stream, then show new stream
this.set( 'current_message_stream', null ).then(function () {
this.set( 'current_message_stream', current_messages.stream );
});
});
// when ANY message stream changes, we see if it's the current one - if so, we
// perform a merge on the top-level `current_message_stream` array
ractive.observe( 'messages.*.stream', function ( new_stream, old_stream, keypath, id ) {
// the value of any * characters are passed in as extra arguments, hence `id`
if ( id === this.get( 'current_stream_id' ) ) {
this.merge( 'current_message_stream', new_stream, {
compare: function ( item ) {
return item.id;
}
});
}
});
I've set up a JSFiddle demonstrating this. I hope it makes sense, let me know if not - and sorry I didn't get round to answering this question much sooner.
If I read a value from Firebase and then remove it, a subsequent limited read (e.g. dataRef.limit(10).once("value") ) will still see the removed value.
If I do an unlimited read, then I won't see the removed value, and a subsequent limited read will also no longer see the removed value.
var gFirebase = new Firebase("https://brianshmrian.firebaseio.com/");
function CreateValue()
{
gFirebase.child("TestBug/Key").set("Value");
}
function ReadValue(limit)
{
var dataRef = gFirebase.child("TestBug");
if (limit)
dataRef = dataRef.limit(10);
dataRef.once("value",function(snapshot)
{
alert((limit?"Limited read\n":"Normal read\n") + snapshot.val());
});
}
function RemoveValue()
{
gFirebase.child("TestBug/Key").remove();
}
In this example code, if I do a CreateValue(), then a ReadValue(), then a RemoveValue(), then a ReadValue(true), the object will still be reported to me in the last ReadValue(). However, if I do a ReadValue(false), I'll no longer see the value, and a subsequent ReadValue(true) will not see the value either.
See here to try it for yourself: http://jsfiddle.net/brianshmrian/5WWR6/
So is this a bug? Or am I making a mistake?
EDIT
Ok, that seems like a not too painful workaround. The code below solves my problem for now:
// Need to do this before the remove to avoid caching problem
dataRef.on("value", function(snapshot)
{
setTimeout(function() { dataRef.off(); }, 3000);
});
dataRef.remove();
I can't find any issues with the code. There is always the gotcha that locally cached data is returned synchronously, but I don't see that as an issue here; there's no way for the read to be getting called before the remove has completed. It looks like a pretty straightforward bug.
I was able to circumvent the behavior by setting up the limit(10).on('value') before calling the add/delete operations. So I think that if you establish your query ref first, you'll be okay.
Example: http://jsfiddle.net/katowulf/6wQFF/2/ (the pre tag is set up on load)
Is there a way to get a callback for when an entire list renders?
I've tried
Template.articles.rendered = function() {
var lastChapter = Chapters.findOne({}, {
sort: {
createdTime: -1
}
})
if (lastChapter._id != this.data._id)
return
doSomething()
};
But this is unreliable because chapters are added 1 by 1 instead of all at once, so this actually fires multiple times.
Thanks.
rendered is called when a part of the template is re-rendered, so you should check inside your rendered method whether you want to do anything now. When does "the entire list renders" happen? You know that in your code, for instance by checking if the list is of an expected length yet.