Asserting text of element with  
up vote
2
down vote
favorite
I need to check the text of a Div tag and ensure if it is showing the correct text of not
here is the HTML Code:

Here is the step definition i wrote to assert the content
Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
});
But cypress is throwing an error:

I am not sure where i am going wrong !!! :(
any help is appreciated
mocha chai cypress
add a comment |
up vote
2
down vote
favorite
I need to check the text of a Div tag and ensure if it is showing the correct text of not
here is the HTML Code:

Here is the step definition i wrote to assert the content
Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
});
But cypress is throwing an error:

I am not sure where i am going wrong !!! :(
any help is appreciated
mocha chai cypress
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I need to check the text of a Div tag and ensure if it is showing the correct text of not
here is the HTML Code:

Here is the step definition i wrote to assert the content
Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
});
But cypress is throwing an error:

I am not sure where i am going wrong !!! :(
any help is appreciated
mocha chai cypress
I need to check the text of a Div tag and ensure if it is showing the correct text of not
here is the HTML Code:

Here is the step definition i wrote to assert the content
Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
});
But cypress is throwing an error:

I am not sure where i am going wrong !!! :(
any help is appreciated
mocha chai cypress
mocha chai cypress
edited 19 hours ago
Brendan
577314
577314
asked Nov 19 at 16:02
Venkata
899
899
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.
cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
expect(text.trim()).equal('DKK 15.00');
});
Sometimes you have to remove the trailing spaces
add a comment |
up vote
0
down vote
This looks like a similar problem to Replacing " " from javascript dom text node.
Please try this command chain
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
.children('.c-ledger__section')
.find('.c-ledger__row-name')
.contains(labelText)
.parent();
parentElement.find('.c-ledger__row-amount')
.invoke('text')
.should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.
cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
expect(text.trim()).equal('DKK 15.00');
});
Sometimes you have to remove the trailing spaces
add a comment |
up vote
0
down vote
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.
cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
expect(text.trim()).equal('DKK 15.00');
});
Sometimes you have to remove the trailing spaces
add a comment |
up vote
0
down vote
up vote
0
down vote
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.
cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
expect(text.trim()).equal('DKK 15.00');
});
Sometimes you have to remove the trailing spaces
I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.
cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
expect(text.trim()).equal('DKK 15.00');
});
Sometimes you have to remove the trailing spaces
answered Nov 20 at 14:32
Maccurt
8461718
8461718
add a comment |
add a comment |
up vote
0
down vote
This looks like a similar problem to Replacing " " from javascript dom text node.
Please try this command chain
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
.children('.c-ledger__section')
.find('.c-ledger__row-name')
.contains(labelText)
.parent();
parentElement.find('.c-ledger__row-amount')
.invoke('text')
.should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);
add a comment |
up vote
0
down vote
This looks like a similar problem to Replacing " " from javascript dom text node.
Please try this command chain
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
.children('.c-ledger__section')
.find('.c-ledger__row-name')
.contains(labelText)
.parent();
parentElement.find('.c-ledger__row-amount')
.invoke('text')
.should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);
add a comment |
up vote
0
down vote
up vote
0
down vote
This looks like a similar problem to Replacing " " from javascript dom text node.
Please try this command chain
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
.children('.c-ledger__section')
.find('.c-ledger__row-name')
.contains(labelText)
.parent();
parentElement.find('.c-ledger__row-amount')
.invoke('text')
.should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);
This looks like a similar problem to Replacing " " from javascript dom text node.
Please try this command chain
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
.children('.c-ledger__section')
.find('.c-ledger__row-name')
.contains(labelText)
.parent();
parentElement.find('.c-ledger__row-amount')
.invoke('text')
.should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);
answered Nov 20 at 18:56
Hiram K. Hackenbacker
1536
1536
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378473%2fasserting-text-of-element-with-nbsp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown