Why MoveToElement no response - appium

I try to move mouse to element by moveToElement, but it doesn't work.
The code is as follows
Actions action = new Actions(driver);
action.MoveToElement(element);
action.Perform();
I think the element is found, because element.Click() is work
P.S. Testing program is a win32 program in Windows.

Perform action is not worked for me too. I found the way with custom method. That my example in Python.
def scroll_to_element(self, locator: str, timeout=2):
by = get_locator_by_string(locator)
def elem_none():
try:
WebDriverWait(self._driver, timeout).until(
ex_cond.invisibility_of_element_located(by), ' : '.join(by))
return True
except TimeoutException:
return False
for _ in range(10):
if elem_none() is True:
size = self._driver.get_window_size()
startx, starty = int(size['width']) * 0.5, int(size['height']) * 0.8
endx, endy = int(size['width']) * 0.5, int(size['height']) * 0.2
self._driver.swipe(startx, starty, endx, endy, 1000)
if elem_none() is False:
break
else:
continue
My method is swiping 10 times. You can changed it to while but it is a bad way - test won't be ended if element won't be found.
This way works for me all times and it is enough for me. Hope it will be helpful for you!

Related

How to Round numbers at 0.6, 1,6, 2,6,...?

I want this to be true for all numbers. I don't want to type this for all numbers of course.
if (overs == 0.6) {
overs = 1.0;
}
I want that if for example 1.6, is reached, it should be converted to 2. I want this to be true for all numbers.
Further Clarification: I don't want it to round at For eg 0.5, i want it to round at 0.6
One Liner
double roundAt6(double n) => (n - n.floor()) > 0.5 ? n.ceil() : n;
Detailed
void main() {
final double overs = 5.6;
print('result: ${roundAt6(overs)}');
}
double roundAt6(double n) {
final double decimalPart = n - n.floor();
print('decimal part: $decimalPart');
final bool didExceed = decimalPart > 0.5;
print('didExceed: $didExceed');
return didExceed ? n.ceil() : n;
}
Maybe ceil()
Returns the least integer no smaller than this.
Example
overs = overs.ceil()
Use round() method.
Returns the integer closest to this.
Example
overs = overs.round()
Insights porvided by #Amsakanna helped me solve the problem. I am posting the exact solution here:
if ((overs - overs.floor()) > 0.55)
{
overs = overs - (overs - overs.floor()) + 1;
}

Dart - Double datatype addition results in long decimal values

In the following program I am adding the list of doubles.
The output I am expecting is 57.7 but it results in 57.699999999999996
void main() {
List<double> list= [1.0,1.0,1.0,1.0,0.8,52.9];
double total = 0.0;
list.forEach((item) {
total = total + item;
});
print(total);
}
Is this a expected behaviour?
Yes, that is expected behavior - to get the desired result use - .toStringAsFixed(1)
void main() {
List<double> list = [1.0, 1.0, 1.0, 1.0, 0.8, 52.9];
double total = 0.0;
list.forEach((item) {
total = total + item;
});
print(total.toStringAsFixed(1));
}
output: 57.7
Using reduce will solve the problem
var total = [1.1, 2.2, 3.3].reduce((a, b) => a + b); // 6.6
This is due to floating point math. This behavior is common in many languages. If you want to know more about this I recommend this site. Some languages like Java have classes made to work with this type of precise operation, however Dart does not have official support for this, luckily to get around this problem there is a package one. I'll show you what worked for me here. Using your code would look like this:
First of all to solve the main problem we must use a package called decimal, add the following dependency in your pubspec.yaml and update the packages:
name: ...
dependencies:
decimal: ^0.3.5
...
Then your file will look like this:
import 'package:decimal/decimal.dart';
void main() {
List<double> list = [1.0, 1.0, 1.0, 1.0, 0.8, 52.9];
double total = list.fold(0, (total, value) {
var result = Decimal.parse(total.toString()) + Decimal.parse(value.toString());
return double.parse(result.toString());
});
print(total); // 57.7
}
Obs: I used the google translator.
For double type addition with round off
list.map<double>((m) => double.parse(m.totalTax.toDouble().toString())).reduce((a, b) => a + b).round()

Why is it the same table even though it is not a prototype

