java - Selenium Webdriver Loop -
i have array within test case passed string select random item array.
i'm having problem whereby when array called within loop, same value array chosen each time.
here array in question - sits within base class.
private string asapselector = "#main-view > div > section:nth-child(1) > section:nth-child(7) > div:nth-child(2) > radio-button-collection > custom-radio-button:nth-child(1) > label"; private string laterselector = "#main-view > div > section:nth-child(1) > section:nth-child(7) > div:nth-child(2) > radio-button-collection > custom-radio-button:nth-child(2) > label"; string [] dateandtime = {asapselector, laterselector}; //date & time array string randomdateandtime = (dateandtime[new random().nextint(dateandtime.length)]); //select random date & time array
also, method calls 'randomdateandtime' sits within base class , looks like
protected void selectdatetimeradio() { driver.findelement(by.cssselector(randomdateandtime)).click(); //fix if(randomdateandtime.equals(asapselector)) { system.out.println("date & time: asap selected"); } else { system.out.println("i need add more 'later' specific tests here..."); //driver.findelement(by.xpath("//input[contains(@class, 'hasdatepicker')]")).sendkeys("19/08/2017 00:00"); system.out.println("date & time: later selected"); } }
within test case, extend base class, , call method, looks like
public class makebooking extends makebookingbase { @test public void makenewbooking() throws throwable { (string scope: vehicletype) { openenvironment(); selectonbehalfof("tommy"); selectleadpassenger("bobby"); selectnumberofpassengers(); selectjourneytyperadio(); selectdatetimeradio(); //the method im stuck called here! if(!scope.equals("disabled")) { selectvehicletype(scope); } else { selectvehicletype(scope); selectwheelchairtype(); } clickreviewbutton(); } } }
as mentioned above, i'm having problem whereby same value array (scope in instance) being used each loop (vehicletype in instance)
is there way generate new value of array each instance of loop? if possible, can please explain below.
thanks.
i guess randomdateandtime
have class variable , value have been set once class has been initiated , have same value thorough. suggest put variable inside method , return random every time method has been called.
hope helps. thanks.
Comments
Post a Comment