Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameter is required by @ Test but has not been marked @optional or defined

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();
}
like image 489
dss Avatar asked Jul 11 '17 03:07

dss


People also ask

What is optional parameter in TestNG?

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.

How do you do parameterization in testing?

So primarily we can achieve parameterization in TestNG in two ways. Using “Parameters annotation” and TestNG XML file. Using “DataProvider annotation”.

What is the type of parameterization is XML parameterization?

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.

How do you exclude a particular test group from a test case execution?

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.


1 Answers

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.

like image 160
Ankur Singh Avatar answered Nov 14 '22 22:11

Ankur Singh