TestProject Forum
Powered by leading experts in the test automation community

Parameterize coded tests

Hello, I have created a simple coded test but all the values are hard coded (such as Fullname, Password in https://example.testproject.io/web/ including the url itself). Is there any way to parameterize the values so that I can select once its imported to my testproject?

Regards
Sisir

After checking the git hub, i got it how to parameterize the test

e.g.
@Parameter(defaultValue = “Sisirkant Prusty”)
public String fullName;

If I do the local testing of the following test case
it does not run as fullName value is null even if the defaultValue is set to Sisirkant Prusty

package main.TestCases;

import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;
import main.Runners.MyFirstTestCasePage;

import static java.lang.Thread.sleep;

/**

  • Created by Sisirkant on 5/2/2020.
    */

@Test(name = “My First Test case”)
public class MyFirstTestCase implements WebTest {

@Parameter(defaultValue = "Sisirkant Prusty")
public String fullName;

@Override
public ExecutionResult execute(WebTestHelper webTestHelper) throws FailureException {
    System.out.println("My Full name: " + fullName);
    WebDriver driver = webTestHelper.getDriver();
    MyFirstTestCasePage myFirstTestCasePage = new MyFirstTestCasePage(driver);
    driver.get("https://example.testproject.io/web/");
    try {
        sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }


    myFirstTestCasePage.enterFullName(fullName);
    myFirstTestCasePage.enterPassword();
    try {
        myFirstTestCasePage.clickLogin();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return ExecutionResult.PASSED;
}

}

But I import the test case to TestProject it works fine. I can override the parameter as well.

Any idea why local test fails?

Hello and thanks for reaching out.

I have tested your code locally and have determined the issue.
The default name property you have set for your name in the code will only overwrite the parameter value when uploading your coded test to the platform, so you will need to set it up with a value when running locally otherwise it will always be NULL and not write anything in the field.

public String fullName = “FirstName LastName”;

Alternatively, please make sure your agent is not currently busy running a recorded test or another java code and that the developer token you have specified for the runner is correct.

Regardless, here is a fully working version of the entire code, including a runner class that needs a developer token inserted and a page object class that will handle interaction with the page, just make sure to give your name String a value when running locally.

Hi, Thanks. I had already tried that and was in impression that I was doing wrong. Now its clear. Thanks for the response!!!

Regards
Sisir