mardi 17 avril 2018

Get access to the same randomized String as in other class

Stupid question about Java basics, but I cannot beat it for days already.

I have a class with initialized data. Randomizer is here.

public class AddContract {
    private Data data = new Data();

    public String bufferCONNUM() {
        return String.valueOf(data.randInt());
    }
    public String bufferPURCHNUM() {
        return String.valueOf(data.randInt());
    }

    class Data {
        final String CONNUM = bufferCONNUM();
        final String PURCHASENUM = bufferPURCHNUM();

        public int randInt() {
            int min = 1;
            int max = 7777;
            return (int) (Math.random() * max + min);
        }
    }

And I have another class:

public class ContractsPage {
public AddContract param;

    public ContractsPage FindContractByContractNumber() {
       param = new AddContract(driver);
       this.contractNumberFilter.clear();
       this.contractNumberFilter.sendKeys(param.bufferCONNUM());
           return this;
    }
}

Pls don't judge how it looks now coz I was trying many variants how to make it work. So, I want get the same instanse of randInt in class ContractsPage as it is in class AddContract. But Object through new generates "new" rng.

tl;dr: With random I get var=5 in Class1, I want to adress the same var=5 in Class2.




Aucun commentaire:

Enregistrer un commentaire