0

Below is my testscript, have called other class methods to it. I would like to divide the testcases to different tests. Now running all in one that would increase my count again more.

    @Listeners(EmailReport.class)
public class CMLoginTest extends BaseTest{
    WebDriver driver;
    Properties prop = new Properties();
    OutputStream output = null;
    InputStream input = null;


    @BeforeTest
    public void init(ITestContext context) {
        webSite = (System.getProperty("webSite") != null ? System.getProperty("webSite")
                : context.getCurrentXmlTest().getParameter("webSite")).toLowerCase();

        env = (System.getProperty("env") != null ? System.getProperty("env")
                : context.getCurrentXmlTest().getParameter("env")).toLowerCase();

        browserName = (System.getProperty("browserName") != null ? System.getProperty("browserName")
                : context.getCurrentXmlTest().getParameter("browserName")).toLowerCase();
        globalVariables.browserUsedForExecution = browserName;
        globalVariables.QA_envValue = env;

        try {

            input = new FileInputStream("./src/main/resources/config.properties");
            prop.load(input);
        }catch(Exception e){
             e.printStackTrace();
        }
    }

@Test(dataProviderClass = DataProviderUtils.class, dataProvider = "parallelTestDataProvider")
public void CMLogin(String browser) throws Exception{
    globalVariables.casename = "Case Manager Login Regression Test";
    final WebDriver driver = WebDriverFactory.get(browser);

        try {
            CMLogin cmlogin= new CMLogin(driver,webSite);
            cmlogin.aLogin("Aty1", "June@1981");

            AddCorp addcorp= new AddCorp(driver);
            addcorp.CreateCorp();

            AddClient addnewclient= new AddClient(driver);
            addnewclient.CreateClient();

            AddNewCase addnewcasedata= new AddNewCase(driver);
            addnewcasedata.CreateCaseData();
            addnewcasedata.ManagersContacts();
            addnewcasedata.AddRemoveSigningCMs();
            addnewcasedata.AddRemoveReminnderCMs();
            addnewcasedata.ProcessModulepage();
0

I am assuming that a new driver is kicked off every time you pass the driver instance to a PageObject class (like addcorp, addnewclient, and addnewcasedata). Make sure you are not creating a new driver as that will open a new browser window, and make sure you are just going to the url of the page you wish to test in those PageObject classes.

Another possibility is that you have a SetUp or teardown method that opens or closes the window after the test has run. I don't see anything like that in the code you provide. It would definitely help if you added an example of one of the PageObject classes so we can see what you are doing with the driver.

To break up those test cases I would instantiate the driver in the init method and do something like this: (fyi I haven't validated this will compile but this is the general direction I'd go)

@Listeners(EmailReport.class)
public class CMLoginTest extends BaseTest
{
    WebDriver driver;
    Properties prop = new Properties();
    OutputStream output = null;
    InputStream input = null;
    private static boolean setUpIsDone = false; //added

    //this will precede all tests and only run once. 
    //It uses boolean value to check if it has been run.
    //If any of the setup steps below need to be run before each test individually, 
    //I would create a new @beforeTest method and include them there
    //Also, usually test methods should not take any parameters.
    @BeforeTest
    public void setUp(ITestContext context, String browser) {
        if (setUpIsDone) {
            return;
        }
        // do the setup
        webSite = (System.getProperty("webSite") != null ? System.getProperty("webSite")
                : context.getCurrentXmlTest().getParameter("webSite")).toLowerCase();

        env = (System.getProperty("env") != null ? System.getProperty("env")
                : context.getCurrentXmlTest().getParameter("env")).toLowerCase();

        browserName = (System.getProperty("browserName") != null ? System.getProperty("browserName")
                : context.getCurrentXmlTest().getParameter("browserName")).toLowerCase();

        globalVariables.browserUsedForExecution = browserName;
        globalVariables.QA_envValue = env;

        //setup the browser once and make it accessible to all test
        driver = WebDriverFactory.get(browser);

        try 
        {
            input = new FileInputStream("./src/main/resources/config.properties");
            prop.load(input);
        }
        catch(Exception e)
        {
             e.printStackTrace();
        }
        setUpIsDone = true;
    }
    @Test(//ADD ATTRIBUTE DETAILS)
    public void AddCorp() throws Exception
    {
        AddCorp addcorp= new AddCorp(driver);
        addcorp.CreateCorp();
    }
    @Test(//ADD ATTRIBUTE DETAILS)
    public void AddAClient() throws Exception
    {
        AddClient addnewclient= new AddClient(driver);
        addnewclient.CreateClient();
    }
    @Test(//ADD ATTRIBUTE DETAILS)
    public void AddNewCaseData() throws Exception
    {
        AddNewCase addnewcasedata= new AddNewCase(driver);
        addnewcasedata.CreateCaseData();
        addnewcasedata.ManagersContacts();
        addnewcasedata.AddRemoveSigningCMs();
        addnewcasedata.AddRemoveReminnderCMs();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.