How can html text be partially validated in Cypress? - cypress

I would like to validate or assert the text inside the div element of the following html has the correct email id
The html snippet is as follows:
<div _ngcontent-mpt-c200="" class="welcome-msg">
Hi, Welcome to our blog, dummyuser#test.com (
<a _ngcontent-mpt-c200="" class="pointer">not Dummy User?
</a>)
</div>
My cypress assertion is:
cy.get('.welcome-msg').invoke('text').should('include.text', 'dummyuser#test.com')
I get this error:
Timed out retrying after 4000ms: You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
text
The invalid subject you asserted on was:
Hi, Welcome to our blog, dummyuser#test.com (not Dummy User?)
To use chai-jQuery assertions your subject must be valid.
I also tried using:
cy.get('.welcome-msg').should('contain.text', 'dummyuser#test.com')
and this:
cy.get('.welcome-msg').invoke('html.text').then(userInfoText => {
userInfoText.should('contain.text', 'dummyuser#test.com')
})
Has anyone got an idea on how to make this assertion work?

In your first attempt you invoked the text() to get the text of the jQuery element followed by an assertion that essentially does the same thing before asserting the text.
You can do either of two things with your first attempt.
cy.get('.welcome-msg').should('include.text', 'dummyuser#test.com')
or
cy.get('.welcome-msg').invoke('text').should('include', 'dummyuser#test.com')

Related

JSON assertion failing in JMeter

On sending an incorrect username/password, the server application sends this JSON:
{"result":"error","additional-info":"Incorrect username or password"}
I have made the assertion:
Server sends:
But the tree viewer seems to indicate that there is an error. The response log file has this message
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1606209008151,39,SignInRequest,401,Unauthorized,SignInUsers 1-1,text,**false**,**path can not be null or empty**,570,263,1,1,http://localhost:9000/ws/users/signin,37,0,21
What am I doing wrong in asserting the response?
UPDATE
I added json assertion but when I run the test, the screen looks like this (red color but not sure what the reason is)
Interestingly, if I change the validation from error to "error" then I can see reason (kind of expandable tree) which when using just error doesn't appear.
If you want to compare the full response - you need to go for Response Assertion.
however it's very sensitive to any changes, a whitespace or line break will cause the failure.
JSON Assertion allows executing arbitrary Json Path queries, so if you want to assert additional-info element you should go for something like:
and this one is for result:
You are validating the expected results, so you don't fail
Check Invert assertion checkbox if you want it to fail (or change to success response)
Invert assertion (will fail if above conditions met) Invert assertion (will fail if above conditions met)

W3C validator: “Element head is missing a required instance of child element title”

For http://www.filmiclub.com/, I am getting this error in the W3C validator:
Element head is missing a required instance of child element title
But when I copy the HTML and do validation with "Validate by direct input", the HTML is 100% error free and there is no validation error.
Do you know why PHP generated HTML with this error?
Choose the "Show source" option and click Revalidate, you'll see the cause. your PHP script is crashing when receiving a request from the validator, so then PHP sends out its own error message response instead of your website.
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: HTTP_ACCEPT</p>
<p>Filename: helpers/common_helper.php</p>
<p>Line Number: 7328</p>
Apparently the W3C's validator sends a HTTP request that does not have the Accept: header, but your PHP code expects the HTTP_ACCEPT header to be present and fails because it is absent.
Change your PHP code to detect the presence (or lack of) Accept header, like so:
if( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
// code here
}

JMeter XPath results are missing expected items

Using XPath assertion: //ul/#class after a HTTP request, the assertion returns:
success_message_1=links
success_message_2=accordion vertnav vertnav-top grid-full
success_message_3=grid-full classic
success_message_4=checkout-types
success_message_5=links
success_message_matchNr=5
It is missing exactly one element, which happens to be the success message I need to find. The structure of the success message is:
<ul class="messages"><li class="success-msg"><ul><li>Message</li></ul></li></ul>
Strangely targeting the item with //li[#class="success-msg"] returns nothing. Using jQuery I did a simple jQuery('ul') and it matches all of the <ul> including the missing one.
I've checked the response and the success message does exist in the response, but why can't I select it with XPath?
The correct XPath expression if you need to obtain "Message" "vanilla" XPath selector will look like
//li[#class='success-msg']/ul/li/text()
If your page is not XML/XHTML compliant you may require to enable "Use Tidy" box in your XPath Assertion.
Particularly for your code following XPath Assertion works for me:
//li/text()='Message'
You may wish to use XPath Extractor combiner with Debug Sampler and View Results Tree listener to see what is the output of your XPath queries and once you'll get "true" - the query is OK to be used in the assertion.

Is there a way to make angular run all the validations of an input instead of stoping when the first validation fails?

I'm having problems trying to make angular run all the validations of an input at once.
Here is a jsfiddle example of my problem http://jsfiddle.net/carpasse/GDDE2/
if you type 1 character on the email input you get this "The minimum lenght is 3." error message
and is not until you type 2 more characters than you get the other error message "This is not a valid email."
Does anybody know how to make angular show both error messages at the same time??
Thanks a lot in advance
You problem is not that all the validators are not being run - they are!
Remember that the way these validations work is by passing the view values through a pipeline of transformation functions, which can also specify the validity of the value.
The problem is that the min length validator passes undefined down the pipeline if it is not valid and that the email validator says that undefined is a valid email address!
Try creating your own validation directive that says that undefined is not a valid email address and you will find both errors are showing: http://jsfiddle.net/eKfj3/

Assert returned status code HTTP 400 as a success

I have been using JMeter for a while and only for load tests. I was wondering if I can use it for ordinary functionality testing.
For example: I have a malformed XML and an application returns 400 Bad Request which I expect to be returned - so it's correct but JMeter resolves it as a failure.
I tried Response Assertions but it didn't work...
Is this possible with JMeter?
To test a non 200 response code, you must check the 'Ignore Status' field in the Response Assertion. Without this, the test will always fail regardless of the response assertion.
So here is what you need to do to test the http response code 400:
Add a new Response Assertion.
Set the following assertion properties:
check the 'Response Code' radio button.
check the 'Ignore Status' box.
check the 'Equals' radio button in the Pattern Matching Rules.
click the 'Add' button.
enter '400' in the row in Patterns to Test.
Done.
Easily.
See answers to this.
You can also possibly try NOT check-box in Pattern Matching Rules Response Assertion.

Resources