Skip to content

Commit

Permalink
fix: clear() and type('{selectall}{del}') behavior difference. (#14498)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh authored Mar 2, 2021
1 parent 7a6f70b commit eee7488
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/driver/cypress/fixtures/dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@
iframe:<br>
<iframe id="iframe" src="/fixtures/generic.html"></iframe>
</div>
<div id="does-not-wrap-input">Text</div>
<div id="input-wrap">
<input style="width:100%" />
</div>
<div>
Cross domain iframe:<br>
<iframe id="iframe-cross-domain" src="http://localhost:3501/fixtures/generic.html"></iframe>
Expand Down
14 changes: 12 additions & 2 deletions packages/driver/cypress/integration/commands/actions/clear_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,24 @@ describe('src/cy/commands/actions/type - #clear', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.clear()` failed because it requires a valid clearable element.')
expect(err.message).to.include('The element cleared was:')
expect(err.message).to.include('`<div id="dom">...</div>`')
expect(err.message).to.include('`<div id="does-not-wrap-input">Text</div>`')
expect(err.message).to.include(`A clearable element matches one of the following selectors:`)
expect(err.docsUrl).to.equal('https://on.cypress.io/clear')

done()
})

cy.get('div').clear()
cy.get('#does-not-wrap-input').clear()
})

it('throws center hidden error if the element is too high', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.clear()` failed because the center of this element is hidden from view')

done()
})

cy.get('#dom').clear()
})

it('throws on an input radio', (done) => {
Expand Down
66 changes: 48 additions & 18 deletions packages/driver/src/cy/commands/actions/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,29 @@ module.exports = function (Commands, Cypress, cy, state, config) {
})
}

const node = $dom.stringify($el)
const callTypeCmd = ($el) => {
return cy.now('type', $el, '{selectall}{del}', {
$el,
log: false,
verify: false, // handle verification ourselves
_log: options._log,
force: options.force,
timeout: options.timeout,
interval: options.interval,
waitForAnimations: options.waitForAnimations,
animationDistanceThreshold: options.animationDistanceThreshold,
scrollBehavior: options.scrollBehavior,
}).then(() => {
if (options._log) {
options._log.snapshot().end()
}

if (!$dom.isTextLike($el.get(0))) {
return null
})
}

const throwError = ($el) => {
const node = $dom.stringify($el)
const word = $utils.plural(subject, 'contains', 'is')

$errUtils.throwErrByPath('clear.invalid_element', {
Expand All @@ -511,24 +531,34 @@ module.exports = function (Commands, Cypress, cy, state, config) {
})
}

return cy.now('type', $el, '{selectall}{del}', {
$el,
log: false,
verify: false, // handle verification ourselves
_log: options._log,
force: options.force,
timeout: options.timeout,
interval: options.interval,
waitForAnimations: options.waitForAnimations,
animationDistanceThreshold: options.animationDistanceThreshold,
scrollBehavior: options.scrollBehavior,
}).then(() => {
if (options._log) {
options._log.snapshot().end()
if (!$dom.isTextLike($el.get(0))) {
options.ensure = {
position: true,
visibility: true,
notDisabled: true,
notAnimating: true,
notCovered: true,
notReadonly: true,
}

return null
})
return $actionability.verify(cy, $el, options, {
onScroll ($el, type) {
return Cypress.action('cy:scrolled', $el, type)
},

onReady ($elToClick) {
let activeElement = $elements.getActiveElByDocument($elToClick)

if (!options.force && activeElement === null || !$dom.isTextLike($elToClick.get(0))) {
throwError($el)
}

return callTypeCmd($elToClick)
},
})
}

return callTypeCmd($el)
}

return Promise
Expand Down

4 comments on commit eee7488

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on eee7488 Mar 2, 2021

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.7.0/circle-develop-eee7488dc30a83e3a37b681d6ff9f42af3ceedfe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on eee7488 Mar 2, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.7.0/appveyor-develop-eee7488dc30a83e3a37b681d6ff9f42af3ceedfe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on eee7488 Mar 2, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.7.0/appveyor-develop-eee7488dc30a83e3a37b681d6ff9f42af3ceedfe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on eee7488 Mar 2, 2021

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.7.0/circle-develop-eee7488dc30a83e3a37b681d6ff9f42af3ceedfe/cypress.tgz

Please sign in to comment.