Why does the WebIDE shows an error for Select elements? - syntax-error

I wrote an application in SAPUI5 in WebIDE. When I add Select items to page it shows and error but the program can run without error what is the reason of the error in WebIDE?
Some part of the code:
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic" xmlns:footerbar="sap.ushell.ui.footerbar" controllerName="xxx.controller.Worklist">
<semantic:FullscreenPage id="page" navButtonPress="onNavBack" showNavButton="true" title="{i18n>worklistViewTitle}">
<semantic:content>
.....
</semantic:content>
<semantic:customFooterContent>
// Here it shows error: Semantic Error: SAPUI5: The Association property is incorrect. Please enter the correct value.
<ActionSelect xmlns:sap.ui.core="sap.ui.core" selectedItem="Element sap.ui.core.ListItem#__item1" selectedKey="item1" selectedItemId="__item1" id="__select_lang">
<items>
<sap.ui.core:ListItem text="English" key="EN" id="__item1"/>
<sap.ui.core:ListItem text="German" key="DE" id="__item2"/>
</items>
</ActionSelect>
</semantic:customFooterContent>
</semantic:FullscreenPage>
</mvc:View>
The error message is:
error: Semantic Error: SAPUI5: The Association property is incorrect. Please enter the correct value.
And I tagged in the code where it is shown.

It's the selectedItem association: It does indeed contain an invalid value (which is ignored at runtime).
Associations are set via the id of an element in XMLViews.
You are using three ways to preselect an item at once. Please choose only one.
selectedItem is an association and has to be set to the id of the selected item. this aggregation is seldom used.
selectedKey has to be set to the key of the item that should be selected (EN or DE in your case).
selectedItemId has to be set to the id of the item that should be selected. this property is usually preferred over the selectedItem association.
In your example it should be like so:
<ActionSelect xmlns:sap.ui.core="sap.ui.core" selectedItemId="__item1" id="__select_lang">

Related

Vue: My initial data value is not accessible when used as a function param

I am having an issue when triggering the click handler in my button here. The error comes back as TypeError: Cannot read property 'discountProduct' of null when I click the button. I know for a fact that this.discountProduct.id has a value by inspecting it from the Vue Tools and by knowing that the button is rendering to begin with since it only conditionally shows if the id > 1.
I alternatively tried to remove this but it still throws the same error.
I also tried manually just inserting the product id as the param and that works so I am not sure what the issue is at this point.
<button v-if="this.discountProduct.id >= 1"
type="button"
v-on:click="addToCart(this.discountProduct.id, true)"
Is you button in the <template> tags?
If so, you do not need to use this delete from the click argument and v-if. However that should only throw a warning.
Can you also post the code for the method addToCart?
If you are not setting the full discountProduct object you will need to make sure setting the id is reactive. Like the example below:
this.$set(this.discountProduct, 'id', 1)
Nested Object/keys are not reactive without using $set. See https://v2.vuejs.org/v2/guide/reactivity.html for more details.
Hope this helps

How to make geb throw error when element not found instead of returning EmptyNavigator

in my page object I have simple method
def clickSomething(byName) {
$("a.name", text: contains(byName)).click()
}
and during execution it does not find required element and goes further.
it happens because, according to documentation, $() returns EmptyNavigator if element not found.
I want for test to fail with some kind of "ElementNotFoundException" or "NullPointerException" on trying to make click on null element.
I also do not want to add additional checks for returned element (because I would need to add that for every element identification).
Is there an elegant workaround for that ?
e.g. for elements declared within "content" there is performed such a check. But what is the best practice for elements found outside content block ?
The issue that you've encountered which is click() not throwing an error when called on en empty navigator has been fixed recently and will be released in the next version of Geb.
If you need to get an error when a selector results in an empty navigator then you can either:
wrap your selector in a content definition with the required template option set to true which is the default
call verifyNotEmpty() on your navigator

Validating form data that uses a selector with Selenium

I am attempting to automate checking the values of a form. I figured out how to check the values submitted via send_keys, but anything submitted via a selector is giving me trouble. I'm a n00b when it comes to automation.
This works:
driver.find_element_by_xpath("//*[#name='CurrentAddress.LineOne'][#value='123 Something Lane']")
This does not:
driver.find_element_by_xpath("//*[#name='CurrentAddress.StateAbbrev'][#value='TX']")
The code that governs the CurrentAddress.StateAbbrev is
<select class="form-control" data-val="true" data-val-required="* State is required" id="CurrentAddress_StateAbbrev" name="CurrentAddress.StateAbbrev"><option value=""></option>
When I try to validate the State, I get this:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#name='CurrentAddress.StateAbbrev'][#value='TX']"}
The form value stores the input as 'TX' but the page shows the State as 'TEXAS'. I've tried looking for either, but it still cannot locate the element. Attempting to locate it via either #name or #id doesn't change the outcome.
I haven't tested this code, but it should work.
//Rather than creating the object of WebElement create object of Select
Select stateDropdown = new Select(driver.findElement(By.xpath("//select[#class='form-control']"));
//To select by visible text, pass the text
stateDropdown.selectByVisibleText("");
//Get text of first selected option
String selectedValue = stateDropdown.getFirstSelectedOption().getText();
This ended up working for me:
driver.find_element_by_xpath("//*[#class='form-control']/option[text()='TEXAS']")

behat fillField xpath giving error?

This line of code:
$this->fillField('xpath','//fieldset[#id="address-container"]/input[#name="address_add[0][city]"]', "Toronto");
Is giving me this error
Form field with id|name|label|value|placeholder "xpath" not found. (Behat\Mink\Exception\ElementNotFoundException)
The reason I want to use xpath in my fillField is because there are actually multiple input[#name="address_add[0][city]"] in my html document. I figure an xpath will let me target specifically the field I want to populate.
What's the best way to fill out just the input[#name="address_add[0][city]"] that is a descendant of fieldset[#id="address-container"] ?
You are not using the method in the wright way.
As i see here xpath is taken as selector.
The method expects 2 parameters:
identifier - value of one of attributes 'id|name|label|value'
value - the string you need to set as value
If you want to use css|xpath then you need to use find method first.
For example:
$this->find('xpath', 'your_selector')->setValue('your_string');
Please note that find might return null and using setValue will result in a fatal exception.
You should have something like this:
$field = find('xpath', 'your_selector');
if ($field === null) {
// throw exception
}
$field->setValue('your_string');
Also your selector could be written as:
#address-container input[name*=city] - this with css
or
//fieldset[#id="address-container"]//input[contains(#name, 'city')] - this with xpath
Make sure you take advantage of your IDE editor when you have any doubts using a method and you should find a php doc with what parameters are expected and what the method will return.
If you are using css/xpath a lot you could override find method to detect automatically the type of selector and to use it like $this->find($selector);
Also you could define another method to wait for the element and to handle the exception in one place, for example waitForElement($selector) that could contain a conditional wait up to 10 seconds and that throws exception if not found.

How to find value of email field using Selenium2Library

I am writing regression tests for a web application using robot framework and the Selenium2Library library. I have a simple test which changes all of the fields of an "account settings" type form (think username, password, email, etc.), then revisits the page and makes sure all of the data was saved. Like so:
*** Test Cases ***
Sample Test
Change All Account Details
New Account Details Should Be Saved
*** Keywords ***
Change All Account Details
Navigate to Account Page
Input Text accountSettingFrom_firstname Test
Input Text accountSettingFrom_lastname Dummy
Input Text accountSettingFrom_email new_email#example.com
# etc etc, eventually save the form
New Account Details Should Be Saved
Go To ${ACCOUNT_URL}
Textfield Value Should Be accountSettingFrom_firstname Test
Textfield Value Should Be accountSettingFrom_lastname Dummy
Textfield Value Should Be accountSettingFrom_email new_email#example.com
I get the following error on the final step (Textfield Value Should Be accountSettingFrom_email new_email#example.com) when running this test: Value of text field 'accountSettingFrom_email' should have been 'new_email#example.com' but was 'None'
I have taken screenshots the moment before that step runs, and I have added a pause and manually confirmed that the value attribute of 'accountSettingFrom_email' is indeed 'new_email#example.com'. HTML of the element at time the check occurs:
<input type="email" name="accountSettingFrom[email]" value="new_email#example.com" class="foo bar" required="required" tabindex="3" maxlength="128" url="/foo/bar" userid="foobar" id="accountSettingFrom_email">
You'll notice that the first two Textfield Value Should Be keywords pass. The only difference I can discern between the three elements is that 'accountSettingFrom_email' is type="email" instead of type="text", but if the the keyword is successfully locating the element, then why can't it grab the value of the value attribute?
So am I doing something wrong? I feel like this or some similar keyword must exist to test this, without having to resort to writing a custom library.
You have hit some bugs in Selenium2Library. When Selenium2Library was created, HTML5 was not ratified. Internally the library is filtering out your element because it has a type other than 'text' (made sense before HTML5). Textfield Value Should Be can only find your element if it has tag name input and attribute value 'text' for type.
See https://github.com/robotframework/Selenium2Library/issues/546
Also due to how Textfield Value Should Be is implemented, the error you are getting makes you think the element was found when in fact it was not because it was filtered out.
See https://github.com/robotframework/Selenium2Library/issues/547
In contrast, Input Text and Input Password have never filtered on element tag or attribute.
I would try Get Element Attribute instead to get the attribute named value instead. According to the API it should be
accountSettingFrom_email#value