0

I am working in Winium automation using java language. I am following page object design pattern.while executing , my code getting error... In the BaseBallOutEvents class. I want to select a value from the drop down option. In winium select class is not supporting , so i used comboBox for selecting dropdown value. In that class in the method groundouttop1 method i used driver.findElement(By.name(velo)).click();otherwise it should not be able to click. now I am getting instantiation exception... anybody please help me...

package page;

public class BaseBallOutEvents {


    private WiniumDriver driver;
    public BaseBallOutEvents(WiniumDriver driver) {
        this.driver=driver;

        // TODO Auto-generated constructor stub
    }
@FindBy(how=How.ID,using="cmbVelocity")
    WebElement textVelocity;
    @FindBy(how=How.ID,using="DropDown")
    WebElement dropDown;
    public  void groundOuttop1(String field,String dist,String velo,String diff) throws InterruptedException {
        //TSBH


        groundOutButton.click();
        enterFielding.sendKeys(field);
        saveButton.click();
        textDistance.sendKeys(dist);
         dropDown.click();

        ComboBox cmbcc=new ComboBox(textVelocity);
        cmbcc.expand();

        driver.findElement(By.name(velo)).click();

        textDifficulty.sendKeys(diff);
        buttonUpdate.click();
    }

package steps;

public class OutEventsSteps {
WiniumDriver driver;
 public void setGroundOutTop1(String f,String dis,String v,String diff) throws InterruptedException {

    Thread.sleep(5000);
    BaseBallOutEvents baseOut = new BaseBallOutEvents(driver);
    baseOut=  PageFactory.initElements(DriverManager.driver, BaseBallOutEvents.class);
    baseOut.groundOuttop1(field, dist, velo, diff);

 }

main method

public class ReporterApp extends DriverManager{
    public static void main(String[] args) throws MalformedURLException, InterruptedException {


            DriverManager manager=new DriverManager();


             LoginSteps loginSteps = new LoginSteps();
             LineUps line=new LineUps(driver);


             OutEventsSteps outsteps=new OutEventsSteps();

             outsteps.setGroundOutTop1("","","", "");

    }
Error::
Exception in thread "main" java.lang.RuntimeException: java.lang.InstantiationException: page.BaseBallOutEvents

Whether I don't use initialize winium driver in the BaseBallOutEvents. when automate the application until combobox selection throws error ::

Exception in thread "main" java.lang.ClassCastException: Specified cast is not valid. Please use RemoteWebElement as parameter –

3 Answers 3

1

You need to instantiate BaseBallOutEvents class by creating object before assigning initialized pageFactory elements.

BaseBallOutEvents baseOut = new BaseBallOutEvents();
baseOut=  PageFactory.initElements(DriverManager.driver, BaseBallOutEvents.class);
0

I read here on GitHub.

In the example given, we rely on the PageFactory to instantiate the instance of the PageObject. It does this by first looking for a constructor that takes "WebDriver" as its sole argument (public SomePage(WebDriver driver) {). If this is not present, then the default constructor is called.

Your BaseBallOutEvents class has neither a default constructor, nor a constructor that accepts a WebDriver object.

Maybe try changing this:

private WiniumDriver driver;
public BaseBallOutEvents(WiniumDriver driver) {
    this.driver=driver;
}

Into:

private WebDriver driver;
public BaseBallOutEvents(WebDriver driver) {
    this.driver=driver;
}

This might solve the issue, not 100% sure.

Alternative

As aternative, try changing:

BaseBallOutEvents baseOut = new BaseBallOutEvents(driver);
baseOut=  PageFactory.initElements(DriverManager.driver, BaseBallOutEvents.class);

Into:

BaseBallOutEvents baseOut = new BaseBallOutEvents(driver);
PageFactory.initElements(DriverManager.driver, baseOut);
2
  • after changes have done,When selecting combobox .. i am getting this error...Exception in thread "main" java.lang.ClassCastException: Specified cast is not valid. Please use RemoteWebElement as parameter
    – user32519
    Commented May 9, 2018 at 16:47
  • I have the feeling that part of the problem comes from Winium specific things that I don't know about. I've updated my description with an alternative based on shilpa gopals suggestion.
    – Pieter A
    Commented May 10, 2018 at 8:06
0

You need to change the code as below. It worked for me.

App/Page class:

public class BaseBallOutEvents {
    public static WiniumDriver driver;

    public BaseBallOutEvents(WiniumDriver driver) {
        this.driver=driver;
    }
    // I did not use @FindBy or any PageFactory stuff, as it was throwing
    // NullPointer exception
    public void AnyPageMethod() {
        driver.findElement(By.name("Edit")).click();
        driver.findElement(By.name("Paste")).click();
    }
}

Test Class:

public class ReporterApp extends DriverManager {
    BaseBallOutEvents bbo;

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        bbo = new BaseBallOutEvents (driver);
        bbo.AnyPageMethod();
    }
}

Make sure the DriverManager class has the below instantiation of WiniumDriver:

public static WiniumDriver driver;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.