serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
718 stars 515 forks source link

Unable to use serenity-core with the Gradle 7.1 implementation group #2709

Open bachhavdipak opened 2 years ago

bachhavdipak commented 2 years ago

I am trying to run my automation test using serenity BDD and I am using the 3.2.0 version with Gradle 7.1 but while running the test getting the below issue if I ran my test using the below group.

implementation group: 'net.serenity-bdd', name: 'serenity-core', version: '3.2.0' But if I change it to testRuntimeOnly then it's working fine

testRuntimeOnly("net.serenity-bdd:serenity-core:3.2.0") I want to run my test using the implementation group only so that transitive dependencies are available in both compile and run time. Is there any way to resolve this issue?

Error:

Build info: version: '4.0.0', revision: '3a21814679'
System info: host: 'UKC-DSEV023991', ip: '110.4.197.09', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_281'
Driver info: io.appium.java_client.ios.IOSDriver
Command: [null, newSession {capabilities=[{appium:accessKey=546456gfgdfgk, appium:app=cloud:com.experitest.ExperiBank, appium:bundleId=com.experitest.ExperiBank, appium:deviceName= IPad (5th Generation) SPEC-0002, appium:deviceQuery=@os='ios' and @category='TABLET', platformName=iOS, appium:platformVersion=8.1, appium:testName=Quick Start iOS Native Demo}], desiredCapabilities=Capabilities {accessKey: eyJ4cC51IjoxMywieHAucCI6MSw..., app: cloud:com.experitest.Experi..., bundleId: com.experitest.ExperiBank, deviceName:  IPad (5th Generation) SPEC..., deviceQuery: @os='ios' and @category='TA..., platformName: iOS, platformVersion: 8.1, testName: Quick Start iOS Native Demo}}]
Capabilities {}

Code:

protected IOSDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities();

@BeforeEach
public void setUp()  {

    dc.setCapability("testName", "Quick Start iOS Native Demo");
    dc.setCapability("accessKey", accessKey);
    dc.setCapability("deviceQuery", "@os='ios' and @category='TABLET'");

    dc.setCapability(MobileCapabilityType.APP, "cloud:com.experitest.ExperiBank");
    dc.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.experitest.ExperiBank");

    try {
        driver = new IOSDriver(new URL("https://XXXX/wd/hub"), dc);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

@Test
public void quickStartiOSNativeDemo() {
    driver.rotate(ScreenOrientation.PORTRAIT);
    driver.findElement(By.xpath("//*[@id='usernameTextField']")).sendKeys("company");
    driver.hideKeyboard();
    driver.findElement(By.xpath("//*[@id='passwordTextField']")).sendKeys("company");
    driver.findElement(By.xpath("//*[@id='loginButton']")).click();
    driver.findElement(By.xpath("//*[@id='makePaymentButton']")).click();
    driver.findElement(By.xpath("//*[@id='phoneTextField']")).sendKeys("0541234567");
    driver.findElement(By.xpath("//*[@id='nameTextField']")).sendKeys("Jon Snow");
    driver.findElement(By.xpath("//*[@id='amountTextField']")).sendKeys("50");
    driver.findElement(By.xpath("//*[@id='countryButton']")).click();
    driver.findElement(By.xpath("//*[@id='Switzerland']")).click();
    driver.findElement(By.xpath("//*[@id='sendPaymentButton']")).click();
    driver.findElement(By.xpath("//*[@id='Yes']")).click();
}

@AfterEach
public void tearDown() {
    System.out.println("Report URL: "+ driver.getCapabilities().getCapability("reportUrl"));
    driver.quit();
}
wakaleo commented 2 years ago

That sound's like an issue with your build script or with Gradle (maybe ask the Gradle community for Gradle-specific advice), not with Serenity. The Serenity sample projects all define the Serenity dependencies as testImplementatinon dependencies but they also would work as implementation dependencies - take a look at https://github.com/serenity-dojo/swaglabs-serenity-cucumber.git

bachhavdipak commented 2 years ago

Thank you for your valuable reply @wakaleo

I have tried to run my solution as per the above repo. I have made two changes

  1. updated sourceCompatibility = 8 and targetCompatibility = 8
  2. Added serenity-junit5

I am still facing the same issue.

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

repositories {
    mavenCentral()
    mavenLocal()
}

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "net.serenity-bdd:serenity-gradle-plugin:3.2.0"
        classpath("net.serenity-bdd:serenity-core:${serenityCoreVersion}")

    }
}

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

sourceCompatibility = 8
targetCompatibility = 8

ext {
    slf4jVersion = '1.7.7'
    serenityCoreVersion = '3.2.0'
    assertJVersion = '3.22.0'
    logbackVersion = '1.2.10'
}

dependencies {
    implementation "ch.qos.logback:logback-classic:${logbackVersion}"

    testImplementation "net.serenity-bdd:serenity-core:${serenityCoreVersion}",
            "net.serenity-bdd:serenity-cucumber:${serenityCoreVersion}",
            "net.serenity-bdd:serenity-screenplay:${serenityCoreVersion}",
            "net.serenity-bdd:serenity-screenplay-webdriver:${serenityCoreVersion}",
            "net.serenity-bdd:serenity-ensure:${serenityCoreVersion}",
         //   "junit:junit:${junitVersion}",

            "io.github.fabianlinz:serenity-junit5:${serenityJunit5Version}"
}

test {
    systemProperties System.getProperties()
    maxParallelForks = 8
}

serenity {
    // Specify the root package of any JUnit acceptance tests
    testRoot="swaglabs"

    // Specify the root directory of any Cucumber feature files
    requirementsDir = "src/test/resources/features"
}

gradle.startParameter.continueOnFailure = true

test.finalizedBy(aggregate)
wakaleo commented 2 years ago

I would recommend using net.serenity-bdd:serenity-junit5 rather than io.github.fabianlinz:serenity-junit5 as it is not part of the official Serenity dependencies. Also, classpath("net.serenity-bdd:serenity-core:${serenityCoreVersion}" in the buildscript dependencies may not work because of the use of a variable.

bachhavdipak commented 2 years ago

@wakaleo : As per your suggestion i have used net.serenity-bdd:serenity-junit5 but still facing the same issue.

I have also created a branch please have a look. I have created branch https://github.com/bachhavdipak/SerenityJunit5

wakaleo commented 2 years ago

What issue are you facing exactly? There are no Serenity tests in that project.

bachhavdipak commented 2 years ago

I am trying to run my test using Junit. image

wakaleo commented 2 years ago

But the test is an ordinary Selenium test, not a Serenity BDD test. What outcome are you expecting?

bachhavdipak commented 2 years ago

@wakaleo , if I add web test in the same project and ran the test using serenity dependencies it's working fine for UI projects but for iOS its failing due to the below issues

Build info: version: '4.0.0', revision: '3a21814679'
System info: host: 'UKC-DSEV023991', ip: '110.4.197.09', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_281'
Driver info: io.appium.java_client.ios.IOSDriver
Command: [null, newSession {capabilities=[{appium:accessKey=546456gfgdfgk, appium:app=cloud:com.experitest.ExperiBank, appium:bundleId=com.experitest.ExperiBank, appium:deviceName= IPad (5th Generation) SPEC-0002, appium:deviceQuery=@os='ios' and @category='TABLET', platformName=iOS, appium:platformVersion=8.1, appium:testName=Quick Start iOS Native Demo}], desiredCapabilities=Capabilities {accessKey: eyJ4cC51IjoxMywieHAucCI6MSw..., app: cloud:com.experitest.Experi..., bundleId: com.experitest.ExperiBank, deviceName:  IPad (5th Generation) SPEC..., deviceQuery: @os='ios' and @category='TA..., platformName: iOS, platformVersion: 8.1, testName: Quick Start iOS Native Demo}}]
Capabilities {}

Also if I change the serenity-core to testRuntimeOnly then it's working fine but not with the implementation or testImplementation . I want to run my test using testImplementation or implementation group so that transitive dependencies are available in both compile and run time. Is there any way to resolve this issue?

bachhavdipak commented 2 years ago

Have you had a chance to go through my issue @wakaleo ?

wakaleo commented 2 years ago

No, I have no idea what the issue could be.

bachhavdipak commented 2 years ago

Have you tried to run my code at your end @wakaleo ? if not could you please give me a favor and try it from your end. I am stuck at the moment or else try to run it with a free account and provide me simple working code and remove your access key and hub URL.

wakaleo commented 2 years ago

That could be done as part of a support ticket or commercial support contract - is that something your company is considering?