Vuetify Select Component and Cypress - vuetify.js

I have a component with a Vuetify Select component:
<v-select
:items="corporations"
label="Corporation name"
data-test="corporation-name"
outlined
></v-select>
And I want to simulate a selection with a Cypress test:
cy.get('[data-test="corporation-name"]').select('Thorgate');
Unfortunately, I can't and I have this error message:
CypressError: cy.select() can only be called on a <select>. Your subject is a: <input data-test="corporation-name" id="input-13" readonly="readonly" type="text" aria-readonly="false" autocomplete="off">
I have also try to enter the value with a type()but Cypress told me
CypressError: Timed out retrying: cy.type() failed because this element is readonly:
Any idea, please?

The errors are pretty self-explanatory.
You're trying to apply a cy.select() method to an <input> tag, when you need a <select> tag
You're trying to .type() into a <input readonly>
cy.select() can only be applied to a <select> tag. If your v-select component renders a "custom select that is a bunch a dynamic divs and inputs INSTEAD of a select", then you need to create a custom Cypress command to handle a cy.customSelect() behavior. For example, it would: click on the main wrapper, find a option by typing words, and click on it... therefore selecting the option
For the second one, because your input is readonly, you can try to use {force: true} in your options when typing (cy.type("text", {force: true})

A little bit late, but, I hope this can help someone. ;)
The easier way I found to solve the problem with vuetify v-select, is using {force: true}, as stated by Jordan, and "pressing enter" at the end of string, like so:
cy.get('[data-test="corporation-name"]').type('Thorgate{enter}',{force:true});
https://docs.cypress.io/api/commands/type#Arguments

Related

Not able to check checkbox elements in Laravel Dusk

I'm trying to do test cases for my application on Laravel 6.0 with Dusk. I'm facing some difficulties in checkbox selection, it is not finding the 'check' element.
As per the documentation I have used the check method and defined the selector with id
My ID is : company-search-type-Investor and my code is:
$browser->scrollToElement('#company-search-type-Investor')
->assertNotChecked('#company-search-type-Investor')
->check('#company-search-type-Investor')
->pause(1000)
Its strange that my test with ->assertNotChecked('#company-search-type-Investor') gets passed but ->check('#company-search-type-Investor') gives an error:
Facebook\WebDriver\Exception\UnrecognizedExceptionException: element click intercepted: Element <input data-v-c1e51704="" id="company-search-type-Investor" type="checkbox"> is not clickable at point (192, 497). Other element would receive the click: <label data-v-c1e51704="" class="kt-checkbox" style="margin-bottom: 6px; font-size: 1.1rem;">...</label>
Any suggestions are welcomed. Thanks.
This could be happening because CSS is being applied that moves the checkbox behind the label. There are two ways to check the checkbox.
You can call click on the label:
$browser->click("label[data-v-c1e51704='']");
You can call sendKeys on the checkbox:
$browser->element("#company-search-type-Investor")->sendKeys(WebDriverKeys::SPACE)

parsley.js 'fails' when trying to validate checkbox

We are re-designing a site and part of that re-design involves making the site accessible to screen readers and the like. I'm using latest version (2.8.0). Here's what's happening --- validation for all text, select and textarea fields in our forms work perfectly. In order to be accessible, checkbox and radio inputs are wrapped in tags. The html for a set of checkboxes looks like this:
<div class="form-group">
<p id="applicant_type_desc" style="margin-bottom: 6px;"><strong>I am: <span class="text-danger" aria-hidden="true">*</span><span class="sr-only">Required</span></strong> <em class="small">(check all that apply)</em></p>
<div class="checkbox">
<label id="applicant_type_patient_desc">
<input type="hidden" name="applicant_type_patient" id="" value="N">
<input type="checkbox" name="applicant_type_patient" id="applicant_type_patient" value="Y" {checked_applicant_type_patient} aria-labelledby="applicant_type_desc applicant_type_patient_desc" data-parsley-multiple="type" data-parsley-error-message="Please specify whether you are a patient, relative, employee or other.">
A patient
</label>
</div>
followed by more checkbox divs without error messages and ended with an end div for the for form-group wrapper.
If I load the form and click 'submit', all the text fields are validated properly. If I add 'required' to the checkbox above, when 'submit' is clicked nothing happens and the form is submitted with no validation at all.
The same thing happens when I try to validate a radio button set as required.
There is some custom jQuery and parsley code which creates a div to hold all the error messages and transforms the error messages into links to the field id so that a screen reader can follow them and focus on the field in error. But imho, this should have no effect on why the form validation doesn't kick in.
I'm absolutely baffled.
FYI - I tried this using an earlier version (2.0.3) of parsley and the validation actually worked, although all my custom error processing was ignored.
Any insight would be greatly appreciated.
As it turns out, parsley handles the errorswrapper element differently for text, textarea and selects then it does for checkboxes and radio buttons.
The starting wrapper element for text, textarea and select contains the parsley-data-id attribute whereas checkbox and radio button elements contain the parsley-data-multiple attribute whether that was generated by parsley or entered manually in the html.
My code was looking for parsley-data-id and, of course the jquery selector failed and generated an error. A colleague was able to spot this for me while we were looking at the page in chrome inspector. Once i saw the error, making a simple adjustment to the form:error event function allowed everything to work.

can not find element using watir webdriver

I am trying to click on the button.
<input data-ember-action="797" value="Search Now" class="cta-1st clrboth primary search-button firepath-matching-node" type="button">
but it keep showing an error of not finding the element to click.
it finds all the elements until the end but when it comes to "click" it throws an error. My code is like this:
#browser.div(:id=>'ember730').section(:class=>'tab-pane fade active in').form(:class=>'flight-search ').input(:class=>'cta-1st clrboth primary search-button').click
Am I missing something?
I am using Watir
Thank you for all the help here. the problem was, I had a wrong reading in one of the elements.
I was missing this part.
#browser.div(:id=>'ember730').section(:class=>'tab-pane fade active in').form(:class=>'flight-search ').text_field(:class=>'cta-1st clrboth primary search-button firepath-matching-node').click
As there is value="Search Now" section of type="button" here, following simple code snippet should do. I have made this working using Watir in my project..
#browser.button(value: "Search Now").click

Is there any version of Angular Material md-select with select all option

I have been using Angular Material in one of my project. Suddenly I realized the need for having a select all option on md-select. I think I will pull a git request for the same.
However, currently I am looking for a similar drop down structure with checkboxes (like md-select multiple) but also a select all option.
I am aware that I can push a dummy empty entry into md-select option array and manipulate reverse way on its selection. But it would require a lot of code change in my current structure and would also not be a elegant thing to do.
I tried looking for it in bootstrap and jQuery-UI, but could not find one yet. Is there any such control known to anyone. Any redirection will be helpful.
You can do that easily inside the HTML. It requires only one line of code, or two lines, if you want a "select none" option as well. For example
<md-input-container>
<label>Users</label>
<md-select ng-model="selectedUser" multiple=""
ng-model-options="{trackBy: '$value.id'}">
<md-optgroup label="Users">
<md-option ng-repeat="user in users"
ng-value="user">{{ user.name }}</md-option>
</md-optgroup>
</md-select>
</md-input-container>
<button ng-click="selectedUser=users">all</button>
<button ng-click="selectedUser=[]">none</button>
Example in Plunker.
Edit: I updated the below Plunker to show the "all" button inside the select box next to the "Users" optgroup title. The relevant change:
<md-select ng-model="selectedUser" multiple="" ng-model-options="{trackBy: '$value.id'}">
<button ng-click="doSelectedUser()" style="float:right">all</button>
<md-optgroup label="Users">

A way around Element cannot be scrolled into view - Watir-webdriver with Ruby

So, we have the following code in our page:
<div class="toggle-wrapper">
<input id="HasRegistration_true" class="registration_required toggle" type="radio" value="True" name="HasRegistration" data-val-required="The HasRegistration field is required." data-val="true">
<label for="HasRegistration_true" class="">On</label>
<input id="HasRegistration_false" class="registration_required toggle" type="radio" value="False" name="HasRegistration" checked="checked">
<label class="checked" for="HasRegistration_false">Off</label>
</div>
These are 2 radio buttons. 'On' and 'Off'. 'Off' is the default value.
Using Watir-webdriver and Ruby, we want to select the 'On' radio button. We do so like this:
browser.radio(:id => "HasRegistration_true").set
But in doing so, we get the following error:
`WebElement.clickElement': Element cannot be scrolled into view:[object HTMLInputElement] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)
We know Selenium 2 scrolls the page to the element, so trying to scroll down is useless.
We are always using the latest releases of watir-webdriver and ruby.
We can't change the HTML of the page since we're QA engineers.
Here are two solutions that have worked for me:
There is a Ruby gem called watir-scroll that can work.
Then
require 'watir-scroll'
browser.scroll.to browser.radio(:id, "HasRegistration_true")
If you don't want to add a gem, my co-worker suggested something that somewhat surprisingly (to me) had the same effect as the above code:
browser.radio(:id, "HasRegistration_true").focus
browser.radio(:id, "HasRegistration_true").set
In my code, ".focus" scrolled straight to the element that was previously not visible. It may work for you as well.
First of all try locating the element using XPATH:
browser.element(:xpath, "//input[#id='HasRegistration_true']").click
or
alternatively if it is a hidden element you are trying to locate then you are better off using CSS. Download firebug add-on for firefox and copy the CSS path of your element.
It should be something like:
browser.element(:css => "the CSS path you have copied from Firebug").click
One of the 2 should do it for you!!
Best of luck!
You could manipulate the html on the fly by executing some javascript to make the radio element settable. To execute javascript on a page, do something like:
#browser.execute_script("your javascript here")
I used something like the following javascript to strip the class out of a label tag which moved it out of the way of the input tag I was attempting to act on for a Chrome specific problem I had.
execute_script("$(\"label.classname\").removeClass(\"classname inline\")")
If the element is contained within a form and a div (Wrap) class I found that I had to do the following to click the 'No' radio button on the "https://quote.comparethemarket.com/Motor/Motor/AboutYourVehicle.aspx?" page:
div_list = #browser.form(:action => "AboutYourVehicle.aspx?ton_t=CTMMO&prdcls=PC&rqstyp=newmotorquote&AFFCLIE=CM01").div(:class => "inputWrap").divs(:class => "custom-radio")
And then:
div_list[1].click
Hope this solves your issue too :-)
I'm not using watir but I have the same error as you "...could not be scrolled into view ...". I tried to use watir just to solve it and didn't work for me. Then, I use an ActionBuilder (move_to with click) and the error disappeared.
My line to avoid the error is:
#driver.action.move_to(*webelement*).click.perform
I hope it will be useful for you

Resources