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

Unable to assert dynamic element #4872

Closed
herawatimanurung opened this issue Mar 16, 2020 · 2 comments
Closed

Unable to assert dynamic element #4872

herawatimanurung opened this issue Mar 16, 2020 · 2 comments
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. STATE: Duplicate An issues has been already reported in the other thread. TYPE: question The issue contains a question that won't be addressed.

Comments

@herawatimanurung
Copy link

herawatimanurung commented Mar 16, 2020

#4013 # What is your Test Scenario?
Assert dynamic element in testcafe by using regex

What is the Current behavior?

What is the Expected behavior?

Element exists

What is your web application and your TestCafe test code?

All class on the page is dynamic element, don't have ID or static element. Here's the screenshoot. I want to expect text "Chat with" "......." dynamic

Here's my code
test('Admin able to open chat with customer', async t => {
await t
// click on Conversation menu
.click(Selector('.nav-label').withText('Conversations'))
// login to livechat
await helper.adminLoginLiveChat()

let conversElemt =  Selector('.jss41.jss43.jss42').child('h5').withText('Conversations')
let img = Selector('img').withAttribute('src', customerImgSrc)
let customerName = 'Junita Lilianty'


await t
// expect go to livechat page
.expect(conversElemt).ok()  
// click on customer
.click(img)
// expect go to conversation
.expect(Selector('h5').withAttribute('class', '/jss\w+/ /jss\w+/').withText('Chat with Junita Lilianty').exists).ok('')
// .expect(Selector('div').)
I got error: Expected not truthy
</details>

<details>
<summary>Your complete configuration file (if any):</summary>

<!-- Paste your complete test config file here (even if it is huge): -->
</details>

<details>
<summary>Your complete test report:</summary>

<!-- Paste your complete result test report here (even if it is huge): -->
</details>

/<details>
<summary>Screenshots:</summary>
<!-- If applicable, add screenshots to help explain the issue. -->

</details>

### Steps to Reproduce:
<!-- Describe what we should do to reproduce the behavior you encountered. -->

1. Go to my website ...
3. Execute this command...
4. See the error...
 
### Your Environment details:
 
* testcafe version:                   <!-- run `testcafe -v` -->
* node.js version:                    <!-- run `node -v` -->
* command-line arguments:  <!-- example: "testcafe ie,chrome -e test.js" -->
* browser name and version: <!-- example: IE 11, Chrome 69, Firefox 100, etc. -->
* platform and version:          <!-- example: "macOS 10.14, Windows, Linux Ubuntu 18.04.1, iOS 12 -->
* other:                                   <!-- any notes you consider important -->
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 16, 2020
@Farfurix
Copy link
Contributor

Farfurix commented Mar 17, 2020

@herawatimanurung

Hello,

You need to use regular expressions without the extra ' symbols. Also, two regular expressions cannot be combined like that: /jss\w+/ /jss\w+/. I modified this part as follows:

- withAttribute('class', '/jss\w+/ /jss\w+/')
+ withAttribute('class', /jss\w+\sjss\w+/)

Please refer to the following examples:

  1. https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/functional-style-selectors.html#withattribute
  2. https://regex101.com/r/VR5mJ0/1

For the team. It duplicates the following issues:

  1. https://stackoverflow.com/questions/60482159/unable-to-find-element-when-uploading-file-in-testcafe
  2. https://stackoverflow.com/questions/60629541/how-to-define-an-selector-if-the-elements-are-dynamic-element
  3. Can't assert dynamic element #4858

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 17, 2020
@Farfurix Farfurix added the TYPE: question The issue contains a question that won't be addressed. label Mar 17, 2020
@Farfurix Farfurix added the STATE: Duplicate An issues has been already reported in the other thread. label Mar 17, 2020
@lock
Copy link

lock bot commented Mar 27, 2020

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 27, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. STATE: Duplicate An issues has been already reported in the other thread. TYPE: question The issue contains a question that won't be addressed.
Projects
None yet
Development

No branches or pull requests

2 participants