WebDriver Instance for mobile web testing

1

I'm working on adapting functional tests of a web to be able to use Device Farm as the device pool for testing in mobile devices. The tests are written in Java, using TestNG and Appium, and i have no problems launching them in desktop browsers locally or in my android phone through a local installation of Appium.
I have adapted the pom.xml following the guidelines in https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html , but i haven't found anything in the documentation stating how i should instantiate WebDriver. I have also reviewed and tested with the method to instantiate it as a RemoteWebDriver using the sdk like this:

String myProjectARN = "arn:evicefarm:us-west-2:XXXXXXXXXX:testgrid-project:XXXXXXXX";
DeviceFarmClient client = DeviceFarmClient.builder()
.region(Region.US_WEST_2)
.build();
CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
.expiresInSeconds(300)
.projectArn(myProjectARN)
.build();
CreateTestGridUrlResponse response = client.createTestGridUrl(request);
URL testGridUrl = new URL(response.url());
WebDriver driver = new RemoteWebDriver(testGridUrl, DesiredCapabilities.chrome());

This works fine for testing in desktop environments, but if i try to adapt it to android environment, i get the following error:

[TestNG] software.amazon.awssdk.services.devicefarm.model.DeviceFarmException: User: arn:aws:sts::XXXXXXXXXXXXX:assumed-role/EC2DeviceHostRole/XXXXXXXXXXXXXXXX is not authorized to perform: devicefarm:CreateTestGridUrl on resource: arn:aws:devicefarm:us-west-2:XXXXXXXXXXXXX:project:XXXXXXXXXXXXXXXXXXXXXXXXX (Service: DeviceFarm, Status Code: 400, Request ID: XXXXXXXXXXXXXXXXXXXXXX, Extended Request ID: null)

How should WebDriver be instantiated for mobile tests? My goal is to run this tests both in Android and iOS devices.

gefragt vor 3 Jahren412 Aufrufe
2 Antworten
1
Akzeptierte Antwort

Hi there,
Thank you for reaching out. Device Farm Mobile Device Testing operates uses a server-side, rather than client-side, execution model. This means that you would instead package your tests according to our instructions here (https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html), then upload them to Device Farm for testing against a pool of devices. In particular, in your test code, you would put code such as the following to indicate that you are using server-side execution during your driver setup method:

[code]
@BeforeSuite
public void setUpDriver() {

    if (System.getenv("DEVICEFARM_DEVICE_NAME") == null) {  
        // This runs against device farm desktop browser devices, client-side  

        String myProjectARN = "arn:evicefarm:us-west-2:XXXXXXXXXX:testgrid-project:XXXXXXXX";  
        DeviceFarmClient client = DeviceFarmClient.builder()  
            .region(Region.US_WEST_2)  
            .build();  
        CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()  
            .expiresInSeconds(300)  
            .projectArn(myProjectARN)  
            .build();  
        CreateTestGridUrlResponse response = client.createTestGridUrl(request);  
        URL testGridUrl = new URL(response.url());  
        WebDriver driver = new RemoteWebDriver(testGridUrl, DesiredCapabilities.chrome());  
    else {  
        // This runs against device farm mobile devices, server-side  

        driver = new AndroidDriver(  
            new URL("http://127.0.0.1:4723/wd/hub"),  
            new DesiredCapabilities());  
    }  

}  

[/code]

Please give this code and those linked instructions a try and let us know your thoughts.

Thank you

AWS
beantwortet vor 3 Jahren
0

Yes, that's exactly the code i was looking for.

Thanks a lot!

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen