Codeception ignores "required" from input fields - codeception

I have form which contains HTML5 "required" in input type text and password. But when I run test cases using codeception, it is not considering that required property and submits the form.

This is the correct behavior! What do you Codeception to do? The 'required' trait should be processed by the browser. If you submit an incomplete form, something happens - it's not automatically an error, depending on what you're trying to do.

Related

What is the proper way to test mandatory field in selenium

I am testing my web application using Selenium. All the form validation in the web application is done by HTML5 and some JS(for safari browser). I want to know what is the proper way to test the form validation.
Currently I am using one approach, i.e Before I filled up a mandatory field I clicked on the submit button. If the page is not refreshed then I assume the form validation working correctly. But I think there should be a better approach to do it. I am unable to find any proper solution. Any suggestion will be highly appreciated.
I also go through this link. But it is not working for me because it is not enough to have required attribute (eg required attribute does not work in older Safari browser).
Rather than checking if the page is refreshed or not, you should instead expect that it is not and that a certain error message or field highlighting or something is applied to the current page. When in an error state, the input fields probably get given an extra class, or an error div/span might be added to the DOM, try checking for that sort of thing

Yii: ClientSide Validation on FileField and TextField

I have a yii form with a file field and a normal text field for supplying an external image url. I managed to get a normal server validation working which checks that only one of the two form fields is filled out (because you can either provide a local file for uploading OR an external picture URL). Important to notice is, that the attribute value of the "file field" seems only to be available after the $_POST var is set, meaning that a normal custom validation rule in the Model Class won't work since the $_POST value of the file field is only available after submission (in the $_FILES var).
But if you look at my provided picture below, I want also a ClientSide Validaton, so that the user gets immediate feedback that it's not allowed to fill out both fields. But how do I accomplish that? I'm sitting on this problem for about 2 days, half of the time on searching for solutions...I am new to Yii.
http://www.prism-informatics.com/images/demo.png
Best wishes,
S
I am not completely sure what your problems is as you didnt provide any code but i assume you forgot :
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}

Filling in hidden inputs with Behat

I am writing Behat tests and I need to change the value of a hidden input field
<input type="hidden" id="input_id" ..... />
I need to change the value of this input field, but I keep getting
Form field with id|name|label|value "input_id" not found
I have been using the step
$steps->And('I fill in "1" for "input_id"', $world);
Is there something special which needs to be done to modify hidden input fields?
Despite the fact that user can't fill hidden fields, there are some situations when this is desirable to be able to fill hidden field for testing (as usually rules have exceptions). You can use next step in your feature context class to fill hidden field by name:
/**
* #Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/
*/
public function iFillHiddenFieldWith($field, $value)
{
$this->getSession()->getPage()->find('css',
'input[name="'.$field.'"]')->setValue($value);
}
Rev is right. If real user can can change input fields via javascript by clicking a button or link. try doing that. Fields that are not visible to user are also not visible to Mink also.
Or else what you can do is Call $session->executeScript($javascript) from your context with $javascript like
$javascript = "document.getElementById('input_id').value='abc'";
$this->getSession()->executeScript($javascript);
and check if that works
It's intended by design. Mink is user+browser emulator. It emulates everything, that real user can do in real browser. And user surely can't fill hidden fields on the page - he just don't see them.
Mink is not crawler, it's a browser emulator. The whole idea of Mink is to describe real user interactions through simple and clean API. If there's something, that user can't do through real browser - you can't do it with Mink.
(source: http://groups.google.com/group/behat/browse_thread/thread/f06d423c27754c4d)

Is there a way to get a QTP to fail a test if a particular element appears on a web page

I am trying to test a JSP based web application with QTP. On some of the pages the JSP is coded to return a particular div element, which will have an ID attribute, to the browser, only of the underlying model has a certain boolean flag set. I'd like to be able to develop a QTP test that fails if the div is present in the returned web page. However, the QTP documentation doesn't seem to have any details on how to do this.
The point is to detect if the condition applies and then explicitly fail the test.
If Browser("b").Page("p").WebElement("html tag:=div", "html id:=theId").Exist Then
''# Report failure
Reporter.ReportEvent micFail, "Element Exists", "It shouldn't"
''# if you also want to stop the test
ExitTest
End If
The default behavior for QTP is to write in 'Report' when a check point fails. i.e. if an element is not found on the page , automatically the QTP will write in the log report. In order to disable that , and to customize your report depending on your test scenarios, you can disable the report logging from the
beginning and write only in case you found an abnormal behavior.
Reporter.Filter = rfDisableAll
'check point validations
Reporter.Filter = rfEnableAll

MonoRail - Server-side vs. Client-side Form Validation

I'm using MonoRail and was wondering how it decides when to use client-side vs. server-side validation? In my model class I have [ValidateNonEmpty] on two properties, one is a textbox, the other is a dropdown. The textbox triggers client-side validation on form submission, if I leave the dropdown empty though it posts back to the server and returns back the validation error from server-side. Is there a way to get the dropdown to trigger client-side validation? Also it's odd because after the postback, it clears what I had entered in the dropdown but maintains the state of the textbox (viewstate anyone??)
Thanks,
Justin
It viewed source and I saw that it was using jQuery for the client-side validation. It had:
"business.businesstype.id":{ required: "This is a required field" },
for the dropdown, which wasn't working. I noticed that it was using 0 as the default dropdown value so I manually put in firstoptionvalue and that got it working:
$FormHelper.Select("business.businesstype.parent.id", $businessTypes, "%{value='id', text='name', firstoption='Select a Business Type', firstoptionvalue=''}")