Checkbox enabled on screen but code says disabled - ruby

OK i have a weird one
I have a check-box that is visible on the page and is click-able. But when i view source it says:
<input disabled="disabled" type="checkbox" class="billingCheck" />
my code to is follows:
browser.checkbox(:class => 'billingCheck').set
I get the following error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-2.0.4/lib/watir/element.rb:84:in
`asse rt_enabled': object {:class=>"billingCheck"} and is disabled
(Watir::Exception: :ObjectDisabledException)
I tried to use the following but it passed right over the code.
if
browser.checkbox(:class => 'billingCheck').visible?
browser.checkbox(:class => 'billingCheck').set
end
Any ideas? Thanks in advance.

Try this:
browser.checkboxes(:class => 'billingCheck').each {|checkbox| checkbox.set if checkbox.visible?}

Related

Cannot verify text in textfield - cypress

I have got the below textfield:
<div _ngcontent-c11="" class="input-container" data-testid="my-textfield"><div _ngcontent-c11="" class="title-container-input"><input _ngcontent-c11="" type="text" ng-reflect-model="my content" class="ng-pristine ng-valid ng-touched"></div><!--bindings={
"ng-reflect-ng-if": "false"
}--></div>
I am trying to check that the textfield has the content "my content"
i have tried the below:
cy.getBySel('my-textfield').should('have.text', 'my content')
also tried:
cy.getBySel('my-textfield').should('contain', 'my content')
i have tried include also but its not working.
I am getting the below as error:
expected <div.input-container> to have text my content, but the text was ''
Does anyone have any idea why this is not working.
If i do a type it is working but verifying the textfield content is not working.
Thank you
You can thy this:
cy.getBySel('my-textfield').find('input').should('have.text', 'my content')
//OR
cy.getBySel('my-textfield').find('input').should('have.value', 'my content')

Cypress picks up the wrong element?

I am trying to find and click this element using Cypress:
<input class="form-control btn btn-primary" type="button" value="Log out">
I have tried several variations, but the closest is this:
cy.get("input[type='button']").filter('.btn-primary').should('have.value','Log out').click()
So when I run this, I get the following response:
expected [ <input.form-control.btn.btn-primary>, 1 more... ] to have value Log out, but the value was Edit.
Sure, there is a button there called Edit, but it is not the one I want. I have specified what I want with the should('have.value','Log out') clause.
So - why does it insist on trying to use the wrong element & failing?
Update: I finally got this working.
This is the solution I went with in the end:
cy.get("input[type='button']").filter('.btn-primary').eq(1)
.should('have.value','Log out').then(($btn) => {
$btn.click()
})
can you try
cy.get('input').find("[value='Log out']").click()
or
cy.get("[value='Log out']").click()
Obviously you need your developers to add ids, but I know your situation.
You could also try if there is only one btn-primary
cy.get('.btn-primary').click()
This was the solution that worked for me:
cy.get("input[type='button']").filter('.btn-primary').eq(1)
.should('have.value','Log out').then(($btn) => {
$btn.click()
})
How about to set an unique testID for that button and get it as simple as it can be.
Something like:
data-test-id= "log-out-button" //put that in your button code
and then in Cypress:
cy.get('[data-test-id="log-out-button"]')
.click()
even though you can set a function to get those testID's more effectively:
Command.Cypress.add('getTestID', (testID) => {
cy.get(`[data-test-id="${testId}"]`)
})
and now everything you do for getting that button (or every element with testID is: cy.getTestID('log-out-button')

How to use multiselect in codeception and laravel

Is it possible to use multiselect boxes on Codeception?
My form code:
<form accept-charset="utf-8" class="form-vertical" id="solicitor-form" method="POST" action="http://mytest.dev/role">
<select multiple="true" id="optgroup" name="solicitor[]">
<option value="1" selected>Yorkshire</option>
<option value="2" selected>Quarry</option>
<option value="3" selected>William Hurst</option>
</select></div></div>
<input class="btn-large btn-success btn" type="submit" value="Update Access">
</form>
I've tried something like this for the test:
$i->SeeOptionIsSelected("#solicitor-form", 'Yorkshire');
$i->SeeOptionIsSelected("#solicitor-form", 'Quarry');
But codeception fails on SECOND select. So then I tried this:
$i->SeeOptionIsSelected('#solicitor-form select[name=solicitor[]]', 'Yorkshire');
$i->SeeOptionIsSelected('#solicitor-form select[name=solicitor[]]', 'Quarry');
but it doesnt seem to resolve solicitor[] correctly, specifically the [] because it trips itself up with the pattern match.
Edit: I tried Daverts answer like this:
$i->selectOption('optgroup',array('Quarry', 'Yorkshire'));
But this is the output when running the test:
* I select option "optgroup","lambda function"
It seems the "lambda function" is not returning the correct result?
Sorry for a delay.
It looks like this feature was not documented. Sorry, I totally forgot to update docs, when released 1.6.3.
You can pass an array of options as a second parameter to select multiple options.
$I->amOnPage('/form/select_multiple');
$I->selectOption('What do you like the most?',array('Play Video Games', 'Have Sex'));
$I->click('Submit');
Thanks, I will update a reference soon.
The bug is exactly with [] as far as I can see in my application, for example I have this select:
<select multiple="true" class="span h300" id="products[]" name="products[]">...</select>
and when I do:
$I->selectOption('Products', array('value', 'someOtherValue') );
I'll get the same error as you do.
As you can see I have some additional classes, .span and .h300 so I've used .h300 selector which is unique on that page and the test works perfectly, the values are in db and verification works as expected...
So to sum it up my selector which works is:
$I->selectOption('.h300', array('value', 'someOtherValue') );
Just my 2 cents on the issue, don't have enough time now to investigate what causes the problem with []...

Yii, Selenium and multiple submit buttons

I've got a form with two submit buttons which I want to test using Selenium.
View:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'profile-form',
'enableAjaxValidation' => true,
'action' => '',
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => true,
'validateOnType' => false,
),
));
?>
<input name="cancel" type="submit" value="Cancel" />
<input name="submit" type="submit" value="Save changes" />
<?php $this->endWidget(); ?>
Controller is nothing special, you can assume it just prints "Your profile has been saved" or "Your profile was not saved" depending on what $_POST['cancel'] it gets
Test code:
<?php
$this->open('/profile_form_url');
$submit_button_selector = 'css=#profile-form input[name="submit"]';
$cancel_button_selector = 'css=#profile-form input[name="cancel"]';
$this->clickAndWait($cancel_button_selector);
$this->assertTextPresent('Your profile was not saved');
$this->open('/profile_form_url');
$this->clickAndWait($submit_button_selector);
$this->assertTextPresent('Your profile has been saved');
The problem is that code works great in browser but not when running tests in Selenium/Firefox. When running tests, it "sees" the first button only (Cancel), clicking "Save changes" has the same effect. If you place Save changes button first, it will not "see" Cancel button.
If you turn enableAjaxValidation off, it works both in browser and Selenium, but I'd like to have a more elegant solution of course. Like for example turning off the AJAX validation on clicking on Cancel.
No, the problem doesn't depend on which locator you use for buttons (xpath, css, id).
clickAndWait() calls waitForPageToLoad() - ajax form validation will generally not trigger this event (unless a page loads), so your test will never complete; this is probably why if you turn ajax validation off it works.
You might want to look at the other options selenium provides (this is an old link to the free phpunit pocket guide that describes some other options - it's based on phpunit 3.1 though) such as using click() and then using waitForCondition() with some javascript to run and return true if the new text is displayed.

How to set the value for the textarea in Codeigniter?

echo form_textarea('general4', set_value('general4'), 'class="general"');
the set_value function doesn't seem to work with the textarea so I tried this:
<textarea name='general4' class="general"><?=set_value('general4')?></textarea>
But still not working, any ideas?
to use form_textarea() in CI you pass parameters rows and coloumns as below
$data = array(
'name' => 'txt_area',
'id' => 'txt_area',
'value' => 'johndoe',
'rows' => '5',
'cols' => '10',
'style' => 'width:50%',
);
echo form_textarea($data);
for more details refer CI user guide https://www.codeigniter.com/user_guide/helpers/form_helper.html#form_textarea
What you did is set the name of the textarea field to: 'general4'. I think what you meant to do is return an actual string to your textarea to pre-populate it with data from a post request or a MySQL database or something like that. There are a number of ways to achieve this.
Method 1:
Set a second parameter in the set_value() function eg:
<textarea name='general4' class="general"><?=set_value('general4', $foo)?></textarea>
Method 2:
You could always use the built in form_textarea() function. Docs found here
Examples:
Generic
<?=form_textarea('name', 'value', 'attributs')?>
Case
<?=form_textarea('general4', $general4, "class = 'foo'")?>
From the CI Documentation:
set_value()
Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form.
<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
The problem was that I didn't need the textfield to be required. So I didn't set any rules in the action url. So I added this:
$this->form_validation->set_rules('general4', 'general question' , 'trim|xss_clean');
And it worked fine!

Resources