Verifying the presence of an option in a list? - ruby

I'm writing automated tests using Cucumber and SitePrism. One test adds a user role to a list, and I'm having trouble verifying the presence of the role (to verify it's successfully assigned) in the final steps.
The gherkin is...
Scenario: Assigning roles to a user
Given I have reached the user edit view in the admin
When I click the Assign Roles tab
And select the first value in the Add Role dropdown
And click Add role
Then I should receive the message of save successful
And the role should be present in the current role list
...With And the role should be present in the current role list being the step I'm having trouble with. After the And click Add role step executes, the HTML for the list appears as such...
<dd>
<select id="current-role-a02322d1-8add-4234-aeca-02d3fca2a239" class="current-role" name="role_id" multiple="multiple">
<option title="System Administrator Role" value="1">Administrator</option>
</select>
</dd>
This one I'm stuck on. What do I set the element as on the page model, and what do I write in my step definitions to verify the presence of <option title="System Administrator Role" value="1">Administrator</option> and make the step fail if it's not present? I would prefer to be checking for value="1" instead of the title or text.
Thank you in advance for the help!

Define a method on your page model that will extract the value that you are trying to assert. This method will contain the element definition and then .text or .value at the end of your element definition. Here you can use value = "1" or title.
In your step definition, call the method and assert that the returned value is equal to "Administrator".

Related

How to store array of values in application.properties file and fetch it to display them in a thyme leaf template

I wanted to store a list of blood groups in the application properties file so that it can be fetched and displayed in a dropdown list while the user is asked to pick a blood group. I'm using thyme leaf template engine. I wanted to use this to avoid hard coding as much as possible(for learning experience). Any ideas?
In application.properties file, define one property bloodGroups
bloodGroups=A+,B+,AB+
In java class(may be controller) bind this property
#Value("${bloodGroups}")
private String[] bloodGroups;
In your controller class set this as model attribute
model.addAttribute("bloodGroups", bloodGroups);
Access in thmeleaf
<select required="true" name="bloodGroup" id="bloodGroup">
<option th:selected/>
<option th:each="bloodGroup: ${bloodGroups}" th:value="${bloodGroup}" th:text="${bloodGroup}"></option>
</select>

Cypress get element by aria role

<form>
<input type='text' name='user'/>
</form>
Tying to get the input element via aria role 'textbox'. I've tried many different ways and everything comes back as 'not found'
cy.get('role=input')
cy.get('[role=input]')
cy.get('role="input")
cy.get('[role="input"])
cy.get('role=textbox')
cy.get('[role=textbox]')
cy.get('role="textbox")
cy.get('[role="textbox"])
cy.get('form[role="textbox"]')
cy.get('form[role=textbox]')
I've tried other things as well like capitalizing role. it's my understanding from the documentation that
cy.get('[role="textbox"]')
should work but returns not found.
You can see from dev-tools that it does have the role
If a role is explicitly set, then you can assert like that: cy.get([role="${role}"], ...rest)
If the role is implied by tag name, you can assert to the tag name as suggested by Rosen.
If you want to assert a specific input, you can use e.g. the name like: cy.get('input[name="user"]')
You can use this css selector
cy.get('input[type="text"]')
cy.findByRole('textbox');
You can try the above

Is it possible to create a user group in Joomla 2.5 that includes everyone that is NOT a member of a particular group?

I have two similar pages that need a menu link. Page 1 is shown to members of Group A. Page 2 is shown to everyone who is not a member of Group A. I have a "Guest" group which would include everyone who is not logged in. But some users are members of group A and Group B. I cannot figure out how to only show one link to them, based on whether they are a member of Group A or not. If I create an access level that includes only Group A and one that includes every other group and someone is in both groups, they will see both links, which is redundant since the pages are different versions of the same page. Any ideas?
We've got a similiar situation, and they way we got around it is to have another Usergroup called "GroupNotA". Then, we have a user plugin that we configure the UserGroups that are in play, and use the OnUserAfterSave event to insure everyone is conditionally in the correct user groups as shown in the code snippets below. With that, we can user menu items, etc. that are available to GroupA and GroupNotA.
myUserPlugin.xml
<field name="usergroup_a" type="usergroup" label="Group A" multiple="false" />
<field name="usergroup_not_a" type="usergroup" label="Group Not A" multiple="false" />
myUserPlugin.php
public function onUserBeforeSave($oldUser, $isnew, $newUser)
{
$UserGroupA = $this->params->get('usergroup_a');
$UserGroupNotA = $this->params->get('usergroup_not_a');
if(in_array(UserGroupA, $newUser['groups'])){
// Use IS in Group A - do nothing?
}else{
// Use is NOT in Group A - Add to group $UserGroupNotA
// add/remove from array $user['groups']
}
A word of caution though, the natural inclination was to use JUserHelper::addUserToGroup(), but it triggers OnUserAfterSave() again, so we went with direct manipulation of the Groups array.
A sample user plugin is installed with Joomla at plugins/user/example.php, and full documentation is available at Plugin/Events/User. Good Luck.
Note I just realized that we do this during a new user registration, so I'm altering the answer to use the event onUserBeforeSave(). I'm not sure that it will work as I originally suggested or not, but at least you have a starting point and the pieces to accomplish a solution.

Setting the HTML Id of an element with laravel

I have to following drop down list
{{ Form::select('selected_site', $select_sites, Input::get('selected_site')) }}
it works fine and I see the name is "selected_site" but how do I set the HTMl Id of the element? I find nothing on this in documentation.
Thanks!
There's one more argument:
{{
Form::select(
'selected_site',
$select_sites,
Input::get('selected_site'),
array('id' => 'yourid')
)
}}
In this last one you can add anything else you need, 'class', 'data-whatever', etc.
There are 2 ways to do this.
You can setup a Label using the Laravel Form builder and use the same name on the control associated with it. As per the documentation at http://laravel.com/docs/html#labels (take a look at the note under this section) After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.
As answered by #antonio-carlos-ribeiro, the 3rd parameter of the control takes a list of options on which you can setup the additional attributes for the control.
Hope this helps...

Drupal Commerce Order object extra data

How might it be possible to get Commerce-Product-Display information in a Commerce-Order object?
The issue is I need to publish a Commerce-Product-Display node when a user has made a payment to publish the node. I am using Rules to detect the payment and attempt to publish the node.
My problem is, because the Completing the checkout process Rules event only has data for a Commerce-Order, and the Commerce-Order does not have information for the Product nor the Product display, I am unable to publish the node.
OK, so here's my new answer based on the new info you provided in your question
=================================
So this is probably a little more complicated than you expected, but not impossible! Two things are important:
the line-items that are attached to your order will contain your products and
you will need to use a rule component, in order to be able to have an additional 'condition-action' combo inside your rule action
Here is how to do it:
In your rule that is triggered upon 'Completing the checkout process', add a loop in your 'Actions' section. You should see 'Add loop' right next to 'Add action'. We'll use this loop to iterate through all the commerce-line-items in your order: that's where the products are hiding
When configuring the loop, tell it to iterate through 'commerce-order:commerce-line-items' and either rename, or remember what it's going to call each line item as it goes through it.
Now - as it's going through each of your order's line items, we'll want to call an entire new rule with its own set of 'condition' and 'action'. The condition we need is to check that the line item contains the product you expect, and the action can be whatever you want - publish a node based on a certain field or whatever. In my case, the action will just be sending an email to prove I found a product. When we need condition-action sets within a rule, we need to create a rule component!!
Go to /admin/config/workflow/rules/components to create a new rule component to run for each of the above items. Click the 'Add new component' link at the top of the page
Select 'Rule' from the drop-down options, since this will be a component that contains both a condition and an action
Name the rule, and in the 'Variables' section, we have to let it know we're going to pass it a parameter to work with. In our case, it will be the commerce line item that is currently being iterated through.
Add two conditions to your component (or whatever checks you think are necessary). I added 'Entity is of type' => Commerce Line item and 'Entity has field' => commerce_product. So this runs for all my products at the moment.
The condition I set on my component is to send an email, and I filled in the following for the body of the email: [line-item:commerce_product], and it prints out the product's name beautifully in the email each time I've tested checking out!
But first - how do I call this component for each of my line item types after I save it?? Read on:
After the component is saved, Add an action to your loop:
From now on, at the very bottom of your actions, you'll see a brand new 'Components' section, and in your case, you should only have one now. Select it to call it for each item:
Last step will be to fill in the parameter to pass to this component, which is obviously the list_item you're currently on, or whatever the computer name of the current item was if you changed it.
Save and test!
Whew! It's a little complicated, but I hope it puts you in the right direction!
The way rules work in Drupal is that not all fields are shown for your entity by default in the actions. What you need to do is prompt Rules to recognize your object as a certain type of node in order for the Rule to add all of its appropriate fields.
You can do this either by
using the 'Content is of type' under the Node section check (and select your Commerce Display node type or
directly using the 'Entity has field' check under the Entities section to check for a specific field you want to use.
Either of those should prompt Rules to recognize the type of entity you're working with and populate the Actions with the necessary fields.
Let us know if this works!

Resources