I have this code:
function createRect(x, y, w, h)
local rect = {
type = "rect",
x = x,
y = y,
w = w,
h = h,
translate = function(rect, vector)
assert(vector.type == "vector2d")
local rect = shapes.createRect(rect.x + vector.x, rect.y + vector.y, rect.w, rect.h)
end,
}
return rect
end
translate = function(rect, vector)
assert(vector.type == "vector2d")
local rect = shapes.createRect(rect.x + vector.x, rect.y + vector.y, rect.w, rect.h)
end
local o = createRect(2,3,4,5)
local q = createRect(2,3,4,5)
print(o.translate, q.translate, translate)
Which is some very easy code and is written to test factory functions in Lua and is very reminiscent of the JS module pattern. Something people usually complain about when talking about factory functions is the memory footprint.
Because o and q are just assigned, of course they have different translate() functions, I assumed.
However I was proven wrong:
function: 0x7fcdbe600d50 function: 0x7fcdbe600d50 function: 0x7fcdbe600d90
Why is this? How can this even be? I assumed to be o.translate and q.translate to be different functions, however they are the same...
How can this even be? I assumed to be o.translate and q.translate to be different functions, however they are the same...
Normally you are correct, however Lua 5.2 introduced an optimization where anonymous functions may be cached if certain conditions are met. Specifically, if the values it references doesn't change between construction then the first created instance of that anonymous function gets reused.
Running your example in repl.it, Lua 5.1, shows this as one possible output:
function: 0xb81f30 function: 0xb81f00 function: 0xb82ca0
But running it under melpon.org/wandbox, Lua 5.2+, shows:
function: 0x14f0650 function: 0x14f0650 function: 0x14efb40
In your example, createRect creates and returns a different rect table for every call but the field rect.translate is being assigned the same anonymous function as the lua value due to this optimization.
Also see
http://lua-users.org/lists/lua-l/2010-07/threads.html#00339
http://lua-users.org/lists/lua-l/2010-07/msg00862.html
http://lua-users.org/lists/lua-l/2010-05/threads.html#00617

Corona - Spawn objects with individual listeners

Please forgive the total n00b question. I'm new to the Corona SDK (and programming in general, save for some VB and reading Frank Zammetti's excellent book) and I've run into a problem. Having tried several things and searched extensively, I just can't get my head around this...
Background: As a learning exercise I'm trying to write a game where there are six 'thingies'. Each thingy will be given a 'score' based on random properties and the thingy with the highest score will be the "right" choice. The user will tap their choice and then they will be told if they have selected correctly or not.
I'm work on my 'draw level' function which will spawn the thingies. This function should produce 6 images on the screen and then make each of those six images identifiable by tap. This is the code I've written:
for i=1,6,1 do
thingy[i] = display.newImageRect("graphics/thingy.png", 67, 122, true);
thingy[i].name = ("thingy"..i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name.." "..thingy[i].x.." index "..thingy[i].id); --for debug
thingy[i]:addEventListener("tap", gc.positionTapped);
end
This creates the things on the screen happily. So then I define a function to react to the tapping of the thing:
function gc:positionTapped(event)
utils:log(sceneName, "positionSelected()");
print(self.id);
end
The utils:log function is there for debug, and works correctly. But the print self.id doesn't work. I'm expecting it to give me thingy id (which should be i as defined in the loop). It returns 'nil'.
I tried changing the spawn loop to be:
for i=1,6,1 do
thingy[i] = display.newImageRect("graphics/thingy.png", 67, 122, true);
thingy[i].name = ("thingy"..i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name.." "..thingy[i].x.." index "..thingy[i].id); --for debug
thingy[i]:addEventListener("tap", gc:positionTapped);
end
And the loop crashes out with "function arguments expected near )"
So I changed it again to be:
for i=1,6,1 do
thingy[i] = display.newImageRect("graphics/thingy.png", 67, 122, true);
thingy[i].name = ("thingy"..i);
thingy[i].id = i;
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
table.insert(thingy[i], gc.gameDG);
print(thingy[i].name.." "..thingy[i].x.." index "..thingy[i].id); --for debug
thingy[i]:addEventListener("tap", gc:positionTapped());
end
and it crashes out with "Runtime error assertion failed!" during the loop, as does:
thingy[i]:addEventListener("tap", gc.positionTapped(thingy[i].id));
and so does:
thingy[i]:addEventListener("tap", gc.positionTapped(i));
I've been reading and googling for three days and still can't find the answer. I'd be really thankful if you'd please take pity on a n00b and help me out. :-)
Try this:
local thingy = {}
local positionSpacing = 55
function tapHandler(event)
print(event.target.name)
end
for i=1,6,1 do
thingy[i] = display.newImageRect("Icon.png", 50, 50, true);
thingy[i].x = (positionSpacing * i) - (positionSpacing / 2);
thingy[i].y = display.contentCenterY;
thingy[i].name = ("thingy"..i);
thingy[i]:addEventListener("tap",tapHandler)
end
Keep coding...............😃

