Can I change text output of failed tests in Nightwatch.js?
× Password Input in "Log in" Pop-up (#password) visible for 16000ms - expected "visible" but got: "not found"
I expect:
× Password Input in "Log in" Pop-up (#password) NOT FOUND for 16000ms
It depends on what you are using. If you are using any of the expect commands then no, you cannot customize the message. However, if you are using assert then you can.
browser.assert.visible('.should_be_visible', 'This is my custom message');
Old question but the above answer is not strictly correct. While some expect commands do not support an optional message, there are also those that do. You can look through the api docs which will tell you which commands support messages and which do not here: http://nightwatchjs.org/api
What is important to note is that optional messages as shown in the answer above will output regardless of pass/fail, meaning they are not strictly 'error messages'.
One way to adapt this is through your naming, for example if a test is looking for an element on a page, do not use a message of 'Cannot find element' as this will display even if the element is found successfully. Instead use something like 'Looking for element'...
.waitForElementVisible('#element', 1000, 'Looking for something on some page')
This at least tells the user what the test was trying to do when it failed but also makes sense when it passes. Hope that helps.
Related
tl;dr - approval settings not working in Outlook Flow
Of 130 staff, I need to when they leave who has returned all their kit. My Column is titled 'Further Action Required.'
I want to set up a weekly email which, if this cell is set to 'Yes', emails the area manager asking them if kit has been returned. Answer is 'Yes' or 'No'.
If they click 'Yes', it emails me and other staff, it also overwrites the cell so that next time it runs, it doesn't email them.
If they hit 'No', I get a notification, nothing happens and it triggers the following week.
I created the whole thing - it doesn't work. So I pared it down to test different areas and it doesn't seem to like the condition for approval....I get Bad Request error, a branch condition not satisfied error and condition failed error. Any ideas? I'm stumped.
Flow error:
Edit view:
Point of clarity - it sent the approval email (I tried the 'Select Options' version but doesn't send any follow up email).
Then I select 'Yes' (returned kit)
and it returns the 'no' (kit not returned) email and then throws up the error above.
When I select No, it does the same....
I'm a bit late to this thread, but for future inquiries, I believe the YES/NO button does not actually function with the words "Yes" or "No." I was getting this same error until I changed the button to a choice and added in my option "Completed." I then changed the condition to look for the word "Completed," and the e-mail was sent. However, when I made the change to choice, I noticed that the field then classified the previous "Yes" option as "1". Thus, it is my take that the "YES/NO" button is actually looking for the words "1" or "0". And if you, like I had, input the word "Yes" into the condition, it fails because it doesn't find it. I did not test this idea, though, since "Completed" works for my needs.
I usually report the events when it passes or fails like:
Reporter.ReportEvent micPass," Title of the passed Event", " Description of Passed Event"
And
Reporter.ReportEvent micFail," Title of the failed Event", " Description of Failed Event"
Is it a good idea to hard code the line number in the title or description of the event like ?
Reporter.ReportEvent micFail," Test Failed at Line 432 ", " Please check line 432 "
To answer the 2nd part of your question, hard-coding will not be a good idea. If you hard-code the line number and in the future, a few lines get added to the code above that line number, the whole point hard-coding goes in vain as the report will now contain the incorrect-line number(which was hard-coded).
And for the first part, I can understand why you want the line-number to be reported. But I don't think there is any "predefined" way of doing it.
But, you can make your own function to get the line number. Here's an idea that you can implement:
Go to the location where your QTP test is stored. Get the full path of the file script.mts(you can find it inside the Action1 Folder). Also, this path can be constructed dynamically if you have good framework and proper folder structure.
After getting the path, you can open that file(script.mts) as a text stream(using the filesystemobject) in Read only mode.
Now you can traverse through the file line-by-line searching for the text "Reporter.ReportEvent micPass," Title of the passed Event", " Description of Passed Event"". After you have found it, you can easily get the line number and return that from your function to store it in some variable which you can use while reporting.
I have not tried this method myself but would have surely given it a try, If I really needed it.
Hardcoding is not a good idea from an end user perspective. In case it's a regression suite it could be used by a tester who doesn't know how to debug the code or analyze. To get the root cause of the failure through reporting (micPass/micFail) you can further refine your scripts
I am trying to write a simple cucumber step where it checks to see if one of two phrases are on the page, but my attempts at if statements have failed. Here is the step i currently have
Then(/^I should see a pdf preview of the magazine$/) do
#browser.windows.last.use
#browser.text.should_not include "Page not found"
But, ideally, I want the step to check and see if the text "Page not found" is present, if so fail the test. If "page not found" is NOT present, then check to see if the text "Forbidden" is present, if so, fail the test. If neither phrase is present, then pass the test.
Where i think I am stumbling, is I dont know how to tell it, to stop and fail the test.
Ideally, I would think it would look like this...
if text "Page not found" visible?
fail test
elseif text "Forbidden" visible?
fail test
else
pass test
But I dont know how to put that into ruby/watir-webdriver code
Do I just have to make it throw exceptions if the test fails? If its that easy, will that fail the test, or pass it but give me a message and how do I make it pass if neither phrase is visible?
A Cucumber step will stop and fail the test as soon as any of the assertions fail (or an exception is raised). Conversely, a Cucumber step will pass if all assertions pass (or there are no exceptions raised).
As a result, you can simply do:
Then(/^I should see a pdf preview of the magazine$/) do
#browser.windows.last.use
#browser.text.should_not include "Page not found" # first assertion
#browser.text.should_not include "Forbidden" # second assertion
end
With this step:
In the situation where "Page not found" is displayed, the first assertion will fail. As a result the step will be marked as Fail (with the message that the text includes "Page not found"). The rest of the Cucumber step will not be executed - ie the second assertion will not be tested.
In the situation where "Forbidden" is displayed, the first assertion will pass so Cucumber will continue to execute the line. When the second assertion is run, it will fail and therefore cause the step to fail (with the message that the text includes "Forbidden").
In the situation where neither text is present, both assertions will pass. Since Cucumber was able to complete the step without any failed assertions (or exceptions), the step will be marked as Pass.
In the situation where both texts are displayed, the step will Fail, but the error message will only indicate the first failure - ie "Page not found" was displayed.
I added a Response Assertion to my test to hit the home page of our local site. I added this to the "Patterns to Test" in a Response Assertion:
Email
This worked. ( To get that label, I did View Source in Firefox and copied the code including all white space. I then clicked "Add" for the Response Assertion and pasted the copied code directly into JMeter this way. ) When I run my test, my test will pass with just this label as a Pattern to Test. It shows no red errors after running it in JMeter.
However, when I add the following span tag by clicking on "Add" to get a new entry in the same Response Assertion, the test will fail.
1.7.0.147
So, to be clear, I had 2 entries for the same Response Assertion...one for the "Email" label and one for the "footerVer" span. Each of these had their own separate line under the same Response Assertion.
Also, for most tests that passed and did not pass, I had "Main Sample only", "Text Response", and "Contains" selected. I did try to change to "Matches" and "Equals" but I just ended up with different errors. So, I wanted to stay on "Contains" for now since my other entry for the "Email" label worked when I had "Contains" selected.
Under the "View Results Tree", JMeter tells me about this failure when I add the span tag:
Assertion error: false
Assertion failure: true
Assertion failure message: Test failed: text expected to contain /
1.7.0.147
/
I also have had success with other tags like , , , , etc. along the way.
Only the tag seems to be giving me a problem right now. Any ideas?
===============================
Added config:
I am not able to add the full response since it is not my code, but the company's code. But, I can try to get something on here that me be useful in a different way.
This is the response dealing with the version copied verbatim from the response tab within JMeter:
<span class="footerVer">
1.7.0.147
</span>
Hope that helps
I would suggest using XPath assertions for multiline HTML entities parsing as page source may vary and it can be a headache to deal with flaky HTML code.
Following XPath expression validates whether inner text of span with footerVer class equals 1.7.0.147
//span[#class='footerVer']/text()='1.7.0.147'
Use Substring instead of Contains for Pattern Matching rules:
http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion
So, I found one way around this. Although, I do not think this is the most efficient way to verify the test. I split the span into 3 individual lines in the Response Assertion.
<span class="copyright marginLeft_100">
© Copyright 2002-2013 Turning Technologies, LLC. All Rights Reserved.
</span>
==========================
I do not really mind the first 2 lines. But, the third line is so generic it really does no good if not combined with the beginning tag
Well, for now, I can at least confirm something. Also, I left it on "Contains", even though I took a look at the other link posted above, because all of my other tags presented no problem when it was on "Contains". Hope this helps someone else also.
Can anyone explain why the first of these expressions works as expected while the second does not? What is the difference between "number one" and DisplayForm#"number one"?
Block[{$MessagePrePrint}, Message[f::event, DisplayForm#"number one"]]
Block[{$MessagePrePrint}, Message[f::event, "number one"]]
The error message is a clue:
An unknown box name (Times) was sent as the BoxForm for the expression. Check the format rules for the expression.
I presume $MessagePrePrint is low level, like $PreRead, and its output needs to be a valid box structure.
Works on my machine (v8.0.1, W7-64):