Skip to content

fix(webApi): selectOption method #4157

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

Merged
merged 1 commit into from
Jan 26, 2024
Merged

fix(webApi): selectOption method #4157

merged 1 commit into from
Jan 26, 2024

Conversation

dyaroman
Copy link
Contributor

Motivation/Description of the PR

I was trying to select an option by value '1999' from year of birth select and I used Playwright 'selectOption' method for this. But I got error:
image

Then I debugged method 'selectOption' and found that '.textContent()' method return value with spaces: ' 1999 ', that why I got error. I think this is a realistic case, many template engines can produce additional spaces.

Here HTML of select element:
image

I suggest to trim the value returned by the 'textContent' method. If 'textContent' returned 'null' we will get type error, but 'catch' block will catch this error and return 'option' argument.
What do you think?

optionToSelect = await el.locator('option', { hasText: option }).textContent();

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@dyaroman
Copy link
Contributor Author

Or we can get value from value attribute:

optionToSelect = await el.locator('option', { hasText: option }).getAttribute('value');

What do you think?

@kobenguyent
Copy link
Collaborator

kobenguyent commented Jan 26, 2024

I guess the other Web helpers may get the same error, would you mind checking it? and add tests for it here https://github.com/codeceptjs/CodeceptJS/blob/3.x/test/helper/webapi.js#L391

@dyaroman
Copy link
Contributor Author

I will try.

trim text content value
@dyaroman
Copy link
Contributor Author

@kobenguyent please take a look. I have run tests local, all works good. Only WebDriver_test.js can't run local, don't have selenium.
Also added new test and markup for it.

@kobenguyent
Copy link
Collaborator

thanks @dyaroman!

@kobenguyent kobenguyent changed the title fix: selectOption method fix(webApi): selectOption method Jan 26, 2024
@kobenguyent kobenguyent merged commit 4837073 into codeceptjs:3.x Jan 26, 2024
@dyaroman dyaroman deleted the patch-1 branch January 26, 2024 14:39
kobenguyent added a commit that referenced this pull request Feb 2, 2024
* updated performSwipe with w3c protocol

* chore(deps-dev): bump @wdio/utils from 8.27.2 to 8.28.8 (#4152)

* fix: I.say would be added to Test.steps object (#4145)

* release 3.5.12 (#4156)

* release 3.5.12

* fix(webapi): selectOption method (#4157)

trim text content value

* DOC: Update contributor faces

* fixed typescript parameter inputs count

* chore(deps-dev): bump testcafe from 3.3.0 to 3.5.0 (#4160)

Bumps [testcafe](https://github.com/DevExpress/testcafe) from 3.3.0 to 3.5.0.
- [Release notes](https://github.com/DevExpress/testcafe/releases)
- [Changelog](https://github.com/DevExpress/testcafe/blob/master/CHANGELOG.md)
- [Commits](DevExpress/testcafe@v3.3.0...v3.5.0)

---
updated-dependencies:
- dependency-name: testcafe
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* updated performSwipe with w3c protocol

* fixed typescript parameter inputs count

* chore(deps-dev): bump @wdio/sauce-service from 8.27.0 to 8.29.1 (#4161)

* removed elementId parameter

* updated performSwipe with w3c protocol

* fixed typescript parameter inputs count

* removed elementId parameter

* run mobile tests

* run mobile tests

* run mobile tests

* tweak ci

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: KobeN <7845001+kobenguyent@users.noreply.github.com>
Co-authored-by: Roman Diachenko <dyaroman@gmail.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: kobenguyent <kobenguyent@gmail.com>
@kobenguyent kobenguyent mentioned this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants