How to use Wingethandle in Robot framework - robotframework

I try to use this in Robot framework
#{Title} = Win get handle("[ACTIVE]")
But It seem doesn't work.I need some Example for this command.
Please Help
Sorry for my poor Grammar
**ERROR**
Cannot set variable '#{Title}': Expected list-like value, got string.

When running keywords, you don't use parentheses after the keyword to submit parameters. Instead use:
${Title}= Win Get Handle [ACTIVE]
The [ACTIVE] parameter is automatically submitted as a string.
Also, notice that I changed #{Title} into ${Title}. That is because # denotes a list variable that expects a list return from the keyword. Apparently the Win get handle returns a String variable, which shall be assigned to a scalar $-denoted variable.
Lastly, I'm not sure if you're using Win Get Handle correctly. To my understanding the implementation for that keyword would return a handle to a window (a unique identifier to run further actions against it) rather than its title.

Related

In gatling, how do I validate the value of a string extracted via the css check?

I'm writing a Gatling simulation, and I want to verify both that a certain element exists, and that the content of one of its attributes starts with a certain substring. E.g.:
val scn: ScenarioBuilder = scenario("BasicSimulation")
.exec(http("request_1")
.get("/path/to/resource")
.check(
status.is(200),
css("form#name", "action").ofType[String].startsWith(BASE_URL).saveAs("next_url")))
Now, when I add the startsWith above, the compiler reports an error that says startsWith is not a member of io.gatling.http.check.body.HttpBodyCssCheckBuilder[String]. If I leave the startsWith out, then everything works just fine. I know that the expected form element is there, but I cant confirm that its #action attribute starts with the correct base.
How can I confirm that the attribute start with a certain substring?
Refer this https://gatling.io/docs/2.3/general/scenario/
I have copied the below from there but it is a session function and will work like below :-
doIf(session => session("myKey").as[String].startsWith("admin")) { // executed if the session value stored in "myKey" starts with "admin" exec(http("if true").get("..."))}
I just had the same problem. I guess one option is to use a validator, but I'm not sure how if you can declare one on the fly to validate against your BASE_URL (the documentation doesn't really give any examples). You can use transform and is.
Could look like this:
css("form#name", "action").transform(_.startsWith(BASE_URL)).is(true)
If you also want to include the saveAs call in one go you could probably also do something like this:
css("form#name", "action").transform(_.substring(0, BASE_URL.length)).is(BASE_URL).saveAs
But that's harder to read. Also I'm not sure what happens when substring throws an exception (like IndexOutOfBounds).

How to pass multiple server values to the web method when using AJAX Toolkit CascadingDropDowns

I need to pass in multiple server values to the web method.
If I pass through a single value in the ContextKey, like this:
ContextKey='<%# this.someValue.ToString()%>'”
I get the value, no problem.
But as soon as I try passing multiple variables, like this:
ContextKey='someKey1:<%# this.someValue1.ToString()%>;someKey2:<%#this.someValue2.ToString()%>'
I end up getting the literal string.
I used this post to get the syntax on how to pass multiple parameters:
http://selftaughtprogrammer.com/2012/11/01/how-to-pass-extra-parameters-when-using-ajax-toolkit-cascadingdropdowns-with-a-database/
Attribute values in ASP.NET markup can be either literals, or server-binded snippet, you cannot mix them in arbitrary order. However this is not a big deal, since server-binded snippet gives you everything need to form the necessary value. Say via string.Format:
ContextKey='<%# string.Format("someKey1:{0};someKey2:{1}", this.someValue1, this.someValue2) %>'

spring form error tag: check for specific error (only display invalid if the not null is not present for example)

