How to scroll to an element with appium using webdriveriO - appium-ios

I am using following command:
browser.scroll('#login');
I am getting this error - Not yet implemented. Please help us: http://appium.io/get-involved.html

public void scroll()
{
Dimension dimensions = driver.manage().window().getSize();
System.out.println(dimensions);
Double screenHeightStart = dimensions.getHeight() * 0.5;
int scrollStart = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
((IOSDriver<MobileElement>) driver).swipe(0, scrollStart, 0, scrollEnd, 1000);
}

Use this command:
browser.execute("mobile: scroll", {direction: 'down'});

For IOS: browser.execute("mobile: scroll", {direction: 'down'});
For Android I've tried so many ways myself but did not get any robust result.

Related

Using WHERE with function in Sequelize query

I'm trying to use a function, JSON_ARRAY_LENGTH(), in my Sequelize query:
MyModel.query({
where: sequelize.where(
sequelize.fn('JSON_ARRAY_LENGTH', sequelize.col('cues')),
0
)
});
This doesn't seem to work. It generates a bad query:
SELECT id, title, /* etc. etc. */
FROM MyModel
WHERE
`MyModel`.`attribute` = JSON_ARRAY_LENGTH(`cues)` AND
`MyModel`.`comparator` = '=' AND
`MyModel`.`logic` = 0;
What is all this attribute, comparator, and logic stuff, and how do I turn it off?
The documentation seems to support what I'm doing. Its example:
Post.findAll({
where: sequelize.where(sequelize.fn('char_length', sequelize.col('status')), 6)
});
// SELECT * FROM post WHERE char_length(status) = 6;
Any ideas would be most appreciated. Thanks!
It seems I've stumbled on a bug:
https://github.com/sequelize/sequelize/issues/6440
This has been fixed in more recent builds:
https://github.com/sequelize/sequelize/pull/9730/commits/3b2972db2c494c8a4118a7e6c16aad0fc2e0eebe
The workaround around for now was to wrap my query with AND:
MyModel.query({
where: {
[sequelize.Op.and]: sequelize.where(
sequelize.fn('JSON_ARRAY_LENGTH', sequelize.col('cues')),
0
)
}
});

Is there a way to tell CMFCColorButton, what colors not to present

Is there a way to tell CMFCColorButton what set of colors to display?
For example, when press, show me just orange white and black.
Update
I've tried by defining:
PALETTEENTRY palleteEntries[2] =
{
/*index 0 black*/
{0,0,0,PC_EXPLICIT},
/*index 1 white*/
{0xFF,0xFF,0xFF,PC_EXPLICIT},
};
CPalette colorPalette;
colorPalette.SetPaletteEntries(0,2,palleteEntries);
Then I get an assertion.
Just create a CPalette object.
Use void CMFCColorButton::SetPalette(CPalette* pPalette) to force usage of this palette.
CPalette colorPalette;
colorPalette.SetPaletteEntries(0,2,palleteEntries);
At this point colorPalette is just a C++ object, not HPALETTE resource object. SetPaletteEntries makes WinAPI call for a non-existing HPALETTE and fails. This is one of those times when MFC is not being helpful by hiding everything. But the debugger helps to point out the problem.
Start with LOGPALETTE instead. LOGPALETTE::palVersion should be 0x0300 otherwise CreatePalette fails. Use this instead:
CPalette pal;
LOGPALETTE* lg = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + 5 * sizeof(PALETTEENTRY));
lg->palNumEntries = 5;
lg->palVersion = 0x0300;
lg->palPalEntry[0] = { 255,0,0,0 };
lg->palPalEntry[1] = { 0,255,0,0 };
lg->palPalEntry[2] = { 0,0,255,0 };
lg->palPalEntry[3] = { 0,0,0,0 };
lg->palPalEntry[4] = { 255,255,255,0 };
if(pal.CreatePalette(lg))
{
m_myColorBtn.SetPalette(&pal);
}
free(lg);

How to pan using paperjs

I have been trying to figure out how to pan/zoom using onMouseDrag, and onMouseDown in paperjs.
The only reference I have seen has been in coffescript, and does not use the paperjs tools.
This took me longer than it should have to figure out.
var toolZoomIn = new paper.Tool();
toolZoomIn.onMouseDrag = function (event) {
var a = event.downPoint.subtract(event.point);
a = a.add(paper.view.center);
paper.view.center = a;
}
you can simplify Sam P's method some more:
var toolPan = new paper.Tool();
toolPan.onMouseDrag = function (event) {
var offset = event.downPoint - event.point;
paper.view.center = paper.view.center + offset;
};
the event object already has a variable with the start point called downPoint.
i have put together a quick sketch to test this.
Unfortunately you can't rely on event.downPoint to get the previous point while you're changing the view transform. You have to save it yourself in view coordinates (as pointed out here by Jürg Lehni, developer of Paper.js).
Here's a version that works (also in this sketch):
let oldPointViewCoords;
function onMouseDown(e) {
oldPointViewCoords = view.projectToView(e.point);
}
function onMouseDrag(e) {
const delta = e.point.subtract(view.viewToProject(oldPointViewCoords));
oldPointViewCoords = view.projectToView(e.point);
view.translate(delta);
}
view.translate(view.center);
new Path.Circle({radius: 100, fillColor: 'red'});

