Which command may I use to drag and drop with cucumber-testing?
From watir-webdriver API docs:
a = browser.div(:id => "draggable")
b = browser.div(:id => "droppable")
a.drag_and_drop_on b
Related
I am trying to write a Cypress test that drags & drops column A onto column B on this webpage - https://the-internet.herokuapp.com/drag_and_drop
I installed the #4tw/cypress-drag-drop package & added the following to my support/commands.js:
require("#4tw/cypress-drag-drop");
Here is my Cypress code:
cy.get("#column-a").drag("#column-b", { force: true });
The test passes, but the columns aren't behaving the same way visually as it does when I manually drag column A onto column B.
Instead, this is what appears on the browser in Cypress Explorer:
As you can see, column A is greyed out, as if it were dragged, but not dropped
Can someone please point out what I'm doing incorrectly?
You cannot, the library does not support the correct events for this page.
But you can do it using Cypress commands.
These are the events used on the page
col.addEventListener("dragstart", handleDragStart, false);
col.addEventListener("dragenter", handleDragEnter, false);
col.addEventListener("dragover", handleDragOver, false);
col.addEventListener("dragleave", handleDragLeave, false);
col.addEventListener("drop", handleDrop, false);
col.addEventListener("dragend", handleDragEnd, false);
This is the test that passes
// check initial order
cy.get('div.column')
.then($cols => [...$cols].map(col => col.innerText.trim()))
.should('deep.eq', ['A', 'B'])
const dataTransfer = new DataTransfer;
cy.get("#column-a")
.trigger('dragstart', {dataTransfer})
cy.get("#column-b")
.trigger('dragenter')
.trigger('dragover', {dataTransfer})
.trigger('drop', {dataTransfer})
cy.get("#column-a")
.trigger('dragend')
// check new order
cy.get('div.column')
.then($cols => [...$cols].map(col => col.innerText.trim()))
.should('deep.eq', ['B', 'A'])
// check drag opacity reverted back
cy.get("#column-a").should('have.css', 'opacity', '1')
cy.get("#column-b").should('have.css', 'opacity', '1')
In that in studio I have created some fields in one module and i also add those fields in Layout. but i want to display the fields according to the selection, for example: if user select option-1 from dropdown field then it has to display say only three field, and if user select option-2 from dropdown field then it has to display say six fields. so i need to add some condition in the layout field. but i can't find any option there.. please help me to find out.
i also attached the example image below.
If you are using sugar 7.6 I can help,
You want to change the fields according to drop down values if i am not wrong .
For that you have to right a code in "record.js" and "create-actions.js" files . just write a js function.
This is an example for crerate-action.js
({
extendsFrom: 'CreateActionsView',
initialize: function (options) {
this.model.on("change:dropdown", this.renderFields, this);
},
renderFields: function () {
// write your code here
},
})
You need to modify the view definitions to add a script into the edit view of your module.
Example:
$viewdefs ['<Module Name>'] =
array(
'<View Name>View' =>
array(
'templateMeta' =>
array(
...
'includes' =>
array(
0 =>
array(
'file' => 'path/to/your/script.js',
),
1 =>
array(
'file' => 'path/to/your/script.js',
),
),
...
),
...
),
...
);
You then can use jQuery or any javascript library to hide or show the fields. if you are using SuiteR or SuiteP theme you can simply add/remove the hidden class to the elements.
Just make sure that you add all the fields into your view which you wish to show or hide.
To make this upgrade save modify or create
custom/modules/module name/metadata/editviewdefs.php for the edit view
custom/modules/module name/metadata/detailviewdefs.php for the detail view
There are many defined ways in sugarcrm, as you have created new fields, all you need to add dependencies on those fields like
$dictionary['YOUR_MODULE_NAME']['fields']['YOUR_FIELD_NAME']['dependency']='(equal($YOUR_DROPDOWN,"OPTION_1"))
see
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/#Visibility_Dependencies_in_Field_Definitions
This can also be added through Studio.
Go to Studio > module > fields > YOUR_FIELD > Dependent and add dependency.
I'm new to EaselJS. I wonder how I can detect a drop of one container on another container in EaselJS.
So I want to get the dropped container in an eventlistener of the drop target container.
Any examples on this?
I could not find this in the drag drop examples of EaselJS.
Thanks
You can also use getObjectsUnderPoint. Here is a quick sample I put together.
http://jsfiddle.net/lannymcnie/6rh7P/1/
var targets = stage.getObjectsUnderPoint(stage.mouseX, stage.mouseY);
This is from another post asking a similar question. I also posted more info about it.
EaselJS: connect 2 containers/shapes using a line
In the pressmove or stagemouseup event, you can verify if the mouse position (stage.mouseX and stage.mouseY) if over the parent container. To do the verification, you can use the hitTest.
Notice that, hitTest will only if your parent container has at least one mouse event listener, which I think is a bug on EaselJS 0.7.1
I made this class on coffeescript to solve that problem:
class DragContainer
DragContainer.prototype = new createjs.Container()
DragContainer::Container_initialize = DragContainer::initialize
constructor: (opts) ->
#initialize opts
DragContainer::initialize = (opts) ->
#Container_initialize()
#droptargets = new Array()
#on 'mousedown', #handleMouseDown
handleMouseDown: (e) =>
#on 'pressup', (ev)=>
#removeAllEventListeners 'pressup'
if #droptargets and #droptargets.length > 0
#evaluateDrop e
evaluateDrop: (e) =>
target = null
dropped = false
for drop in #droptargets
pt = drop.globalToLocal stage.mouseX, stage.mouseY
if drop.hitTest pt.x, pt.y
target = drop
dropped = true
if dropped
#dispatchEvent {type: 'dropped', currentTarget: target}
else
#dispatchEvent {type: 'dropped', currentTarget: null}
The droptargets property is an array that keeps the objects you want to associate with the drop of your container.
I´m developing an application using Zend Framework 2 and I need to translate the text of the radio buttons ("Show", "Hide") that I´ve created in my form:
//within the Form
public function addRadioButtons ()
{
$isPublicRadioButtons = new Element\Radio('isPublic');
$isPublicRadioButtons->setAttribute('id', 'isPublic')
->setAttribute('value', '0')
->setValueOptions(array(
'0' => 'Show',
'1' => 'Hide',
));
$this->add($isPublicRadioButtons);
}
What do I have to do in the view side to be able to translate them?
I know that to render translations to the views I need to use $this→translate() view helper. So within the view I´ll have to somehow call the text of the radio buttons..
//Whithin the view
echo $this->translate($someHowCallTheTextOfRadioButton('isPublic') , $textDomain, $locale);
Look at FormLabel section to read about translating labels in zend framework 2. I think that most important thing to remember is:
If you have a translator in the Service Manager under the key,
‘translator’, the view helper plugin manager will automatically attach
the translator to the FormLabel view helper. See
Zend\View\HelperPluginManager::injectTranslator() for more
information.
How to properly setup translator you have in ZendSkeletonApplication
In your view you can do something like this:
$this->formRadio()->setTranslatorTextDomain('textdomainhere');
You can have your form implement the TranslatorAwareInterface and, if you are using PHP 5.4+, have it use the TranslatorAwareTrait (otherwise you simply have to implement the interface yourself). You can now inject a translator instance into your form, e.g. in the form's factory. Then you can translate the labels as follows:
//within the Form
public function addRadioButtons ()
{
$isPublicRadioButtons = new Element\Radio('isPublic');
$isPublicRadioButtons->setAttribute('id', 'isPublic')
->setAttribute('value', '0')
->setValueOptions(array(
'0' => $this->getTranslator()->translate('Show'),
'1' => $this->getTranslator()->translate('Hide'),
));
$this->add($isPublicRadioButtons);
}
I have spent hours on the net to find a solution, but nothing works.
I have a form divided into 2 subForms (I couldn't get the accordion pane to work)
like this :
$sfBase = new Zend_Dojo_Form_SubForm('base_info');
$sfBase->setName('base_info')
->setAction('/product/add?f=1');
$id = new Zend_Form_Element_Hidden('id');
$id->addFilter('Int')
->setAttrib('style', 'display:none');
$nom = new Zend_Dojo_Form_Element_TextBox('name');
$nom->setLabel('Nom du produit')
->setTrim(true)
->setValue("Entrez le nom")
->setPropercase(true);
$sdesc = new Zend_Dojo_Form_Element_TextBox('sdesc');
$sdesc->setLabel('Courte description du produit')
->setTrim(true)
->setValue("Description")
->setPropercase(true);
$sfBase->addElements(array($id, $nom, $sdesc);
$submitSubBase = new Zend_Dojo_Form_Element_SubmitButton('sub1');
$submitSubBase->setLabel('ok');
$sfBase->addElement($submitSubBase);
and another subform which contains few other elements :
$sfComp = new Zend_Dojo_Form_SubForm('comp_info');
$sfComp->setName('comp_info')
->setAction('/product/add?f=2');
...
$submitSubComp = new Zend_Dojo_Form_Element_SubmitButton('sub2');
$submitSubComp->setLabel('envoyer');
$sfComp->addElement($submitSubComp);
$this->addSubForms(array('base_info' => $sfBase,
'comp_info' => $sfComp
));
In my controller I display the entire instanciated form :
$this->view->base = $form;
but whenever I click on a submit button nothing happens. I tried placing a single submit button added to the form (not to a subForm)
with setAction :
$baseForm->setAction($this->view->url(
array('controller' => 'Product', 'action' => 'add', 'id' => '1'), 'default',
true));
but it is the same, finally I divided the form into two distinct Zend_Form instead of subforms, but that is not very clean...
So having tried multi page forms, subForms and dojo containers unsuccessfully I don't know what to do, and any help would be welcome !
thank you
I don't know if this will help at all but here is my answer.
If the MAIN form is not Dojo enabled, have you called Zend_Dojo::enableForm() in the init method? Is the MAIN form extending frorm Zend_Dojo_Form? If it's extending from Zend_Dojo_Form then you don't have to call Zend_Dojo::enableForm().
The Dojo forms submit through the use of javascript. You should have some javascript on the client side that can handle the responses from the server that will come back. If you don't have javascript on the client side to handle these returns, then you won't 'see' the results of the submit.
Try this, write some javascript using the dojo toolkit that will create an alert box when it receives something from the server. This way, if you click on the submit button and an alert box comes up you'll know that the form was submitted.