ISSUE1: I have one variable 'name' which will have some runtime value and i am using this value in classes accross packages and also i can't return this value in method because i am already returning boolean value.This variable contains same value, it does not change in each class. expected: it should contain different values for different classes execution and should not override
I tried below:
public static commonClass {
protected static ThreadLocal<String> stringThreadLocal=new ThreadLocal<>();
public static String name=null;
public static boolean getName()
{
//---some code here---
name = driver.findElement(By.id(element)).getText()
stringThreadLocal.set(tempname);
name=getString();
//---- some code here----
return flag;
}
public static String getString(){
return stringThreadLocal.get();
}
}
Test Class in which i need to use it in @beforeclass method:
public class Class1{
String searchName = null;
@BeforeClass(alwaysRun = true)
@Parameters("browser")
public void verifyConnectJourneyBuilderUI(String browser) throws Exception {
flag=commonClass.getName();
assertEquals(flag, true);
System.out.println("created with name:"+ commonClass.name);
searchName= commonClass.getString();
}
}
In every class execution a new name gets generated but sometimes all threads take the same name and i get same value in 'name' as well as 'searchName' variable.
I referred similar issue at (How to store runtime variables in parallel execution selenium java ?) but could not get proper colution. Can someone suggest something?
ISSUE2: Sometimes TC fails because one thread can't find 'name' for a class. I am assuming that if TCs in one class are executed and one thread becomes free then both threads will work on another class and both will have different values, but since I am deleting the element which contains in 'name' in @afterclass that one element is deleted in @afterclass of one class then it won't find it for the next class TCs. Is my understanding correct?