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)
Related
I am currently testing my login page in flutter and I want to make sure that the values I am entering are the ones being passed when I click log-in (username and password). I want to do more than just validate if the inputs are in a certain format. I would like to see if I wrote "Tom123" it returns "Tom123". What is the best way to go about testing this?
I believe there is a documentation specific for this kind of test:
enterText method
Give the text input widget specified by finder the focus and replace
its content with text, as if it had been provided by the onscreen
keyboard.
I am currently trying to fill in the Google sign in form using Capybara, but I am having the hardest time getting it to find the hidden field to fill in.
Here is the HTML for the field I am trying to fill in.
Here is the test code
require "rails_helper.rb"
RSpec.describe "Sign in page" do
it 'displays the page intention' do
visit('/mars')
expect(page).to have_content 'Sign in with Google'
end
it 'fills in user information' do
find(:xpath, '//*[#id="identifierId"]', visible: false)
end
end
And this is the error I am getting.
First, you shouldn't be attempting to fill in a hidden field, you should be interacting with the visible elements like a user would have to. In this case, it may mean needing to click on another element first to trigger the email input to change to being active. Something like
first('form div[jscontroller]').click
fill_in('identifierId', with: email)
should work for the google login page.
Note: also you should be preferring CSS over XPath for finding elements whenever possible, since it will be faster, easier to read, and can't unintentionally break element scoping (// vs .// in XPath - see https://github.com/teamcapybara/capybara#beware-the-xpath--trap)
Update: Additionally all the it blocks are completely independent, with a browser reset in between, so you need to visit the desired page for each one (if all the it blocks in the describe require visiting the same page you could put the visit in a before block.
Note: this all assumes you are actually using the Selenium driver for this test, as the question tags imply.
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.
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'),
);
}
I'm using Selenium to ease my testing burden and I have about 1,000 different drop down list combinations (spread across multiple pages and drop down lists) that need to be tested. Basically, what I would like to do is select each <option> inside of a <select>, click the Submit button, select an item (first, second, third, etc.) in the drop down list on the resulting page, click submit, and then go back and select the next item, in sequence. Each time, it should assert that a certain value (related to the drop down list value selected) is present on the final page. Does anybody know if this kind of logic is possible in Selenium?
I'm having a hard time explaining this, so hopefully this pseudo code clears things up
foreach option in select
select option
submit form
foreach option in select
select option
submit form
assert that page contains text that matches selected values
Edit: I have selected values from the drop down list while the recorder is playing, but it seems like the recorder isn't picking up the selected drop down list values. Nor have I been able to figure out how to perform the operation for each <option> in a <select>.
The first question I have is whether or not it's even possible. If it is, could somebody please point me in the right direction to get me started?
Edit 2: I'm not opposed to using another web automated testing utility. If anybody has any recommendations for a free alternative, please feel free to make that recommendation.
What language are using Selenium in? If you're just using Selenium by writing HTML, I'd recommend switching to a programming language and using Selenium RC -- bindings are available for a wide variety of languages, such as Java and Python. In Java, I believe the following would do what you want:
void test(Selenium browser, String startPageUrl,
String firstFormLocator, String firstSelectLocator,
String secondFormLocator, String secondSelectLocator) {
browser.open(startPageUrl);
for (String option : browser.getSelectOptions(firstSelectLocator)) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
for (String subOption : browser.getSelectOptions(secondSelectLocator) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
browser.select(secondSelectLocator, "label=" + subOption);
browser.submit(secondFormLocator); // Or click the submit button
// Do your assertions
}
}
}
The code isn't exactly readable, so it might be worth some time abstracting the page away slightly using the Page Object pattern. This also helps make the code more maintainable, for instance when you change the ID of an element, you only need to change it in the page object rather than every test.
Also bear in mind that doing this 1000 times isn't going to be quick. It might be worth seeing if you do similar testing just below the web interface to allow quicker feedback from tests, and then test the web interface is using the lower layer correctly. Also, do you really need 1000 tests? It seems that there's some redundancy in testing here -- is the 1000th test going to fail if the last 999 have passed?