Here is the scenario:
I have:
public class RandomStringUUID {
public RandomStringUUID() {
final String uuidstring = UUID.randomUUID().toString().replaceAll("-", "");
}
public String getRandomStringUUID() {
final String uuidst = UUID.randomUUID().toString().replaceAll("-", "");
return uuidst;
}
}
Where i am generating a Unique Value.
Then in :
public class AddSingleDomain {
public static RandomStringUUID RUUID = new RandomStringUUID();
@Test
public void addSingleDomain() {
AssertJUnit.assertEquals(DomainsPage.getTitle(), "View Account");
String randomUIDSeed = RUUID.getRandomStringUUID();
System.out.println("Random Domanin Name Prefix: "
+ randomUIDSeed);
System.out.println("Random Domanin Name Prefix: " + RUUID);
getDriver().findElement(By.name("vo.zoneName")).sendKeys(
randomUIDSeed + ".tv");
I use it, and then, yet in another class:
public class VerifyDBSingleDomain {
String url = "jdbc:oracle:thin:@a.b.c.d:1521:ms";
@Test
public void VerifyDBSingleDomainTest() {
Properties props = new Properties();
props.setProperty("user", "user");
props.setProperty("password", "pass");
String sql = "Select zoneid from zone where zonename =" + randomUIDSeed + ".tv";
I want to use the SAME VALUE “randomUIDSeed”
If in class VerifyDBSingleDomain i : String randomUIDSeed = RUUID.getRandomStringUUID();
would it be the same object ? How can i use this as same object, and hence guranteeing the same value across ALL classes during runtime.
You could start by making this little change:
You can then use it like this:
This is just a hint into the direction. This is not a “perfect” clean solution. You might want to google “Singleton Design Pattern”. And I can imagine ~10 other ways to do this right now … But anyway.
This will create one of your IDs once for the runtime of your app.