简体   繁体   中英

Running appium test for android with multiple appPackage using @AndroidFindBy

I am in a process of changing the appPackage of my android apk from com.mycurrentpackage to com.myfuturepackage .

I have all the ids of the elements defined as

com.mycurrentpackage:id/elementID

Currently I find the element as

@AndroidFindBy(id = "com.mycurrentpackage:id/startup_text1")

@CacheLookup

private MobileElement startup_text1;

I want to be able to change it dynamically. So I defined a static variable appPackage.

Here is the part of the constructor

...

appPackage = driver.getCapabilities().getCapability("appPackage").toString();

PageFactory.initElements(new AppiumFieldDecorator(this.driver, 30, TimeUnit.SECONDS), this);

...

As you can see appPackage is already defined before initializing elements.

But when I do it this way

@AndroidFindBy(id = appPackage+":id/startup_text1")

@CacheLookup

private MobileElement startup_text1;

While compiling it says

Error:(42, 35) java: attribute value must be constant

Is there any other way to do it?

Your idea of having package name as variable is correct, but it must be final:

public static final String appPackage = "com.mycurrentpackage";

Now you can use:

@AndroidFindBy(id = appPackage+":id/startup_text1")

Can I also use

@AndroidFindBys({
@AndroidFindBy(id = "com.mycurrentpackage:id/startup_text1"),
@AndroidFindBy(id = "com.futurepackage:id/startup_text1")
})
@CacheLookup
private MobileElement startup_text1

When I used this one it takes a long time to load the page.

Do I need to list it as

private List<MobileElement> startup_text1

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM