serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

Error on my first serernity with appium: this class doesn't have an empty or a page enabled constructor #226

Open baligit opened 4 years ago

baligit commented 4 years ago

Hallo all,

i am trying to build my Test on Serernity with Appium using cucumbar. I am trying to do a simple test Calculator. Unfortunately my program failed with the follwing error: Failed to instantiate class implementSenario.Stepdefcalulator - this class doesn't have an empty or a page enabled constructor"

This is my Stepdefcalulator class: package implementSenario;

public class Stepdefcalulator extends MobilePageObject {

public Stepdefcalulator(WebDriver driver){
    super(driver);
}
@AndroidFindBy(id="com.sec.android.app.popupcalculator:id/bt_01")
private WebElement elementOne;
@AndroidFindBy(id="com.sec.android.app.popupcalculator:id/bt_add")
private WebElement elementPlus;
@AndroidFindBy(id="com.sec.android.app.popupcalculator:id/bt_equal")
private WebElement elementEqual;
@AndroidFindBy(id="com.sec.android.app.popupcalculator:id/txtCalc")
private WebElement elementResult;

@Given("^I am on the calculator app$")
public void i_am_on_the_calculator_app() {
}

@When("^I click one$")
public void i_click_one() {
    elementOne.click();
}

@When("^I click plus$")
public void i_click_plus() {
    elementPlus.click();
}

@When("^I click equals$")
public void i_click_equals() {
    elementEqual.click();
}

@Then("^the result should be (\\d+)$")
public void the_result_should_be(int arg1) {
    assertThat(elementResult.getText()).isEqualTo(arg1);
}

}

And this is my MobilePageObject class:

public class MobilePageObject extends PageObject {

public MobilePageObject(final WebDriver driver) {
    super(driver, new Predicate<PageObject>() {
        @Override
        public boolean apply(PageObject page) {
            PageFactory.initElements(new AppiumFieldDecorator(
                    ((WebDriverFacade) page.getDriver()).getProxiedDriver(), page.getImplicitWaitTimeout()), page);
            return true;
        }
    });
}

}

and this is my gradle file:

defaultTasks 'clean','test','aggregate'

repositories { mavenLocal() jcenter() }

buildscript { repositories { mavenLocal() jcenter() } dependencies { classpath("net.serenity-bdd:serenity-gradle-plugin:2.0.91") } }

apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'net.serenity-bdd.aggregator'

sourceCompatibility = 1.8 targetCompatibility = 1.8 ext { slf4jVersion = '1.7.7' serenityCoreVersion = '2.0.17' junitVersion = '4.12' assertJVersion = '3.8.0' logbackVersion = '1.2.3' CucumbarVersion = '1.9.20' }

dependencies { compile "ch.qos.logback:logback-classic:${logbackVersion}" testCompile "net.serenity-bdd:serenity-core:${serenityCoreVersion}", "net.serenity-bdd:serenity-junit:${serenityCoreVersion}", "junit:junit:${junitVersion}", "org.assertj:assertj-core:${assertJVersion}", "net.serenity-bdd:serenity-cucumber:${CucumbarVersion}" compile group: 'io.appium', name: 'java-client', version: '4.1.2' }

test { testLogging.showStandardStreams = true systemProperties System.getProperties() }

gradle.startParameter.continueOnFailure = true

test.finalizedBy(aggregate)

wakaleo commented 4 years ago

How are you using the Stepdefcalulator class?

baligit commented 4 years ago

I am unsing Stepdefcalulator on my following Testrunner:

@RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/feature")

public class MyTestRunner { @Managed(driver = "appium") public WebDriver driver;

 @Steps
Stepdefcalulator testerTow;

@Test
public void second_test(){
    testerTow.i_am_on_the_calculator_app();
    testerTow.i_click_one();
    testerTow.i_click_equals();
    testerTow.i_click_one();
    testerTow.the_result_should_be(2);
}
wakaleo commented 4 years ago

@Steps is for step library classes, not for page objects - you don't need an annotation for page objects. It looks like you are mixing step definition methods, glue code and page object logic in one class. Have a look at the docs (https://serenity-bdd.github.io/theserenitybook/latest/index.html) to see how Serenity code is intended to be layered.