java-client icon indicating copy to clipboard operation
java-client copied to clipboard

Getting Authorization required

Open ayushi-nyk opened this issue 3 years ago • 12 comments

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.

ayushi-nyk avatar Feb 08 '23 15:02 ayushi-nyk

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

valfirst avatar Feb 09 '23 10:02 valfirst

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

<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"> <modelVersion>4.0.0</modelVersion>

<groupId>testProject</groupId> <artifactId>Practice</artifactId> 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
<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-api</artifactId>
  <version>4.7.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-remote-driver</artifactId>
  <version>4.7.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-support</artifactId>
  <version>4.8.0</version>
  <scope>runtime</scope>
</dependency>

	<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
	<dependency>
		<groupId>io.appium</groupId>
		<artifactId>java-client</artifactId>
		<version>8.3.0</version>
	</dependency>
	
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
<!--  run testng using jar -->
org.apache.maven.plugins maven-jar-plugin 3.1.0 abc/JarMain
    <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
    <plugin>
      <artifactId>maven-clean-plugin</artifactId>
      <version>3.1.0</version>
    </plugin>
    <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
    </plugin>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-install-plugin</artifactId>
      <version>2.5.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-deploy-plugin</artifactId>
      <version>2.8.2</version>
    </plugin>
    <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
    <plugin>
      <artifactId>maven-site-plugin</artifactId>
      <version>3.7.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-project-info-reports-plugin</artifactId>
      <version>3.0.0</version>
    </plugin>
  </plugins>
</pluginManagement>

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

ayushi-nyk avatar Feb 13 '23 07:02 ayushi-nyk

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

valfirst avatar Feb 13 '23 09:02 valfirst

@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 .

ayushi-nyk avatar Feb 13 '23 09:02 ayushi-nyk

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

valfirst avatar Feb 15 '23 14:02 valfirst

@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));
        }

Liandro73 avatar Jul 10 '23 20:07 Liandro73

@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

Salchi12 avatar Nov 15 '23 15:11 Salchi12

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

Liandro73 avatar Nov 15 '23 16:11 Liandro73

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

Salchi12 avatar Nov 15 '23 16:11 Salchi12

@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

Liandro73 avatar Nov 16 '23 01:11 Liandro73