prashant-ramcharan / courgette-jvm

Multiprocess | Parallel Cucumber-JVM | Parallelize your Java Cucumber tests on a feature level or on a scenario level.
MIT License
131 stars 38 forks source link

Question : For Appium test running on connected devices in parallel without giving device name in feature file scenario #299

Closed LearningPur closed 2 years ago

LearningPur commented 2 years ago

Hi @prashant-ramcharan Both iOS and Android you provided example runs on both devices as expected, thanks for that.

I remember when i used this library for web automation it was not required to give browser name in scenario however running the scenario on Device it does require to give device name, in below feature file scenario you can see in order to trigger scenario on device we require to give device name.

Is it possible to run all scenarios given in feature file on all connected devices (Example 3 Android devices) in parallel without giving device name in scenario ? Example in below scenario how about if we replace Given I have a Pixel_5 device, Given I have a Nexus_S device with Given I have apps lunched on mobile device. Reason I am asking is because what if we have 300 test cases we want those all to run in all connected devices for that we need to give device name in every scenario and if we forget to give device name in some scenario then all time those scenarios will be excluded

Example

@android Feature: Test android application

Scenario: Verify application list dialog on Emulator Given I have a Pixel_5 device When I open app menu And I open Alert Dialogs menu And I open List dialog menu Then I verify Command one is shown

Scenario: Verify application single choice list on Nexus_S Given I have a Nexus_S device When I open app menu And I open Alert Dialogs menu And I open Single choice list menu Then I verify Traffic is shown

Thanks

prashant-ramcharan commented 2 years ago

Hi, this question is more related to your framework design choices and not Courgette but will provide some advice..

In short: No, you cannot run 1 test across 3 devices at the same time using a single JVM process.

You have to run 1 test 3 times (passing a different device name each time) as opposed to 1 test across 3 devices as this cannot be done using a single process.

You best option is to run the tests in parallel using 3 separate process:

gradle runTests -DdeviceName=device1
gradle runTests -DdeviceName=device2
gradle runTests -DdeviceName=device3
vinitsan83 commented 2 years ago

@prashant-ramcharan I don't want 1 test case to run on all 3 devices.

Example :

prashant-ramcharan commented 2 years ago

Yes, you will have to design this in your test framework. Courgette will not be able to do this for you.

Perhaps consider using a cloud provider to manage device allocation for your parallel runs.

vinitsan83 commented 2 years ago

But is it possible to run scenarios in parallel without giving device name in scenario step ? Like an example using this library for Web Automation we were not required to give browser name in scenario step.

All the scenarios in feature file running thru runner class used to run in parallel without giving browser name in scenario step

vinitsan83 commented 2 years ago

I am really sorry to bother you @prashant-ramcharan but since i used your library in my Web Automation and everybody appreciated, want to use same for our new Android and iOS native apps.

prashant-ramcharan commented 2 years ago

With web automation you can have multiple instances of the same browser unlike mobile automation where you can only have a unique device (determined by uuid) run 1 test at a time.

You don't explicitly need to specify the device name in the step definition but you still need a way to pass this data to your tests (usually by passing system properties)

You cannot run more than 1 test on a single device at any one time so your tests need to know which device (uuid or device name) to run on. You have to design your test framework to be able to determine which devices are available and unfortunately Courgette cannot help with this.

Using a cloud provider usually helps with this.

LearningPur commented 2 years ago

Thanks @prashant-ramcharan so based on your comment you think it will be very similar setup for running appium test on cloud (browserstack) like how we have for Web Automation ?

You don't explicitly need to specify the device name in the step definition but you still need a way to pass this data to your tests (usually by passing system properties) : Thanks for this hint

You cannot run more than 1 test on a single device at any one time so your tests need to know which device (uuid or device name) to run on. You have to design your test framework to be able to determine which devices are available and unfortunately Courgette cannot help with this. : Make sense, thanks for this advice.

LearningPur commented 2 years ago

Hi @prashant-ramcharan We have created framework utilizing courgette-jvm library and everything works as expected but we were told instead of passing device name in scenarios find a solution to pass it other way.

you mentioned this in your above comment

You don't explicitly need to specify the device name in the step definition but you still need a way to pass this data to your tests (usually by passing system properties) : Can you please give us a solution how we can read system properties (devices.properties) which will carry multiple devices in parallel during runtime in separate thread.

Thanks Much

prashant-ramcharan commented 2 years ago

Hi, this is more of framework design question and not related to Courgette.

Some advice: It's not just only about reading a system property at runtime, you need a service or process that would notify your test if a device is free a not. Just reading a property at runtime does not mean the device is free and can be used.

This is a framework design decision that you would need to explore further.

mateiQA commented 2 years ago

Hello @prashant-ramcharan, I think an ideal case would be for you to integrate https://github.com/AppiumTestDistribution/AppiumTestDistribution which is a service that handles devices. In this case, people would be able to use the adapted courgette framework with ATD to handle the device allocation I think this would be a great addition to the current state of the mobile part and it would gain a lot of popularity

vinitsan83 commented 2 years ago

I agree with @mateiQA , I heard about ATD but since wasn't sure about courgette library can integrate with ATD didn't try.

I love using courgette library and used it in my last 2 projects 1 for Web Automation and another one for Rest API

This time want to try for Mobile Automation.

@prashant-ramcharan Do you think you can integrate ATD with courgette library so device allocation issue can be resolved ?

I also heard about https://github.com/Testinium/MobileDeviceInfo and tried it with courgette but when it comes to handle parallel execution that's where i am stuck.

Thanks and appreciated @prashant-ramcharan for providing this awesome courgette library that take care of lot of stuff.

prashant-ramcharan commented 2 years ago

Thanks @mateiQA @LearningPur

I will consider creating a new Courgette plugin for mobile device allocation instead of integrating with a 3rd party but will investigate further.

vinitsan83 commented 2 years ago

Damm @prashant-ramcharan you are awesome. Really appreciated for considering it, Thanks a ton. See this is the reason I love using Courgette and will be using it till i am in IT field.

Just because of integrating Courgette in my last project i worked on for Web Automation and what it all comes in package everybody in my team (Director, Manager) appreciated and I was given a promotion as Senior Automation Engineer, They don't know but all credit goes to you my bro @prashant-ramcharan thanks much.

vinitsan83 commented 2 years ago

With you Happy New 2022 Year @prashant-ramcharan , God Bless You, May all your dream come true in this new year 2022 and will pray to GOD that you and your family stay healthy.

prashant-ramcharan commented 2 years ago

This feature is now released in Courgette version 6.2.0

https://github.com/prashant-ramcharan/courgette-jvm#courgette-mobile-device-allocator

vsan6545 commented 2 years ago

You are awesome @prashant-ramcharan thank you so much, appreciated for releasing sooner than later. You are great, thanks a ton. I have no word to describe how much you helped me so far in my carrier.

vsan6545 commented 2 years ago

Hi @prashant-ramcharan I just tried on Android and noticed it keep throwing "Connection refused (Connection refused)" error. I have 3 scenarios in 1 feature file with 2 thread, all 3 scenarios runs on 2 connected devices but constantly throwing "Connection refused (Connection refused)" error

Screen Shot 2022-01-03 at 10 53 19 AM

Here is the full log attached

full log

prashant-ramcharan commented 2 years ago

Looking at the logs the tests did run fine but your AfterScenario(Hooks.java:172) failed.

Try fixing your Cucumber hooks, perhaps remove the terminateApp call as this is what your logs are showing at the issue.

prashant-ramcharan commented 2 years ago

Please refer to the example project: https://github.com/prashant-ramcharan/courgette-jvm-appium-android