isonic1 / flick

A CLI with helpful QA tools for Android (Devices & Emulators) and iOS (Devices).
MIT License
101 stars 26 forks source link

please post some examples of using it from java code #26

Open VenkateshPS opened 7 years ago

VenkateshPS commented 7 years ago

@isonic1 could you post some examples of using flick from java code or please point me if there is already some.

shapovalovei commented 7 years ago

@VenkateshPS Hi, I try to help you. In my project, I use DefaultExecutor

For example:

 public static int runShell(String command, String arguments) {
        CommandLine commandLine = new CommandLine(command).addArguments(arguments);

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);

        DefaultExecuteResultHandler executeResultHandler = new DefaultExecuteResultHandler();
        DefaultExecutor executor = new DefaultExecutor();
        executor.setStreamHandler(streamHandler);
        executor.setExitValue(0);

        try {
            log.info(String.format("Running: %s %s", command, arguments));
            executor.execute(commandLine, executeResultHandler);
            executeResultHandler.waitFor();

            int exitCode = executeResultHandler.getExitValue();
            String output = outputStream.toString();

            log.info("Command executed. Exit code: " + exitCode);
            log.info("Message: " + output);

            TestGlobalsManager.setTestGlobal("OUTPUT", output);
        } catch (IOException | InterruptedException e) {
            log.error("Cannot execute command: " + e.toString());
        }

        return executeResultHandler.getExitValue();
    }

After that, you can call this function

String arguments = String.format("video -a start -p %s -u %s -e true", Config.PLATFORM_NAME.toLowerCase(), Config.DEVICE_UID);
CommonFunctions.runShell("flick", arguments);
VenkateshPS commented 7 years ago

Thanks @shapovalovei

VenkateshPS commented 7 years ago

@shapovalovei

what is the command to fetch device vitals(memory, cpu)

shapovalovei commented 7 years ago

@VenkateshPS Your question how to get memory and CPU from the device ?

VenkateshPS commented 7 years ago

@shapovalovei yes , will this help $ flick vitals -n com.package.name ?

saikrishna321 commented 7 years ago

@VenkateshPS flick as library helps you capture video from android and iOS device, you cannot get device stats from this library

shapovalovei commented 7 years ago

@VenkateshPS #23

VenkateshPS commented 7 years ago

@shapovalovei @saikrishna321 Thanks , are you aware of some libraries which can get device vitals during Automation runs.

shapovalovei commented 7 years ago

@VenkateshPS I think you can use ADB for Android devices.

for example:

adb shell dumpsys cpuinfo
adb shell dumpsys meminfo 'your apps package name'

and in code just parse values needed. then we just printed them in test logs and just manually looked through them.

isonic1 commented 7 years ago

Hey guys - Flick vitals are android only. So you YOU CAN get memory and cpu info for both the app and device for Android. You CANNOT get this information for iOS. If anyone comes across a tool to capture this for iOS I'd gladly add it to Flick.

@shapovalovei thank you for you assistance in answering @VenkateshPS question.

VenkateshPS commented 7 years ago

I tried using

flick vitals -p android -n com.xxxxx.xxx -u 3208df540c2471a1, but get below error even if app is installed and i am passing the correct package name

com.xxxxx.xxx was not found on device 3208df540c2471a1! Please choose one from above. e.g. package:com.samsung.android.asksmanager

isonic1 commented 7 years ago

Make sure the package name and UUID are correct. Can you see the package listed when running this command adb -s #{udid} shell pm list packages?

flick vitals -p android -n com.myawesomeapp.com

VenkateshPS commented 7 years ago

Thanks @isonic1

pavanbachu0604 commented 6 years ago

@isonic1 : Any luck wth capturing iOS vitals ?

JeevaTamil commented 6 years ago

@shapovalovei Above java code is not working for me. iOS - 11.3 MacOS - 10.13.2

Note: Output of the above code

Command executed. Exit code: -559038737 Message:

But I can do the same via terminal. Please guide me to use flick in my Appium test script(java)