appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 757 forks source link

Getting Authorization required #1858

Open ayushi-nyk opened 1 year ago

ayushi-nyk commented 1 year ago

I have below selenium version 4 and io.appium version 8 java client dependency in same pom.xml -

org.seleniumhq.selenium selenium-java 4.0.0

,

io.appium java-client 8.0.0

When I able to run app test on browser stack then getting below error - Exception e === org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response: Authorization required

However this issue was not happening when I was using selenium 3.1 and appium 7.6 .

All I want is to upgrade the selenium version 4 in my framework and we have common framework for web and app.

Please suggest.

valfirst commented 1 year ago

Please follow migration guides, for Appium you can find the guide here: https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md

ayushi-nyk commented 1 year ago

@valfirst The error I got is before driver invocation , below is my code and pom.xml-

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0 testProject Practice 0.0.1-SNAPSHOT Practice http://www.example.com UTF-8 1.7 1.7 junit junit 4.11 test org.testng testng 7.1.0 org.seleniumhq.selenium selenium-api 4.7.2 compile org.seleniumhq.selenium selenium-remote-driver 4.7.2 compile org.seleniumhq.selenium selenium-support 4.8.0 runtime io.appium java-client 8.3.0 org.apache.maven.plugins maven-surefire-plugin 2.19.1 {test_type} ${suiteXmlFile} org.apache.maven.plugins maven-jar-plugin 3.1.0 testverifypackage/testclass1 org.codehaus.mojo exec-maven-plugin 1.2.1 default-cli exec java -jar ${basedir}/target/Practice-0.0.1-SNAPSHOT.jar org.apache.maven.plugins maven-jar-plugin 3.1.0 abc/JarMain maven-clean-plugin 3.1.0 maven-resources-plugin 3.0.2 maven-compiler-plugin 3.8.0 maven-surefire-plugin 2.22.1 maven-install-plugin 2.5.2 maven-deploy-plugin 2.8.2 maven-site-plugin 3.7.1 maven-project-info-reports-plugin 3.0.0

Code -

package testverifypackage;

import java.net.URL; import java.util.HashMap;

import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.remote.options.BaseOptions;

public class AppiumUpgrade {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    try {
        UiAutomator2Options options = new UiAutomator2Options().setPlatformName("Android");

        options.setCapability("appium:platformVersion", "11.0");
        options.setCapability("appium:deviceName", "Samsung Galaxy S21 Ultr");

        HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
        browserstackOptions.put("user","***");
        browserstackOptions.put("key","***");
        browserstackOptions.put("appiumVersion", "2.0.0");
        options.setCapability("bstack:options", browserstackOptions);

        System.out.println("options == " +options);

        AndroidDriver driver  = new AndroidDriver(
                new URL("http://hub.browserstack.com/wd/hub"), options);

    System.out.println("Appium Driver is Up !!!");

    driver.quit();

    System.out.println("Appium Driver is Closed !!!");
        } 
            catch(Exception e) {
            System.out.println("Exception e === " + e);
        }
    }
    }

Error - Exception e === org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response: Authorization required

valfirst commented 1 year ago

@ayushi-nyk most likely you provided wrong credentials, or used improper way to provide credentials

ayushi-nyk commented 1 year ago

@valfirst The same is working fine when i used selenium 3.1 and appium 7.6 . Is this something related to appium and selenium version compatibility .

valfirst commented 1 year ago

@ayushi-nyk Appium Java Client follows semantic versioning, it means bump of major version may introduce breaking changes

Liandro73 commented 1 year ago

@ayushi-nyk I was with the same issue in a recent project, but I am actually studying about the new versions of Appium and Selenium, and I am really focused in this project, and I found your issue, but yet without a fix. Please for this new format using new Selenium and Appium, try this values:

Replace: user to userName key to accessKey

        if (platform.equals("DEVICE_FARM")) {  
            MutableCapabilities capabilities = new MutableCapabilities();
            capabilities.setCapability("app", "bs://??????");

            HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
            browserstackOptions.put("userName", userName);
            browserstackOptions.put("accessKey", accessKey);
            browserstackOptions.put("osVersion", "13.0");
            browserstackOptions.put("deviceName", "Google Pixel 7");
            browserstackOptions.put("projectName", "Project Name");
            browserstackOptions.put("buildName", "1.0");
            browserstackOptions.put("sessionName", "Session Name");
            browserstackOptions.put("appiumVersion", "2.0.0");
            browserstackOptions.put("local", "false");
            browserstackOptions.put("debug", "true");
            browserstackOptions.put("timezone", "New_York");
            capabilities.setCapability("bstack:options", browserstackOptions);

            androidDriver = new AndroidDriver
                              (new URL("http://hub.browserstack.com/wd/hub"), capabilities);
            androidDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(SHORT_TIMEOUT));
            waitDriver = new WebDriverWait(androidDriver, Duration.ofSeconds(LONG_TIMEOUT));
        }
Salchi12 commented 11 months ago

@ayushi-nyk I was with the same issue in a recent project, but I am actually studying about the new versions of Appium and Selenium, and I am really focused in this project, and I found your issue, but yet without a fix. Please for this new format using new Selenium and Appium, try this values:

Replace: user to userName key to accessKey

        if (platform.equals("DEVICE_FARM")) {  
            MutableCapabilities capabilities = new MutableCapabilities();
            capabilities.setCapability("app", "bs://??????");

            HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
            browserstackOptions.put("userName", userName);
            browserstackOptions.put("accessKey", accessKey);
            browserstackOptions.put("osVersion", "13.0");
            browserstackOptions.put("deviceName", "Google Pixel 7");
            browserstackOptions.put("projectName", "Project Name");
            browserstackOptions.put("buildName", "1.0");
            browserstackOptions.put("sessionName", "Session Name");
            browserstackOptions.put("appiumVersion", "2.0.0");
            browserstackOptions.put("local", "false");
            browserstackOptions.put("debug", "true");
            browserstackOptions.put("timezone", "New_York");
            capabilities.setCapability("bstack:options", browserstackOptions);

            androidDriver = new AndroidDriver
                              (new URL("http://hub.browserstack.com/wd/hub"), capabilities);
            androidDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(SHORT_TIMEOUT));
            waitDriver = new WebDriverWait(androidDriver, Duration.ofSeconds(LONG_TIMEOUT));
        }

Hi @Liandro73, how can i put more devices? I hope u can help me

Liandro73 commented 11 months ago

Hi @Salchi12, you can use a browserstack.yml file to send parallel tests:

userName: yourUser
accessKey: yourPass
framework: testng
app: bs://sample.app
platforms:
  - platformName: android
    deviceName: Samsung Galaxy S22 Ultra
    platformVersion: 12.0
  - platformName: android
    deviceName: Google Pixel 7 Pro
    platformVersion: 13.0
  - platformName: android
    deviceName: OnePlus 9
    platformVersion: 11.0
browserstackLocal: true
buildName: 0.1.0
projectName: Project Name
Salchi12 commented 11 months ago

@Liandro73 but when i use the yml file and the execution throws me test with diferent devices I choose

Liandro73 commented 11 months ago

@Salchi12 You know that BrowserStack has a list of possible devices to choose from, right? Try this link to verify the devices and OS version, before to set your test execution: https://www.browserstack.com/automate/capabilities?tag=selenium-4