23.2 C
London
Sunday, September 1, 2024

java – Why IOS app is just not relaunching after every cucumber state of affairs?


I do setup an autoamtion framework for cell with java and appium. And got here throughout a difficulty with the IOS half. The app is just not relaunching after every cucumber state of affairs, even when I initilize the motive force each time in @Earlier than Hook. (identical strategy works for android).

package deal stepdef;

import com.qa.utils.*;
import io.cucumber.java.After;
import io.cucumber.java.Earlier than;
import io.cucumber.java.Situation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import androidPages.BasePage;

public class Hooks extends BasePage {
    protected static closing Logger logger = LogManager.getLogger(Hooks.class);
    DriverManager driverManager = new DriverManager();

    @Earlier than
    public void initialize() throws Exception {
        driverManager.initializeDriver();
    }

    @After
    public void give up(Situation state of affairs) throws InterruptedException {
        DriverManager driverManager = new DriverManager();
        if (state of affairs.isFailed()) {
            byte[] screenshot = ((TakesScreenshot) driverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
            state of affairs.connect(screenshot, "picture/png", "FailedScreenshot");
        }
        driverManager.getDriver().give up();
    }
}

That is the DriverManager calss:


import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.web.URL;
import java.util.Properties;

public class DriverManager {
    personal static closing ThreadLocal<AppiumDriver> driver = new ThreadLocal<>();

    protected closing Logger logger = LogManager.getLogger(this.getClass());


    public AppiumDriver getDriver() {
        return driver.get();
    }

    public void setDriver(AppiumDriver driver2) {
        driver.set(driver2);
    }

    public void initializeDriver() throws Exception {
        AppiumDriver driver = null;
        Properties props = new PropertyManager().getProps();
        URL serverUrl = new URL(props.getProperty("appiumURL"));

        attempt {
            swap (props.getProperty("platformName")) {
                case "android_emulator":
                    driver = new AppiumDriver(serverUrl, new CapabilitiesManager().getCaps());

                case "ios_emulator":
                    driver = new AppiumDriver(serverUrl, new CapabilitiesManager().getCaps());
                    logger.information(">>>>>>The motive force initialized");
            }

            if (driver == null) {
                throw new Exception("driver is null. ABORT!!!");
            }
            this.driver.set(driver);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }

}

Why for android it’s relaunching the app each time, however for IOS the app stays open and proceed from the place it left?
Easy methods to repair that ?

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here