0
I have a form with Brands, Models and Versions of Cars.
I’m using Phpunit to test the form. It works that way:
User selects the brand, then the select of templates is loaded and at the end the select of versions is loaded.
My application is made with Laravel 5.2 and I looked in the documentation how to create a test for forms and did so:
$this->visit('/compre-seu-carro')
->select('Chevrolet', 'marca_compra')
->select('Agile', 'modelo_compra')
->select('2010', 'ano_compra')
->select('Agile LT 1.4 8V (Flex) 2010', 'versao_compra')
->type('Dona Florinda', 'Nome')
->type('[email protected]', 'Email')
->type('999999', 'Telefone')
->select('melhor condicao a vista', 'troca')
->press('Avançar');
When I go to excommunicate Phpunit he shows me this message:
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
..E 3 / 3 (100%)
Time: 565 ms, Memory: 18.00MB
There was 1 error:
1) WebsiteTest::testNewBuyRegistration
InvalidArgumentException: Input "modelo_compra" cannot take "Agile" as a value (possible values: ).
/var/www/html/mapadocarro/vendor/symfony/dom-crawler/Field/ChoiceFormField.php:140
/var/www/html/mapadocarro/vendor/symfony/dom-crawler/FormFieldRegistry.php:122
/var/www/html/mapadocarro/vendor/symfony/dom-crawler/Form.php:77
/var/www/html/mapadocarro/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:576
/var/www/html/mapadocarro/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:556
/var/www/html/mapadocarro/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:543
/var/www/html/mapadocarro/tests/WebsiteTest.php:37
ERRORS!
Tests: 3, Assertions: 9, Errors: 1.
I don’t think it is loading the template and version selects. How could I resolve this error to test the form submission ?
Ajax of the form:
$('.select-brand').change(function() {
var brand = $('.select-brand');
if (brand.val() != '') {
var model = $('.select-model');
var idBrand = $('.select-brand').val();
brand.attr('disabled', 'true');
model.attr('disabled', 'true');
model.html('<option value=""> Carregando modelos... </option>');
$.get(url + '/get-models/' + idBrand, function (models) {
model.empty();
model.html('<option disabled selected value=""></option>');
$.each(models, function (key,value){
if(!value){
model.html('<option value="">Nenhum modelo encontrado!</option>');
}else{
model.append('<option value="'+ value.name +'">'+ value.name +'</option>');
}
});
brand.removeAttr('disabled');
model.removeAttr('disabled');
});
}else{
var model = $('.select-model');
model.empty();
model.attr('disabled', 'true');
model.html('<option disabled selected value=""></option>');
}
});
there is some ajax request?
– RFL
The element
<select name="modelo_compra">
or<input type="radio" name="modelo_compra">
is there? Post the HTML content.– Guilherme Nascimento
@Rafaelacioly Yes !
– Lucas Lopes
@Guilhermenascimento It is a select that is empty until the choice of the brand and then populated with the models of the brand.
– Lucas Lopes
The test is happening before the data is placed in select.
– RFL
https://laravel.com/docs/5.2/testing#testing-json-Apis
– RFL
But you are using
name
orid
html? Put the page HTML structure/compre-seu-carro
. Detail, I’m pretty sure you don’t recognize Javascript by testing, so you’d have to use route testing or simulate the data population in select– Guilherme Nascimento