Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clear actions in ActionChains #7943

Merged
merged 5 commits into from
Feb 14, 2020
Merged

Fix clear actions in ActionChains #7943

merged 5 commits into from
Feb 14, 2020

Conversation

bayilyas
Copy link
Contributor

@bayilyas bayilyas commented Jan 17, 2020

Clear actions in ActionChains object after performing

Fixes #7913

Description

ActionChains assigned to a variable does not clear previous actions after perform and reset_actions does not solve the issue.

Motivation and Context

Assigning ActionChains to a variable and using it in different actions causes a repetition of all previous actions. The example below, in the second drag and drop, actions will be executed for element1 and element2 and not only for the element2. Clearing device.action in the perform method solve the issue.

Not: clearing actions on the remote end with driver.execute(Command.W3C_CLEAR_ACTIONS) can be also executed in the pefrom method.

actions = ActionChains(driver)
actions.drag_and_drop(element1, target).perform()
actions.reset_actions()
actions.drag_and_drop(element2, target).perform()

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@claassistantio
Copy link

claassistantio commented Jan 17, 2020

CLA assistant check
All committers have signed the CLA.

Clear actions in ActionChains object after perform

Fixes #7913
@isaulv
Copy link
Contributor

isaulv commented Feb 3, 2020

Suppose you run perform an action twice. Would this still work?
Example:

action = Actions(driver)
action.move_to_element(element)
action.perform()
action.perform()

@bayilyas
Copy link
Contributor Author

bayilyas commented Feb 3, 2020

For the case you want to run perform twice, it will do nothing like in Java. Should it be possible to repeat perform and is correct? If so, clearing actions can be implemented in clear_actions.

@isaulv
Copy link
Contributor

isaulv commented Feb 6, 2020

@bayilyas seems like you need to merge master.
@AutomatedTester Can you review and merge this if its acceptable?

@AutomatedTester AutomatedTester merged commit 20cae7e into SeleniumHQ:master Feb 14, 2020
Copy link

@Proc-64core Proc-64core left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -53,26 +53,27 @@
def key_action(self): def key_action(self):
return self._key_action return self._key_action
@Property @Property
def pointer_action(self): def pointer_action(self):
return self._pointer_action return self._pointer_action
def add_key_input(self, name): def add_key_input(self, name):
new_input = KeyInput(name) new_input = KeyInput(name)
self._add_input(new_input) self._add_input(new_input)
return new_input return new_input
def add_pointer_input(self, kind, name): def add_pointer_input(self, kind, name):
new_input = PointerInput(kind, name) new_input = PointerInput(kind, name)
self._add_input(new_input) self._add_input(new_input)
return new_input return new_input
def perform(self): def perform(self):
enc = {"actions": []} enc = {"actions": []}
for device in self.devices: for device in self.devices:
encoded = device.encode() encoded = device.encode()
if encoded['actions']: if encoded['actions']:
enc["actions"].append(encoded) enc["actions"].append(encoded)
device.actions = []
self.driver.execute(Command.W3C_ACTIONS, enc) self.driver.execute(Command.W3C_ACTIONS, enc)

 def clear_actions(self):	    def clear_actions(self):

.

@bayilyas bayilyas deleted the clear-actions-fixes branch February 27, 2020 20:51
@TheMakerOfWorlds
Copy link

will the fix be available in v4? and is there any way to get this fix now?

@TheMakerOfWorlds
Copy link

will the fix be available in v4? and is there any way to get this fix now?

nvm just added your change in the code thank you so much

@bayilyas
Copy link
Contributor Author

bayilyas commented May 24, 2021

I did commit to clear actions after performing actions. With the commit, it will be impossible to reuse the actions after perform.
In Java, there's no such possibility but in Python was and I more than sure that we shouldn't remove this possibility.

Prepared action can be reused several times and reset_actions should be used to clear previous actions. Is this correct behavior? I think my commit was a mistake and should be revert.
@AutomatedTester what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActionChains does not reset actions
6 participants