Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  54] [ 3]  / answers: 1 / hits: 5877  / 3 Years ago, tue, june 15, 2021, 12:00:00

In our tool we create a url which quiet a few parameters with values. And I want Cypress to check the contents of this url.


The example url is:
http://someUrl.com/sap/?action=create&type=sw&notifno=70432&repby=TRL&repres=ABC&geo=017&startloc=12345&notiftp=2021-06-15T08:06:42.379Z&scen=1.0&refno=1234567&awsrt=-&vrst=&sbst=&objtp=art&objtxt=&objfc=&tel=084123456&prio=4 Niet urgent&priost=&prioen=&wbi=&facts=&bgeb=AB-CD&bequi=


I have stored the url in 'href' variable but how i can now check all the attr and their values? I really don't have a clue.


More From » cypress

 Answers
20

I'd parse it into an object and then use .wrap(), .its(), and .should() commands:


const url = "http://someUrl.com/sap/?action=create&type=sw&notifno=70432&repby=TRL&repres=ABC&geo=017&startloc=12345&notiftp=2021-06-15T08:06:42.379Z&scen=1.0&refno=1234567&awsrt=-&vrst=&sbst=&objtp=art&objtxt=&objfc=&tel=084123456&prio=4 Niet urgent&priost=&prioen=&wbi=&facts=&bgeb=AB-CD&bequi=";
const arr = url.split('/?')[1].split('&');
const paramObj = {};
arr.forEach(param => {
const [ key, value ] = param.split('=');
paramObj[key] = value;
});

cy
.wrap(paramObj)
.its('tel')
.should('eq', '084123456');

or if you want to assert more properties:


cy
.wrap(paramObj)
.then(obj => {
expect(obj.notifno).to.eq('70432');
expect(obj.tel).to.eq('084123456');
});

[#1238] Monday, June 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deiong

Total Points: 15
Total Questions: 103
Total Answers: 99

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
deiong questions
Mon, Nov 22, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Tue, Jul 21, 20, 00:00, 4 Years ago
;