Hi I am seeing this error, please help
Parameter 'Visit' is required by @Test on method searchByVisitNo but has not been marked @Optional or defined.
I don't know why is there a need to mark it optional when it is defined in testng xml file
Here is the entire code I used
<suite name="Suite" parallel="tests">
<test name="SearchByVisit">
<parameter name="Visit" value="123456"/>
<classes>
<class name="abc"/>
</classes>
</test>
</suite>
@Parameters({"Visit"})
@Test(priority=3)
public void searchByVisitNo(String VisitNumber)throws InterruptedException
{
searchByVisit(VisitNumber);
}
public void searchByVisit(String Visit) throws InterruptedException
{
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("search-input"))
);
element.sendKeys(Visit);
clickSearch();
}
When we declare a parameter as optional, TestNG first looks in testng xml if parameter value is provided. If provided, it will use that value otherwise it will assign default value to parameter. It will not throw any exception. We just need to append parameter name with “@Optional” (from org.
So primarily we can achieve parameterization in TestNG in two ways. Using “Parameters annotation” and TestNG XML file. Using “DataProvider annotation”.
Parameters annotation with Testng. xml. Select parameterization using annotations when you do want to deal with complexity & the number of input combinations are less. Suite level – The parameters inside the <suite> tag of TestNG XML file will be a suite level parameter.
You can disable or exclude the test cases by using the enable attribute to the @Test annotation and assign False value to the enable attribute.
You are passing paramter <parameter name="Visit" value="123456"/>
in your .xml file and you directly running your TestNG class. So it's not getting that parameter while compiling .
So you need to run your xml suite to provide a valid parameter to your TestNG class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With