I have two classes that have page objects. How to check if they match inside the method? I tried with contains and Assert.Equals and having hard time to figure out. obj1 = $455.00/year obj2 = $455.00/year.
Class A {
AndroidFindBy(id="sdjl")
private MobileElement obj1;
public boolean example(String text) {
String bodyText = obj1.getText();
return bodyText.contains("$455.00");
}
}
Class B {
AndroidFindBy(id="sjkl")
private MobileElement obj2;
public void exampleb() {
String yearly = obj2.getText();
class A v = new Class A(driver);
Assert.assertEquals(yearly,v.example("$455.00"));
}
}
yearly is a string type object and v.example("$455.00") returns either true or false , a boolean type parameter.
As far as I know, Assert.assertEquals(param1,param2) takes homogeneous parameters . If first one is a string, second one must also be a string .
This is how you can check if a string contains or is equal to another string inside the example
method.
class A {
@AndroidFindBy(id = "android:id/sdjl")
private MobileElement obj1;
public String getObj1Value() {
String bodyText = obj1.getText();
return bodyText;
}
public void example() {
B b = new B();
String obj1Value = getObj1Value();
String obj2Value = b.getObj2Value();
boolean equals = obj1Value.equals(obj2Value);
if (equals) {
// ...
}
boolean contains = obj1Value.contains(obj2Value);
if (contains) {
// ...
}
}
}
class B {
@AndroidFindBy(id = "android:id/sdjl")
private MobileElement obj2;
public String getObj2Value() {
String yearly = obj2.getText();
return yearly;
}
public void example() {
A a = new A();
String obj2Value = getObj2Value();
String obj1Value = a.getObj1Value();
boolean equals = obj2Value.equals(obj1Value);
if (equals) {
// ...
}
boolean contains = obj2Value.contains(obj1Value);
if (contains) {
// ...
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.