Using Karate, according to Karate - is it possible to find element according to part of its parameter I have tried to do that using:
* def filter = function(x){ return x.attribute('placeholder').startsWith('Very') }
* def list = locateAll('input[placeholder]', filter)
But I have no idea how to use it for inserting the value. I have tried this:
* retry().input(list[0], '12312312311111')
and this:
* retry().input('list[0]', '12312312311111')
but neither worked.
Have you any idea what is wrong in syntax?
Thank you.
Whatever locate returns is an Element object. So you can call methods on it. Please read the documentation: https://github.com/intuit/karate/tree/master/karate-core#locate
So this should work:
* list[0].input('12312312311111')
* list[0].retry().input('12312312311111')
Related
I am using the following to get the transaction timestamp:
val outputStateRef = StateRef(ledgerTx.id, 0)
val queryCriteria = QueryCriteria.VaultQueryCriteria(stateRefs = listOf(outputStateRef))
val results = serviceHub.vaultService.queryBy<ContractState>(queryCriteria)
val recordedTime = results.statesMetadata.singleOrNull()?.recordedTime
The problem is the transaction time is not always returned, sometimes null is returned for the timestamp.
Why is this happening and how can I ensure the timestamp is always returned?
results is Vault.Page<ContractState> which contains the following variables:
/**
* Returned in queries [VaultService.queryBy] and [VaultService.trackBy].
* A Page contains:
* 1) a [List] of actual [StateAndRef] requested by the specified [QueryCriteria] to a maximum of [MAX_PAGE_SIZE].
* 2) a [List] of associated [Vault.StateMetadata], one per [StateAndRef] result.
* 3) a total number of states that met the given [QueryCriteria] if a [PageSpecification] was provided,
* otherwise it defaults to -1.
* 4) Status types used in this query: [StateStatus.UNCONSUMED], [StateStatus.CONSUMED], [StateStatus.ALL].
* 5) Other results as a [List] of any type (eg. aggregate function results with/without group by).
*
* Note: currently otherResults are used only for Aggregate Functions (in which case, the states and statesMetadata
* results will be empty).
*/
As it looks from your code, if result page contains multiple StateAndRef, the method code singleOrNull()? will actually return null.
This is my guess based on available codes, please share more information if this wasnt the cause of the issue.
I would add your own timestamp to the state and record it in the flow.
Or, you can add a Time-Window to the transaction (https://docs.corda.net/api-transactions.html#time-windows). I believe this also ensures that the statesMetadata.recordedTime will not be null.
I am currently stuck on a probably very simple question.
How do I validate my DateIntervalType to be != 0 - meaning atleast something has been selected.
And how do I set a minimum/maximum: for example minimum interval of 1 day.
Background: I want to send an email every X years/months/days depending on the user select - an interval of 0 would mean permanent email sending, which I do not want.
Sadly I did not find anything helpful yet. Also tried integer assertations like #Assert\GratherThan etc. but that does not work.
Thanks in advance
Solution: Thanks to #Arleigh Hix for putting me on the right direction.
I solved my problem with following solution:
/**
* #Assert\Expression("this.checkInterval()")
*/
private $interval;
public function checkInterval() {
return $this->getTimestamp()->add($this->getInterval()) > $this->getTimestamp(); //getTimestamp() returns a DateTime
}
So basically just add the interval to any date and compare the new date to the initial date. With this way you can also get the difference in seconds and compare for min max values.
Better practise is probably to create a custom validator which will be my next step.
It looks you should be able to use an Expression constraint Maybe like this (I'm not sure about syntax for constructing the \DateInterval in the annotation)
/**
* #Assert\Expression(
* "value >= minimum",
* values = { "minimum": new \DateInterval('P1D') }
* )
*/
$dateIntervalField;
Alternatively, you should be able to set your minimum interval to an entity property and then compare value to that.
public function __construct()
{
$this->minInterval = new \DateInterval('P1D');
}
/**
* #Assert\GreaterThanOrEqual(
* value = this.minInterval
* )
*/
$dateIntervalField;
I want to have a computed property that tracks that historical max of another property. Both these attributes are a member of an ndb class.
My naive approach was the following:
number = ndb.IntegerProperty(default=0)
highest_ever_number = ndb.ComputedProperty(lambda self: self.highest_ever_number if self.highest_ever_number >= self.number else self.number)
The intent was to set the highest_ever_number to a new number if number ever surpassed highest_ever_number.
This doesn't work because highest_ever_number is initially unset. I cannot set it to a default value using "default=0". Is there a workaround to this?
Thanks
I don't think you can use such conditions inside a Computed Property. This whole functionality can be done within a function, so it doesn't need to be a ComputedProperty. A better alternative to this problem could be to create a class method and call it whenever necessary.
Instead of using a computed property, you should use a normal IntegerProperty but use a _pre_put hook (https://cloud.google.com/appengine/docs/standard/python/ndb/modelclass#hooks) to verify/update highest_ever_number.
I can't test it right now, but this might do the trick:
number = ndb.IntegerProperty(default=0)
highest_ever_number = ndb.ComputedProperty(lambda self: self.highest_ever_number if
self.highest_ever_number and self.highest_ever_number >= self.number else self.number)
Hei guys! I need help in a python program. I wanna make a method which returns the sum of the keys as a dictionary. But I get a error "object is not iterable".
def totaltAntallSalg (dic) :
s = sum (dic.keys)
return s
call_function = totaltAntallSalg({"Ahmed":2,"Nada":1, "hala":3 })
How can I solve this problem?
thanks in advance
How can you add strings ? It might be values that you want to add.
To add values you may use following code:-
def totaltAntallSalg(dic):
D={}
D['sum']=sum(dic.values())
return D
First time user of fmdb here, trying to start off doing things correctly. I have a simple single table that I wish to perform a SELECT WHERE .. LIKE query on and after trying several of the documented approaches, I can't get any to yield the correct results.
e.g.
// 'filter' is an NSString * containing a fragment of
// text that we want in the 'track' column
NSDictionary *params =
[NSDictionary dictionaryWithObjectsAndKeys:filter, #"filter", nil];
FMResultSet *results =
[db executeQuery:#"SELECT * FROM items WHERE track LIKE '%:filter%' ORDER BY linkNum;"
withParameterDictionary:params];
Or
results = [db executeQuery:#"SELECT * FROM items WHERE track LIKE '%?%' ORDER BY linkNum;", filter];
Or
results = [db executeQuery:#"SELECT * FROM items WHERE track LIKE '%?%' ORDER BY linkNum;" withArgumentsInArray:#[filter]];
I've stepped through and all methods converge in the fmdb method:
- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args
Depending on the approach, and therefore which params are nil, it then either calls sqlite3_bind_parameter_count(pStmt), which always returns zero, or, for the dictionary case, calls sqlite3_bind_parameter_index(..), which also returns zero, so the parameter doesn't get slotted into the LIKE and then the resultSet from the query is wrong.
I know that this is absolutely the wrong way to do it (SQL injection), but it's the only way I've managed to have my LIKE honoured:
NSString *queryString = [NSString stringWithFormat:#"SELECT * FROM items WHERE track LIKE '%%%#%%' ORDER BY linkNum;", filter];
results = [db executeQuery:queryString];
(I've also tried all permutations but with escaped double-quotes in place of the single quotes shown here)
Update:
I've also tried fmdb's own …WithFormat variant, which should provide convenience and protection from injection:
[db executeQueryWithFormat:#"SELECT * FROM items WHERE track LIKE '%%%#%%' ORDER BY linkNum;", filter];
Again, stepping into the debugger I can see that the LIKE gets transformed from this:
… LIKE '%%%#%%' ORDER BY linkNum;
To this:
… LIKE '%%?%' ORDER BY linkNum;
… which also goes on to return zero from sqlite3_bind_parameter_count(), where I would expect a positive value equal to "the index of the largest (rightmost) parameter." (from the sqlite docs)
The error was to include any quotes at all:
[db executeQuery:#"SELECT * FROM items WHERE track LIKE ? ORDER BY linkNum;", filter];
… and the % is now in the filter variable, rather than in the query.