vendredi 4 octobre 2019

Loop a try and catch statement in selenium

Im having a issue with the setup of my mobile emulator tests.

Basically i have a list of mobile devices i can use to run my selenium tests on mobile. These a re a pool of devices and can be used by anyone who has paid for the service so its possible on occasion these devices will be in use and this will create a session not created exception.The problem Im having is that im using a try/catch to ensure if one device is unavailable another set of device capabilities can be used. The problem im having is that on occasion both devices are in use and the tests get ignored. This is my current code:

@BeforeClass
public void setup()throws Exception{

    //Setup a mobile device on Kobiton, if this one is not available, the next one will be used

        try {
            this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxyss7());

        } catch (SessionNotCreatedException e) {
            System.out.println("Secondary device being used");
            this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxys7());
        }

}

Ive tied using the following code but the (!done) is not allowed

boolean done = false;
while (!done) {
try {
    ...
    done = true;
} catch (...) {
}
}

Aucun commentaire:

Enregistrer un commentaire