prashant-ramcharan / courgette-jvm

Multiprocess | Parallel Cucumber-JVM | Parallelize your Java Cucumber tests on a feature level or on a scenario level.
MIT License
130 stars 38 forks source link

Running Appium test with courgette-jvm library on Browserstack cloud fail #322

Closed LearningPur closed 2 years ago

LearningPur commented 2 years ago

Hi @prashant-ramcharan I have read thru the readme you have provided in this library but it seems either i am missing something or you missed something to add in this readme to let community know how to run appium test on browserstack cloud with this library

Running on local with this library works like a charm, no issue at all.

Here is the setup we have in framework to run appium test in parallel on Browserstack if you can please help pin point where the issue is it will be much appreciated

====== CourgetteRunner.java =====

import courgette.api.CourgetteOptions;
import courgette.api.CourgettePlugin;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import org.testng.annotations.Test;

@Test
@CourgetteOptions(
        threads = 3,
        runLevel = CourgetteRunLevel.SCENARIO,
        reportTargetDir = "target/HtmlReport/ExtentReport",
        rerunFailedScenarios = true,
        rerunAttempts = 1,
        showTestOutput = true,
        reportTitle = "",
//        environmentInfo = "app=Android test application; project_info=Courgette-JVM is awesome!",

        plugin = {CourgettePlugin.MOBILE_DEVICE_ALLOCATOR, "extentreports"},
           mobileDevice = {
                   "Pixel_4_API_32",
                   "Pixel4XL_Api_32",
                   "Pixel_5_API_32"
           },

        cucumberOptions = @CucumberOptions(
                features = "src/test/resources/features",
                glue = "com/sysolab/mobile/automation/steps",
                tags = "@ListParallel",
                publish = true,
                plugin = {"pretty",
                        "json:target/HtmlReport/cucumber-report/cucumber.json",
                        "html:target/HtmlReport/cucumber-report/cucumber.html"}
        ))
public class Android_Runner extends TestNGCourgette  {
}

======= Hooks.java ========

  public static AndroidDriver<WebElement> AndroidDriver;

  @Before
   public void before(Scenario scenario) throws IOException {

          AndroidDriver = BS_createAndriodDriver();
   }

  private AndroidDriver<WebElement> BS_createAndriodDriver() throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();

        // BrowserStack
        capabilities.setCapability("browserstack.user", "");
        capabilities.setCapability("browserstack.key", "");
        capabilities.setCapability("app", "bs://354e998a024c7d672f7e5661936849854857b987");
        capabilities.setCapability("project", "First Java Project");
        capabilities.setCapability("build", "browserstack-build-1");
        capabilities.setCapability("name", "first_test");

        capabilities.setCapability("device", CourgetteMobileDeviceAllocator.DEVICE_NAME);
     //   capabilities.setCapability("udid", CourgetteMobileDeviceAllocator.UDID);
     //   capabilities.setCapability("systemPort", CourgetteMobileDeviceAllocator.PARALLEL_PORT);
        capabilities.setCapability("platformName", "Android");

        capabilities.setCapability("automationName", "UiAutomator2");
        capabilities.setCapability("autoLaunch", false);
        capabilities.setCapability("newCommandTimeout", 90000);

        currentScenario.log(format("Android Device: %s", capabilities.getCapability("avd")));

      //  return new AndroidDriver<>(serverURL, capabilities);
        return new AndroidDriver (
                new URL("http://"+username+":"+accessKey+"@"+server+"/wd/hub"), capabilities
        );
    }
prashant-ramcharan commented 2 years ago

@LearningPur Please clarify what the exact issue is?

Generate your capabilities from here: https://www.browserstack.com/app-automate/capabilities

You would then just need to replace the device capability with this:

capabilities.setCapability("device", CourgetteMobileDeviceAllocator.DEVICE_NAME);
LearningPur commented 2 years ago

Hi @prashant-ramcharan I created sample project and invited you as Collaborators, when you get a chance can you please look into it

https://github.com/LearningPur/Syscolab-Mobile-Apps-Automation

In Hooks.java class i have removed BrowserStack detail as that i can't shared due to it's owned by company, if you can please try with yours and run the "Android_Runner" located inside "Runner" package.

You may also need to manually upload .apk (located inside resources/apps/dev/ folder) to browserstack and replace "bs://354e998a024c7d672f7e5661936849854857b987"

=============. If i comment out these lines of code in Android_Runner =============.

  /*  plugin = {CourgettePlugin.MOBILE_DEVICE_ALLOCATOR, "extentreports"},
    mobileDevice = {
            "Pixel_4_API_30",
            "Pixel4XL",
            "Pixel_4_API_30"
    },*/

It throws an error "java.lang.ExceptionInInitializerError" pointing to capabilities.setCapability("device", CourgetteMobileDeviceAllocator.DEVICE_NAME);

============= If i uncomment above lines of code from Android_Runner =========

it throws

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: [BROWSERSTACK_INVALID_DEVICE] Incorrect device name 'Pixel_4_API_30' specified for the 'device' capability. To view the list of available devices and configure the value for 'device' capability, visit our capability builder - https://www.browserstack.com/app-automate/capabilities (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 809 milliseconds

prashant-ramcharan commented 2 years ago

@LearningPur The error looks clear to me. You specifying a device name that does not exist in Browserstack.

You can try with a device that exists on Browserstack:

mobileDevice = { "Google Pixel 5"  },

As in my comment above and in the actual error message, you get the device names from https://www.browserstack.com/app-automate/capabilities

LearningPur commented 2 years ago

I have replaced devices with browserstack devices

        plugin = {CourgettePlugin.MOBILE_DEVICE_ALLOCATOR, "extentreports"},
           mobileDevice = {
//                   "Pixel_4_API_32",
//                   "Pixel4XL_Api_32",
//                   "Pixel_5_API_32"

                   "Google Pixel 5",
                   "Samsung Galaxy Note 10",
                  " Google Nexus 6"
           },

Now i am getting this error

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Session not started or terminated (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.49 seconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '341-MBC02FG14MMD6N.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_202'
Driver info: driver.version: AndroidDriver
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '341-MBC02FG14MMD6N.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_202'
Driver info: driver.version: AndroidDriver

It throws an error at this line

       return new AndroidDriver (
                new URL("http://"+username+":"+accessKey+"@"+server+"/wd/hub"), capabilities
        );
prashant-ramcharan commented 2 years ago

Hi @LearningPur This is not an issue with Courgette.

Please reach out to the BrowserStack / Appium forums.

I suggest you first try to get your project to run a test successfully against BrowserStack using a Cucumber test

LearningPur commented 2 years ago

Yes i created sample project to first run test on browserstack before using your library and it worked.

I have followed this document that browserstack provides https://www.browserstack.com/docs/app-automate/appium/getting-started/java

I would request you if you can please use my repo i created to try with. I am not 100% sure if it is only with your library but it works fine if i run test with browserstack provided instruction above in url.

prashant-ramcharan commented 2 years ago

Courgette just returns a string device name and nothing more.

It does not manage external connections so any errors you see about Selenium or Appium is not related to this library.

LearningPur commented 2 years ago

Understand what you are saying but if you can please take a look at where we are making mistake in our framework that will be much appreciated, whenever you get a chance not in hurry.

Just because of this we really don't want to give up this framework that we implemented with your library it is giving awesome result everybody loving it just that now the requirement is to integrate with cloud.

prashant-ramcharan commented 2 years ago

This is all you would need:

Add your specific browserstack.user, browserstack.key, app capabilities.

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserstack.user", "your_bs_user");
        capabilities.setCapability("browserstack.key", "your_bs_key");
        capabilities.setCapability("app", "bs://your_bs_app");
        capabilities.setCapability("device", CourgetteMobileDeviceAllocator.DEVICE_NAME);
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("automationName", "UiAutomator2");
        capabilities.setCapability("autoLaunch", false);

        return new AndroidDriver<>(new URL("http://hub.browserstack.com/wd/hub"), capabilities);
LearningPur commented 2 years ago

I am really sorry it was a silly mistake i had due to which it was failing, "bs://your_bs_app" this was throwing an error which i replaced with new Dev build and it worked.

I am sorry to bother you, forgive me

Thanks Victor