-1

Please find below code. I am facing the problem at Line: dataTransformationsPanel.applyModelListFirstElement();

but it works fine if I do it in public static void main(String args[]) method itself. Please suggest me.

package test.dataPage;

import helper.DataTransformationsPanel;
import helper.Driver;
import helper.First;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.testng.Assert;

import pageObjects.DataPage;

public class ApplyModel extends Driver {

    First first;
    DataTransformationsPanel dataTransformationsPanel;
    DataPage dataPage;

    String columnNameExpected;

    public ApplyModel() {
        super();
        columnNameExpected = "New Predicted Column";
        first = new First();
        dataTransformationsPanel = new DataTransformationsPanel();
        dataPage = new DataPage();
    }

    @Test
    public void applyModel() {
        first.login();
        first.openDataPage();
        dataTransformationsPanel.applyModelListFirstElement();
        dataTransformationsPanel.applyModelNewColumnName(columnNameExpected);
        dataTransformationsPanel.applyModelOkButton();

        /*
         * try { Thread.sleep(5000); }
         * 
         * catch (InterruptedException e) { e.printStackTrace(); }
         */
        webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        String columnNameActual = dataPage.lastColumnInTable();
        Assert.assertEquals(columnNameActual, columnNameExpected);

        first.removeDataSet();
        first.logOut();
    }
}

Thanks in advance!

user2118784
  • 442
  • 1
  • 6
  • 18
  • Please attach stacktrace, and `main` function code in which it is working properly. – baju Jan 29 '15 at 13:01
  • Where does the NPE happen? – Konstantin Yovkov Jan 29 '15 at 13:01
  • Have you tried debugging ? My guess is that your DataTransformationsPanel is null. Anyway, your solution should not just be to fix this, but to separate the test from the business logic. – blagae Jan 29 '15 at 13:07
  • Please provide your code for `applyModelListFirstElement()`. – Vivek Singh Jan 29 '15 at 13:10
  • `webDriver.findElement(By.linkText("DATA")).click(); webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); webDriver.findElement(By.id("btn-apply-model")).click(); webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);` – user2118784 Jan 29 '15 at 13:20
  • 1
    There might be possibilities that the webDriver is not initialised in DataTransformationsPanel. is it able to click DATA? And another thing, implicitlyWait you need to declare once for the driver. Declaring it multiple times wont make it to wait for 10 more seconds. – Vivek Singh Jan 30 '15 at 09:15

1 Answers1

0

So, you want to have a Test class.

Try to use a @Before method instead of constructor.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • I have used the below code but still I am facing problem. `@Before public void setUp() { columnNameExpected = "New Predicted Column"; first = new First(); dataTransformationsPanel = new DataTransformationsPanel(); dataPage = new DataPage(); first.login(); first.openDataPage(); }` – user2118784 Jan 30 '15 at 06:15