I was wondering if it was possible to compare two page.locator values.
Ex. Say I have a product number that I store in a variable (ex. const poNumber = page.locator(xpath to element). I want to take this value and compare it with another page.locator value. Would this be possible
You could do it like this with assertions:
const poNumber = await page.locators(`foo`).inputValue();
const val2 = await page.locators(`barbaz`).inputValue();
expect(val2).toEqual(poNumber);
Or:
const poNumber = await page.locators(`foo`).inputValue();expect(await page.locators(`barbaz`).inputValue()).toEqual(poNumber);
Or just take both values and do a string comparision:
if (poNumber === val2) {...}
Related
I have a question.
How to Sorted List<Map<Sting,Object> and change compare value.
List<Map<String, Object>> dataList=new ArrayList<>();
Map<String, Object> someMap= new HashMap<>();
then i want sorted value and change value.
the someMap temp value like this.
someMap.put("totalPoint",1)
someMap.put("regDate",2022-08-01 06:00)
someMap.put("rank",1)
someMap1.put("totalPoint",2)
someMap1.put("regDate",2022-08-02 08:00)
someMap1.put("rank",2)
someMap2.put("totalPoint",2)
someMap2.put("regDate",2022-08-01 06:00)
someMap2.put("rank",3)
someMap3.put("totalPoint",4)
someMap3.put("regDate",2022-08-01 10:00)
someMap3.put("rank",4)
some logic dataList.add(someMap);
dataList.add(someMap1);
dataList.add(someMap2);
dataList.add(someMap3);
first i'd sotred totalPoint and change rank value
AtomicInteger ai=new AtomicInteger();
List<Map<String, Object>> collect = dataList.stream()
.sorted(Comparator.comparing(o -> String.valueOf(o.get("totalPoint")))).collect(Collectors.toList())
.stream().map(x -> {
x.put("rank", map.size() - ai.getAndIncrement());
return x;
}).collect(Collectors.toList());
That map sort totalpoint and replace rank to map.size() - ai.getAndIncrement()
But I want this result
I need compare date and total point from map
someMap.put("totalPoint",1)
someMap.put("regDate",2022-08-01 06:00)
someMap.put("rank",4)
someMap1.put("totalPoint",2)
someMap1.put("regDate",2022-08-02 08:00)
someMap1.put("rank",3) //compare this
someMap2.put("totalPoint",2)
someMap2.put("regDate",2022-08-01 06:00)
someMap2.put("rank",2)//compare this
someMap3.put("totalPoint",4)
someMap3.put("regDate",2022-08-01 10:00)
someMap3.put("rank",1)
how to use compare this map?
I'm looking for a simplest way to sort list based on given value instead of using two list.
Example I have list [a,b,c,d], with a given value d,I can sort it like this:
But if I have an object list, how can I sort it based on given value?
Example
List<ABC> list = [{fid:1,name:"a"},{fid:2,name:"b"},{fid:3,name:"c"},{fid:4,name:"d"}]
I have value 3. I want to sort the list become
List<ABC> list = [{fid:3,name:"c"},{fid:1,name:"A"},{fid:2,name:"b"},{fid:4,name:"d"},{fid:4,name:"d"}]
You just need to perform custom sorting here, rest of the things will remain same.
List list = [{"fid":1,"name":"z"},{"fid":10,"name":"b"},{"fid":5,"name":"c"},{"fid":4,"name":"d"}];
list.sort((a,b)=> a["fid"].compareTo(b["fid"]));
int fidIndex=4;
int indexToRemove=list.indexWhere((element) => element["fid"]==fidIndex);
Map<String,dynamic> removedItem= list.removeAt(indexToRemove);
list.insert(0,removedItem);
print(list);
You can sort list using comparator:
const list = [{fid:1,name:"a"},{fid:2,name:"b"},{fid:3,name:"c"},{fid:4,name:"d"}]
const fixedFid = 3
const sortedList = list.sort( (item1, item2) => {
if (item1.fid === fixedFid){
return -1
}
if (item2.fid == fixedFid){
return 1
}
return item1.fid.localeCompare(item2.fid)
})
I'm new to scala and trying to concatenate two varying size list based on condition,
Below are the lists,
val check1:String = "NULL||BLANK||LENGTH"
val check2:String = "LENGTH||DUPLICATE"
val check3:String = "NUMERIC"
val checkLists = List(check1,check2,check3)
checkLists: List[String] = List(NULL||BLANK||LENGTH, LENGTH||DUPLICATE, NUMERIC)
val condList = List(">=2","<7")
I'm trying to concatenate checkLists & condList based on condition and create new list, whenever List contains String "LENGTH" it should concatenated with condList like below
List(NULL||BLANK||LENGTH~>=2, LENGTH~<7||DUPLICATE, NUMERIC)
I can able to use zip, foreach and case to concatenate of two equal size lists but here I'm facing trouble with different size lists.
Using zipAll will give the answer you are looking for:
checkLists.zipAll(condList, "", "").map {
case (check, cond) => check.replaceAll("LENGTH", "LENGTH~" + cond)
}
List(NULL||BLANK||LENGTH~>=2, LENGTH~<7||DUPLICATE, NUMERIC)
The missing element of condList is given as "", but a different default condition could be used if required.
Note that if the second LENGTH string is in the third element of checkLists rather than the second element, it will not get any condition. This may or may not be what is required.
I have 2 immutable case classes A(source, key, value) and B(source, key, value)
I want to add A over B in such a way when 'source' and 'key' doesn't exist, to be added from A to the B and when 'source' and 'key' exist to replace the value from B with the one from A. The same way 'merge_array' function from php works on a multidimensional array.
I tried with 'A.union(B).groupBy(.key)' and then 'groupBy(.source)' and get the 1st value. But then I realized that I can never be sure that first value will always be the value of A.
I'm quite new to scala and I really ran out of ideas how I could do this from a functional immutable point of view.
Anyone has any idea how I could do this?
Thank you
Edit:
case class TranslationValue(source: String, key: String, value: String)
def main(args:Array[String]):Unit = {
println(merge(data1.toSet, data2.toSet))
}
def merge(a: Set[TranslationValue], b: Set[TranslationValue]) = {
a.union(b).groupBy(_.key).flatMap{ case (s, v) =>
v.groupBy(_.source).flatMap{case (s1, v1) => {
for (res <- 0 to 0) yield v1.head
}
}
}
}
Example
data1 has this data
Set(
TranslationValue(messages,No,No),
TranslationValue(messages,OrdRef,Order Reference),
TranslationValue(messages,OrdId,Order Id)
)
data2 has this data
Set(
TranslationValue(messages,No,No),
TranslationValue(messages,OrdRef,OrderRef)
TranslationValue(messages,Name,Name)
)
putting data1 over data2 I want to obtain
List(
TranslationValue(messages,No,No),
TranslationValue(messages,OrdRef,Order Reference),
TranslationValue(messages,OrdId,Order Id)
TranslationValue(messages,Name,Name)
)
I know that what I do can be done better, but like I said, I'm learning :)
you can group in one go:
def merge(a: Seq[TranslationValue], b: Seq[TranslationValue]) = {
a.union(b).groupBy(t=>(t.key,t.source)).map(c=>c._2.head)
}
i think you could also override the equals method for TranslationValue so that two translation values are equal when source and key are the same(the hashcode method has also to be overridden). Then a.union(b) would be enough.
edit:
It seems Set doesnt guarantee order of items(Scala: Can I rely on the order of items in a Set?), but a seq should.
I have converted grid1 and grid2 into arrays and using following function which iterates through table and should return corresponding value form table when grid1 and grid2 values are matched. But somehow the final output contain only 4 integer values which isn't correct. Any suggestion what is possibly wrong here?
def grid(grid1,grid2):
table = {(10,1):61,(10,2):75,(10,3):83,(10,4):87,
(11,1):54,(11,2):70,(11,3):80,(11,4):85,
(12,1):61,(12,2):75,(12,3):83,(12,4):87,
(13,1):77,(13,2):85,(13,3):90,(13,4):92,}
grid3 = np.zeros(grid1.shape, dtype = np.int)
for k,v in table.iteritems():
grid3[[grid1 == k[0]] and [grid2 == k[1]]] = v
return grid3
I think what's happening is that the assignment to the variables "k" and "v" not done using "deepcopy". This means the assignment is just to the variables and not their values. For example, when the value of "k" changes on subsequent iterations, all previous "gridx" assignments now reflect the new/current status of "k".