I have a strange behavior : I created Test Class with 2 Test Methods as below.
When I call AddLimitedBuyOrderwithRandom in the first method it works fine without any exception, but if I call AddLimitedBuyOrderwithRandom from the second method I get a NoSuchElement exception.
This is the code for the test class:
public class TestLoginPage extends TestBase {
public HomePage homeobject;
public NewOrdersLoginPage OrderLoginObject;
public OrderMgmtPage OrdersMgmentObject;
@Test
public void SuccessLogin() throws InterruptedException
{
homeobject = new HomePage(driver);
homeobject.OpenOrdersPage();
OrderLoginObject = new NewOrdersLoginPage(driver);
OrderLoginObject.userLogin(“140”, “12345”);
OrdersMgmentObject = new OrderMgmtPage(driver);
OrdersMgmentObject.AddLimitedBuyOrderwithRandom(“10”);
}
@Test(enabled= true)
public void AddLimitOrderTest() throws InterruptedException
{
OrdersMgmentObject = new OrderMgmtPage(driver);
OrdersMgmentObject.AddLimitedBuyOrderwithRandom(“10”);
}
}
and this is the code for AddLimitedBuyOrderwithRandom:
public void AddLimitedBuyOrderwithRandom(String SharesCount) throws InterruptedException
{
clickButton(NewOrderLink);
clickButton(BuyTypeRadio);
selectDropdownByValue( companyList, “Company”);
typeText(ShareNoTxt, SharesCount);
selectDropdownByValue( OrderTypeList, “2”);
selectDropdownByValue( OrderValidityList, “0”);
double Pricerandom = getRandomNumberInRange(ReturnShareLimitDown(),ReturnShareLimitUp());
typeText(SharePriceTxt,Double.toString(Pricerandom));
clickButton(SubmitOrderBtn);
}
(Added from comments on answers)
My base class is:
public class TestBase
{
public static WebDriver driver ;
public static String downloadPath = System.getProperty(“user.dir”) + “\Downloads”;
public String BaseURL = “URL”;
@BeforeSuite
@Parameters({“browser”})
public void startDriver(@Optional (“chrome”) String browserType)
{
if (browserType.equalsIgnoreCase(“chrome”) )
{
System.setProperty(“webdriver.chrome.driver”, System.getProperty(“user.dir”)+”/drivers/chromedriver.exe”);
driver = new ChromeDriver();
}
}
driver.manage().window().maximize();
driver.navigate().to(BaseURL);
}