Binding variables in Prolog

I am having the following issue in a Prolog program.
The mathematical formulation of the problem is as follows:
Let Entanglements = the set of structures of the form entanglement(Symbol, Index, PosX, PosY), where Symbol is a character, Index an integer, and PosX and PosY variables (bound or unbound).
For all entanglement(Symbol, Index, PosX, PosY) in Entanglements, with one of the two variables PosX or PosY bound and the other unbound, bind the unbound variable to Symbol.
After that, let RemEntanglements = all entanglement(Symbol, Index, PosX, PosY) in Entanglements with at least one of PosX and PosY bound.
Question: Given the set Entanglements, what are the Remaining Entanglements (RemEntanglements)?
My code does not function as intended. Could you give a hint as to what I ought to change?
function(Entanglements, RemEntanglements) :-
findall(entanglement(Symbol, Index, PosX, PosY),
(member(entanglement(Symbol, Index, PosX, PosY), Entanglements),
(var(PosX), nonvar(PosY), PosX = Symbol;
var(PosY), nonvar(PosX), PosY = Symbol)),
Changed),
findall(entanglement(Symbol1, Index1, PosX1, PosY1),
(member(entanglement(Symbol1, Index1, PosX1, PosY1),Entanglements),
(var(PosX1);
var(PosY1))),
RemEntanglements).
Test query:
test(RemEntanglements) :-
function([entanglement('0',2,'X',P3),
entanglement('X',3,P3,P1), entanglement('0',4,P6,P7)],
RemEntanglements).
This query should work as follows:
1) Bind P3 to '0', given that entanglement('0',2,'X',P3) has one bound variable and an unbound one
2) RemEntanglements = [entanglement('X',3,'0',P1), entanglement('0',4,P6,P7)], given that P3 was already bound to the '0' symbol, but the others are still unbound.
The answer I got:
[entanglement('0', 2, 'X', _G11664), entanglement('X', 3, _G11655, _G11656), entanglement('X', 3, _G11647, _G11648), entanglement('0', 4, _G11639, _G11640), entanglement('0', 4, _G11631, _G11632)]
Thank you in advance!
I think you're using the wrong predicate: findall(Template,Goal,List) it's a list generator, and works - abstractly - instancing Template in Goal, then copies Template in List. Then any binding in Goal will be undone among executions.
Then I would write in this way
function(Entanglements, RemEntanglements) :-
maplist(instance, Entanglements),
include(one_bound, Entanglements, RemEntanglements).
instance(entanglement(Symbol, _Index, PosX, PosY)) :-
( ( var(PosX), nonvar(PosY) )
-> PosX = Symbol
; ( var(PosY), nonvar(PosX) )
-> PosY = Symbol
; true
).
one_bound(entanglement(_Symbol, _Index, PosX, PosY)) :-
nonvar(PosX) ; nonvar(PosY).
test(RemEntanglements) :-
function([ entanglement('0',2,'X',P3),
entanglement('X',3, P3,_),
entanglement('0',4, _,_)],
RemEntanglements).
that yields
?- test(L).
L = [entanglement('0', 2, 'X', '0'), entanglement('X', 3, '0', 'X')].
The way it is written now, you should at least get rid of singleton variables. They almost always point to an error in the logic of your predicate. For one, you are binding variables in the first findall (to Changed) and then using the original list in the second findall, which is clearly not your intention.
The singleton variables in your test however should be unbound, you can start their names with an underscore to silence the warning.

Resources