Matter.js Gravity Point

Is it possible to create a single gravity / force point in matter.js that is at the center of x/y coordinates?
I have managed to do it with d3.js but wanted to enquire about matter.js as it has the ability to use multiple polyshapes.
http://bl.ocks.org/mbostock/1021841
The illustrious answer has arisen:
not sure if there is any interest in this. I'm a fan of what you have created. In my latest project, I used matter-js but I needed elements to gravitate to a specific point, rather than into a general direction. That was very easily accomplished. I was wondering if you are interested in that feature as well, it would not break anything.
All one has to do is setting engine.world.gravity.isPoint = true and then the gravity vector is used as point, rather than a direction. One might set:
engine.world.gravity.x = 355;
engine.world.gravity.y = 125;
engine.world.gravity.isPoint = true;
and all objects will gravitate to that point.
If this is not within the scope of this engine, I understand. Either way, thanks for the great work.
You can do this with the matter-attractors plugin. Here's their basic example:
Matter.use(
'matter-attractors' // PLUGIN_NAME
);
var Engine = Matter.Engine,
Events = Matter.Events,
Runner = Matter.Runner,
Render = Matter.Render,
World = Matter.World,
Body = Matter.Body,
Mouse = Matter.Mouse,
Common = Matter.Common,
Bodies = Matter.Bodies;
// create engine
var engine = Engine.create();
// create renderer
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: Math.min(document.documentElement.clientWidth, 1024),
height: Math.min(document.documentElement.clientHeight, 1024),
wireframes: false
}
});
// create runner
var runner = Runner.create();
Runner.run(runner, engine);
Render.run(render);
// create demo scene
var world = engine.world;
world.gravity.scale = 0;
// create a body with an attractor
var attractiveBody = Bodies.circle(
render.options.width / 2,
render.options.height / 2,
50,
{
isStatic: true,
// example of an attractor function that
// returns a force vector that applies to bodyB
plugin: {
attractors: [
function(bodyA, bodyB) {
return {
x: (bodyA.position.x - bodyB.position.x) * 1e-6,
y: (bodyA.position.y - bodyB.position.y) * 1e-6,
};
}
]
}
});
World.add(world, attractiveBody);
// add some bodies that to be attracted
for (var i = 0; i < 150; i += 1) {
var body = Bodies.polygon(
Common.random(0, render.options.width),
Common.random(0, render.options.height),
Common.random(1, 5),
Common.random() > 0.9 ? Common.random(15, 25) : Common.random(5, 10)
);
World.add(world, body);
}
// add mouse control
var mouse = Mouse.create(render.canvas);
Events.on(engine, 'afterUpdate', function() {
if (!mouse.position.x) {
return;
}
// smoothly move the attractor body towards the mouse
Body.translate(attractiveBody, {
x: (mouse.position.x - attractiveBody.position.x) * 0.25,
y: (mouse.position.y - attractiveBody.position.y) * 0.25
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/matter-attractors#0.1.6/build/matter-attractors.min.js"></script>
Historical note: the "gravity point" functionality was proposed as a feature in MJS as PR #132 but it was closed, with the author of MJS (liabru) offering the matter-attractors plugin as an alternate. At the time of writing, this answer misleadingly seems to indicate that functionality from the PR was in fact merged.
Unfortunately, the attractors library is 6 years outdated at the time of writing and raises a warning when using a newer version of MJS than 0.12.0. From discussion in issue #11, it sounds like it's OK to ignore the warning and use this plugin with, for example, 0.18.0. Here's the warning:
matter-js: Plugin.use: matter-attractors#0.1.4 is for matter-js#^0.12.0 but installed on matter-js#0.18.0.
Behavior seemed fine on cursory glance, but I'll keep 0.12.0 in the above example to silence it anyway. If you do update to a recent version, note that Matter.World is deprecated and should be replaced with Matter.Composite and engine.gravity.

How to fix Adobe Flex simple multiplication error

We are using version 3.6. We call a rounding function to clean up the decimal part. Something like this...
private function ceilingRounding(value:Number, power:Number):Number
{
var scale:Number = Math.pow(10, power);
return (Math.ceil(value * scale) / scale);
}
The function result is unexpected for the following values:
value = 76.7549, scale = 10000.
The result should be 76.7549 but we get 76.7550
Using the debugger, we see that value * scale = 767549.0000000001. Of course this would be rounded up to 76.7550, but why are we getting .0000000001 and how can we fix this?
The "NUMBERS" values ​​hold this approximation operation, you can modify your function and add the following into operation, plus I let the function that I use regularly to do the rounding.
public static function roundToPrecision(numberVal:Number, precision:int = 0):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
return Math.round(decimalPlaces * numberVal) / decimalPlaces;
}
If you need Fixed decimal Number try
var myNum:Number = 1.123556789
myNum.toFixed(3);
trace(myNum); // 1.123
If you need Precision decimal Number try
myNum.toPrecision(3);
trace(myNum); // 1.124;
For more options see rounding in link.
Reference NumberFormatter

Resources