I have some geb content like this
buttonName(wait: true){$("a.btn_primary")}
I need get value from {} i.e. i need string $("a.btn_primary")
For example def value = "$("a.btn_primary")"
If your buttonName is correct, then try this:
def value = buttonName.text()
Cheers!
Try
def value = buttonName.value()
if .text() does not work.
From The Book of Geb,
"The value of input, select and textarea elements can be retrieved and set with the value method. Calling value() with no arguments will return the String value of the first element in the Navigator.
Calling value(value) will set the current value of all elements in the Navigator. The argument can be of any type and will be coerced to a String if necessary. The exceptions are that when setting a checkbox value the method expects a boolean (or, an existing checkbox value) and when setting a multiple select the method expects an array or Collection of values."
Hope it works out!
Related
I noticed that when calling values() or values_list() one a queryset returns the normal value in the field and not the display value I'd like. Is there a way to manupilate the display value of the field while creating a result that is a list of list of the queryset?
class FooBar(models.Model):
...
foo_bar = models.CharField(_("foo"), choices=[(1, 'foo'), (2, 'bar')])
def get_foo_bar_display(self):
return "something"
def get_foobar(user):
foobar = FooBar.objects.filter(user=user).values_list(.., 'foo_bar')
foobar = list(map(list, foobar))
return foobar
It always returns the foo_bar original value and not the display value.
One way out for you is to get the model instances with only some selected fields (needed for the get_x_display to work correctly) using .only() query set method.
Going from there you can call the get_x_display on the model like you'd normally do.
I am iterating over a hashmap that is made of string keys and has objects as values and I am setting the attributes of the objects. The value of my hashmap is an object which has other objects as attributes. The problem is that once I set the value for the first object with key "1-1", in the second iteration when I want to set the value for my second key"2-1", the value corresponding to the first entry which was assigned right before ends up overridden with the value of the second entry, in other words, the attribute value of the first entry ends up overridden with the attribute value corresponding to the second entry. More specifically for key "1-1", in the first iteration of my hashmap, when I print methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold(), I get the value "T", then as soon as I move to the second key with value "2-1", I end up with a different value when I reprint methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold(), namely I end up with "N", while it should be "T" in reality, the "N" I am getting actually coresponds to the value of methodtraceHashMap2.get("2-1").Method.Owner.getDeveloperGold() which was set for the second entry of my hashmap which has the key "2-1"
for(MethodTrace MethodTrace: methodtraceHashMap2.values()) {
String reqClass=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.Owner.ID;
MethodTrace.Method.Owner.DeveloperGold=classTraceHashMap.get(reqClass).DeveloperGold;
System.out.println("yes");
}
System.out.println(methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold());
Here is the snippet that populates the map but the problem arises in the previous snippet when I populate the attribute MethodTrace.Method.Owner.DeveloperGold of the MethodTrace, I do not believe that the problem is linked to the snippet below
ResultSet myresults = st.executeQuery("SELECT traces.* from traces");
while (myresults.next()) {
MethodTrace MethodTrace = new MethodTrace();
Method method= new Method();
Requirement requirement= new Requirement();
requirement=RequirementHashMap.get(myresults.getString("requirementid"));
method = MethodHashMap.get(myresults.getString("methodid"));
MethodTrace.setMethod(method);
MethodTrace.setRequirement(requirement);
//checking whether the method is present in the superclasses
MethodTrace.setGold(myresults.getString("goldfinal"));
String reqMethod=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.ID;
String reqClass=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.Owner.ID;
MethodTrace.Method.Owner.DeveloperGold=classTraceHashMap.get(reqClass).DeveloperGold;
System.out.println(reqMethod+"-");
System.out.println(MethodTrace.Method.Owner.DeveloperGold);
methodtraceHashMap2.putIfAbsent(reqMethod, MethodTrace);
System.out.println("WE ARW IN THE LOOP "+methodtraceHashMap2.get("1-1"));
methodtraceHashMap2.putIfAbsent(reqMethod+"_"+System.currentTimeMillis(), MethodTrace);
System.out.println("WE ARW IN THE LOOP "+methodtraceHashMap2.get("1-1"));
}
I have a piece of code below that checks that every value of regionId (found under region.hotels.regionId) matches its property value regionid_request.
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)
def regionid_request = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue("regionid") as Integer
region.hotels.each { hotel ->
assert hotel.regionId == regionid_request
}
I want the code above to perform slightly differently. Instead of saying each regionid needs to match its property value, I just want any of regionid to match its property value. In other words I want to ensure when I have my response, that at least one of the regionIds matches the property value.
What needs to be changed above to match this condition?
Thank you,
Just
assert region.hotels.regionId.contains(regionid_request)
I want to iterate thru the set of attributes for an entity and for each one, get the text value. I can do this by getting the attribute type and explicit casting but is there a way to do it regardless of type? Similar to this method...
I don't think you'll be able to simply get a text value without testing for and handling the specific field types that are possible on an entity, since some field types have more complex values where you'll need to decide what value you want to get from the field. I ran into this same situation and ended up building a function to do the heavy lifting for me. Basically I did a case statement on the attribute type and got the values I wanted based on the business needs, here's an example of the function I used:
Private Function GetAttributeValue(ByRef pEntity As Entity, ByRef pAttr As KeyValuePair(Of String, Object)) As String
Dim lstrValue As String = String.Empty
Select Case pAttr.Value.GetType
Case GetType(OptionSetValue)
lstrValue = String.Format("{0} - {1}", CType(pAttr.Value, OptionSetValue).Value.ToString(), pEntity.FormattedValues(pAttr.Key))
Case GetType(EntityReference)
lstrValue = CType(pAttr.Value, EntityReference).Id.ToString()
'... could also get the Name value from the EntityReference
Case GetType(Money)
lstrValue = CType(pAttr.Value, Money).Value.ToString()
Case GetType(Date)
lstrValue = CType(pAttr.Value, Date).ToString("MM/dd/yy hh:mm:ss")
Case GetType(Guid)
lstrValue = CType(pAttr.Value, Guid).ToString()
Case Else
'... assume a string and just return the attribute value, or do some other handling
End Select
Return lstrValue
End Function
Once I had this function, I could just iterate through the attributes on the entity I was dealing with and get some text value back that represented the value for each field regardless of the field type. One thing to note, in my example I'm getting the string value of OptionSet fields using .FormattedValues(), I believe you can only use that if your entities have the Id unique identifier field populated.
you can use the method GetFormattedAttributeValue of the Entity class.
Example:
Entity myAccount = service.Retrieve("account", accountId, new ColumnSet(true));
string createdOn = myAccount.GetFormattedAttributeValue("createdon");
I have a webtable which MIGHT have a weblink object in it's Row 2, Column 1 cell (also Index of this object is 0). If it indeed is a link I would like to click it else ignore it. Is there a way to identify the class of this object given that we know the row and column number.
Below was my initial code. However it doesn't work always when the webtable cell doesn't have a link to click
Set Table = Browser("Oracle PeopleSoft").Page("Request Payment Predictor").WebTable("Run Control ID").ChildItem(2, 1, "Link", 0)
Table.Click
I would like to know if there a way to find the class of the Object (in cell of a web table) so I can click on the Object only if it's a link Or in other words can we use GetRoProperty("Class Name") on a WebTable Cell Object?
The ChildItem function returns a test object of the requested type if it exists, otherwise it returns Nothing.
So your code should look like this:
Set aLink = Browser("Oracle PeopleSoft")_
.Page("Request Payment Predictor")_
.WebTable("Run Control ID").ChildItem(2, 1, "Link", 0)
If Not aLink is Nothing Then
aLink.Click
End If
The object returned by ChildItem is a test object (if it's not Nothing) so you can use the regular test object methods on it.
Please note that the object returned is not a table cell object, it's the object of the type you requested, this type may be WebElement which is considered the base class of all web objects. This means that you can use ChildItem with "WebElement" and then see what actual type it is by getting its micClass (which is what the Class Name is called internally).
Print webElem.GetROProperty("micclass")
Pro tip: The indexes are 1 based, you can use the undocumented Highlight function in order to make sure you're working on the right object (obj.Highlight).