So I have a String I need to check for a valid format for which I used a pattern, and whether the entered value is valid according to some business rules for which I used a custom validator. Now the customer would prefer it if the error message associated with the latter is only shown if the former didn't occur. But as far as I know there is no way to make this distinction.
Or can anyone think of a way to do this?
The trick is: have two different constraints (annotations),
one for the pattern, that accept null,
and a second for not null.
By default the javax.validation.constraints.Pattern "validator" accept null.
Accepts String. null elements are considered valid.
(javax.validation.constraints.Pattern javadoc)
So what you need to do in the end is this:
#NotNull(message="{validation.notNull}")
#Pattern(pattern="123" message="{validation.notPattern}")
String myString;
Added:
(Comment)
Not really the desired behaviour since I want to reuse the bean object but the conditions aren't the same for each page. – Jack Nickels 5 mins ago
In this case you can use the so called groups (See JSR303 Bean Validation Spec, Chapter 4.1.2 groups -- there is also an example). Use the default Group for #Pattern and an other group for #NotNull. Now you can enable or disable the Validation rules according the groups you specify for validation.
validator.validate(myObject, Default.class);
validator.validate(myObject, MyGroup.class);
There is one problem left: in Spring 3.0 you can not Specify the Group you want to use for the automatic validation process. But in 3.1 you can, according to that Feature Request SPR-6373 (I have not tryed it, but I hope it works)

return domain objects from grails constraint validation

Is it possible to write your own validator in grails that will return a valid object?
Something like:
static constraints = {
name(validator: {val, obj ->
if (Drink.findByName(val)) return [Drink.findByName(val)]
})
}
In other words - if the Drink already exists in the DB, just return the existing one when someone does a
new Drink("Coke")
and coke is already in the database
You cannot do this with a custom validator. It's not really what it was meant for. From the Grails Reference:
The closure can return:
null or true to indicate that the value is valid
false to indicate an invalid value and use the default message code
a string to indicate the error code to append to the "classname.propertName." string used to resolve the error message. If a field specific message cannot be resolved, the error code itself will be resolved allowing for global error messages.
a list containing a string as above, and then any number of arguments following it, which can be used as formatted message arguments indexed at 3 onwards. See grails-app/i18n/message.properties to see how the default error message codes use the arguments.
An alternative might be to just create a service method that 1) looks for the domain and returns it if it exists, 2) otherwise, saves the domain and returns it.
There's probably a more elegant alternative. Regardless, Grails' constraints mechanism isn't (and shouldn't be) capable of this.
Not sure if you can do this from inside the validator, but:
Drink d = Drink.findOrSaveWhere(name: 'Smooth Drink', alcoholLevel: '4.5')

Test if the user typed email format ASP.NET (VB)

I have a TextBox, and I want to force the user to type an email format in this field like (example#mail.com) ?
I don't want to use FilteredTextBoxExtender or the RegularExpressionValidator.
I want to do it manualy.
Use the MailAddress class of System.Net.Mail. If what you pass into it is not a valid email address it will fail.
Example:
How do I validate email address formatting with the .NET Framework?
You are really going to reinvent the wheel.
But if it is your wish, you have to use string manipulation functions built in to the String object.
First do a check whether there is a in # symbol in the text.
Use String.Contains to check that.
Or you can use String.IndexOf to check whether the # symbol is present, and if present which index is it present. (considering the string as an array of characters)
And then check whether there are any (and how many) characters present before the # symbol.
If the symbol # symbol was in the 4th index, then you know there are 3 characters before etc.
There's plethora of functions for the String object. You may have to use Length function and String.SubString to retrieve parts of the string.
Get the indexes of the # symbol and the . symbol and check whether there are at least 3 characters in between.
I really cant seem to think of all the possibilities but first list down all the possibilities and check them one by one.
You can also use the Contains method to check whether illegal characters are present :)
EDIT: String.LastIndexOf will return the last index where a specified character was found ;)
And you count and check whether the # symbol was found more than once etc
String.IndexOfAny(Char[])
String.IndexOfAny Method (Char[], Int32)
String.IndexOfAny Method (Char[], Int32, Int32)
This is the best way I found on internet.
Regex.IsMatch(YourStringEmail, "^(?("")("".+?""#)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])#))" + _
"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$")
Thank you.

Resources