prashant-ramcharan / courgette-jvm

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

Get current thread #350

Closed albertolopez55 closed 1 year ago

albertolopez55 commented 1 year ago

Hello How can i get the current thread in which my code is running? Depending on the thread number, i need to do some modifications. my test cases requiere to use different devices and when using a device, it has to be locked out. For example, for thread 1, i need to use device 1 thats why i need to know the thread number in my code. Tks

prashant-ramcharan commented 1 year ago

Hi,

Each test is run in a separate Java process so the thread number will likely be 1.

If you are using Appium, have you tried the Courgette Device Allocator Plugin ?

A possible solution would be to tag your Cucumber tests with the deviceName you want the test to run against but then you would need a separate process to track what devices are locked etc..

albertolopez55 commented 1 year ago

Hi. Tks for your answer. No, i am not using Appium I am testing APIs. The devices are logical devices (not physical). Unfortunately i cannot use tags for the test cases to determine the device because part of the testing is to select random logical devices. Before using courgette, I used "Thread.currentThread().getName()" and it retrieved the number thread. But now, with courgette it always retrieve the value "main" Any other suggestion? Tks in advance

prashant-ramcharan commented 1 year ago

Hi,

The reason why it always shows as main is because the invoked thread is Cucumber (main) so when calling Thread.currentThread() it was alway returns main

I will update Courgette and pass the parent threadId and threadName as a system property so in your test you can retrieve it like:

System.getProperty("courgette.threadId"); // example: 14

System.getProperty("courgette.threadName");  // example: pool-1-thread-1
albertolopez55 commented 1 year ago

Thank you! that will be great!

prashant-ramcharan commented 1 year ago

This is now released in Courgette version 6.6.1

albertolopez55 commented 1 year ago

I have tested the new changes and it is working fine! Thank you for your support This changes has been very helpful. Now i can handle the devices depending on the thread Thank very much!