Question:
Is there a way that I can offset the starting location to drag?
I would like to edit the location of where to start the dragging process. Testing on another element that I can grab without adjustment the below code works fine:
var controlPoint = $$('circle.points').first();
browser.actions().
dragAndDrop(controlPoint.getLocation(), {x: 500, y: 50}).
perform();
However when I try to set it up for modifying the location like this:
var controlPoint = $$('circle.points').first();
controlPoint.getLocation().then(function (loc) {
// would modify loc.x and loc.y here if this didn't give an error
browser.actions().
dragAndDrop(loc, {x: 500, y: 50}).
perform();
});
I get the following error:
Failures:
1) Single Segments should test dragging and dropping of control points
Message:
UnknownError: unknown error: at least an element or offset should be set
(Session info: chrome=36.0.1985.125)
(Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.4 x86_64)
Stacktrace:
UnknownError: unknown error: at least an element or offset should be set
(Session info: chrome=36.0.1985.125)
(Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.4 x86_64)
==== async task ====
mouseMove
at Array.forEach (native)
==== async task ====
ActionSequence.perform
at /Users/willko/Desktop/e2e_sketching/specs/sketch2.js:25:6
==== async task ====
The problem is in dragAndDrop(loc because dragAndDrop() takes an ElementFinder or WebElement as first argument and you're passing loc which is an Object with x and y properties.
Try this:
browser.actions().
dragAndDrop(controlPoint, {x: 500, y: 50}).
perform();
Is it possible to parameterize the second parameter or offset to dragAndDrop? Drag and drop works with hardcoded offset object like here described {x: 500, y: 50} but treats {x:x, y:y}, at least for me, as undefined (in ActionSequence.mouseMove function).
Related
I'm learning how to implement great CollectionViewPagingLayout templates in my project.
This one: https://github.com/amirdew/CollectionViewPagingLayout
First I specify which template to use (now I use "invertedCylinder") - and this part works well:
extension MovieCollectionViewCell: ScaleTransformView {
var scaleOptions: ScaleTransformViewOptions {
.layout(.invertedCylinder)
}
}
The problem appears when I try to modify the template. There is an extension, written by the creator of the Layout:
extension YourCell: ScaleTransformView {
var scaleOptions = ScaleTransformViewOptions(
minScale: 0.6,
scaleRatio: 0.4,
translationRatio: CGPoint(x: 0.66, y: 0.2),
maxTranslationRatio: CGPoint(x: 2, y: 0
)
}
I have tried to get rid of stored properties error and modify the code:
extension MovieCollectionViewCell: ScaleTransformView {
var scaleOptionsDetailed: ScaleTransformViewOptions {
minScale: 0.6,
scaleRatio: 0.4,
translationRatio: CGPoint(x: 0.66, y: 0.2),
maxTranslationRatio: CGPoint(x: 2, y: 0)
}
}
But this gives me more errors:
Redundant conformance of 'MovieCollectionViewCell' to protocol 'ScaleTransformView'
Cannot find 'minScale' in scope
Consecutive statements on a line must be separated by ';'
I understand that this is a question about basics. But it is already the second day im trying to solve the issue and would be very grateful for a guidance.
I don’t know why that repo includes stored properties on an extension. That is illegal and will likely always be illegal.
You could convert your variable scaleOptions to a computed property. To do that get rid of the equals sign. Then every time you reference that property it will run the code in the closure and generate a new value.
It is also possible to fake stored properties for extensions using associated values from the Objective-C runtime, but that is considered a hack and probably not a great idea.
I am having issues with Processing 3.3. I am just starting on a type of nebula simulator, meant to simulate the birth and life cycle of a star from a nebula to red giant. I have created two classes so far: Gas, for each individual gas particle, and Nebula, referring to the collection of particles. I have typed in the following code to the editor with the same result each time: 'Class "Nebula" does not exist.' My code, drastically simplified, is as follows:
Gas:
class Gas {
/* variables, constructor, etc. */
void applyGravity(Nebula n) {
/* code to apply force of gravity of
the nebula to the particle */
}
}
Nebula:
class Nebula {
ArrayList<Gas> particles; // array of particles
/* variables, constructor, etc. */
}
Oddly enough, I don't get the error that 'Class "Gas" does not exist' in the Nebula class, but I do get the error 'Class "Nebula" does not exist' in the Gas class.
I have tried exiting and reopening the files, as well as reinstalling Processing. Any help would be greatly appreciated.
Basically, the Processing editor can handle two types of code. The first type is a basic list of function calls, like this:
size(500, 200);
background(0);
fill(255, 0, 0);
ellipse(width/2, height/2, width, height);
With this type of code, Processing simply runs the commands one at a time.
The second type of code is a "real" program with function definitions, like this:
void setup(){
size(500, 200);
}
void draw(){
background(0);
fill(255, 0, 0);
ellipse(width/2, height/2, width, height);
}
With this type of code, Processing calls the setup() function once at the beginning, and then calls the draw() function 60 times per second.
But note that you can't have code that mixes the two types:
size(500, 200);
void draw(){
background(0);
fill(255, 0, 0);
ellipse(width/2, height/2, width, height);
}
This will give you a compiler error, because the size() function is not inside a function!
What's going on with your code is Processing sees that you haven't defined any sketch-level functions, so it tries to treat it as the first type of code. But then it sees class definitions, which are only valid in the second type of code. That's why you're getting an error.
To fix your problem, just define a setup() and/or draw() function in your code, so Processing knows it's a "real" program.
Normally, drag and drop are done using 2 elements.
But, what if I have a dynamic grid, and I want to select a part of it by click-hold and dragging it then release. (similar to drag and drop)
I was able to get the x and y coordinates already, but I am not sure how to make it work without an element.
It looks like an element is required.
After using the element (body), I was able to make drag and drop work.
var offsetx = dndoffset.x;
var offsety = dndoffset.y;
browser.waitForAngular();
this.getTargetIndex(<ObjectToBeDragged>,function (targetIndex) {
var targetElement = element.all(by.repeater(<ng-repeat value>)).get(targetIndex);
targetElement.getLocation().then(function (location) {
offsetx = Math.round(offsetx + location.x);
browser.actions().mouseMove(<ObjectToBeDragged>)
.mouseDown()
.mouseMove(targetElement)
.mouseMove(targetElement, {x: offsetx, y: offsety})
.mouseUp().perform();
});
browser.waitForAngular();
});
The above is the snippet I am using to drag and drop. You always have element in the DOM (even it is dynamic). You have to pick the right one and place it there.
Since we have the ng-repeat, we are using by.repeater() to locate the element dynamically.
I am using two canvases in my project, synchronizing moving objects in the two containers. The challenge is after moving one object, I can't drag any object in the second container.
I am using:
blueLine2.on('dragmove', function () {
circle2.x(blueLine2.x() + blueLine2.points()[0]);
blueLine1.setPosition({ x: blueLine2.x() * 2, y: blueLine2.y() * 2 });
circle1.x(blueLine1.x() + blueLine1.points()[0]);
guides2.draw();
guides1.draw();
});
Here is the complete code: http://jsfiddle.net/user373721/6f1e0c1p/
Would appreciate your suggestions.
For performance reasons KineticJS is not drawing hit canvas while dragging. So you have to update hit canvas after dragend:
greenLine1.on('dragend', function() {
guides2.draw();
});
http://jsfiddle.net/6f1e0c1p/1/
i created 2 sprite objects and want to check if they collide, but it doesnt seem to work.
My code:
creation of the sprites:**
.addGroup("flying", {width: 366, height: 254})
.addSprite("flyinganimation",{animation: flight,
posx: 0, posy: 0, width: 366, height: 254})
.addGroup("obstacles", {width: 169, height: 67})
.addSprite("obstaclenames", {animation: obstacleimage,
width: 169,height: 67,
posx: 300,
posy: 400})
looped code in the callback function:**
var collision = $("#flying,.group").collision("#obstacles,.group");
if (collision > 0)
{
document.write ("collision");
}
I see two potential problems here:
1) collision() returns a jQuery object so you will need to do a .size() in order to retrieve the number of collisions
2) you should apply collision() to only one object.
To sum up your first line should look like this:
var collision = $("#flying").collision("#obstacles,.group").size();