i need to parse a string in cypress. i am trying to grab a piece of string with the methods provided by javascript. but it doesn't work gives me an error:
type i have this string:
text2 = "change status id 423 in Cult"
text1 = 423
var id = text2.split (' ')
expect (text1).to.eq(id[3])
how can i do such a thing in cypress. I should take part of a string and pare it but with the split method it gives me an error
below the error returned:
i need to parse a string in cypress. i am trying to grab a piece of string with the methods provided by javascript. but it doesn't work gives me an error:
type i have this string:
text2 = "change status id 423 in Cult"
text1 = 423
var id = text2.split (' ')
expect (text1).to.eq(id[3])
how can i do such a thing in cypress. I should take part of a string and pare it but with the split method it gives me an error
below the error returned:
Share Improve this question edited Nov 12, 2020 at 9:50 bigeyes asked Nov 12, 2020 at 8:55 bigeyesbigeyes 1191 gold badge2 silver badges12 bronze badges 8- Pls add the error so we can debug the situation – Rosen Mihaylov Commented Nov 12, 2020 at 9:00
- Edit: First - it seems you arenet selecting any text Second: It seems like it fails because it is a JQuery element. Try using cy.wrap(text2).split(' ')> – Rosen Mihaylov Commented Nov 12, 2020 at 9:26
-
@bigeyes What do you get when you use
cy.log(text2)
– Alapan Das Commented Nov 12, 2020 at 9:35 - I updated the post image @AlapanDas with cy.log(text2) is highlighted in purple – bigeyes Commented Nov 12, 2020 at 9:41
- if i put cy.wrap(text2).split(' ') get the following error cy.wrap(...).split is not a function @RosenMihaylov – bigeyes Commented Nov 12, 2020 at 9:42
1 Answer
Reset to default 2You have to use then() instead of should() -
cy.get('p.text-lg').invoke('text').then((text) => {
var splitText = text.split(' ')[5]
expect(splitText).to.equal(291)
})