0

I have started building up my first Appium test in Android and for that, I started writing my code.

I instantiated my DesiredCapabilities object but when I am trying to use that reference, I cant see that reference.

Link to Image for the issue:

enter image description here

Below are the dependencies added for my project:

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.13.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>6.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>test</scope>
    </dependency>

  </dependencies>

Please help me what is missing in order to help to proceed with coding. Is any jar being missed which I need to associate?

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
Arka
  • 101
  • 1
  • 8

2 Answers2

3

You can not access the method using references directly, in the class because there is no execution entry point. You have to write your code within some method, constructor or in block(static/non-static). Refer below examples :

Way I

    DesiredCapabilities capabilities =DesiredCapabilities.android();

    public FirstDemoClass() {
        // TODO Auto-generated constructor stub
        capabilities.setCapability("deviceName", "emulator-5554");
    }

Way II

    DesiredCapabilities capabilities =DesiredCapabilities.android();

   // method
    public void setCapabilities() {

        capabilities.setCapability("deviceName", "emulator-5554");
    }

Way III

    static DesiredCapabilities capabilities = DesiredCapabilities.android();

    // block
    static {
        capabilities.setCapability("deviceName", "emulator-5554");
    }

    public static void main(String[] args) {

    }

This should work. let me know if any thing there.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
  • How does this answer the OPs question or solve his issue? ---"I instantiated my DesiredCapabilities object but when I am trying to use that reference, I cant see that reference" – GPT14 Jul 26 '18 at 04:59
  • @GPT14, because OP has not written the code inside method/constructor. and that is the way java allow to access the method of particular reference it won't allow to access some method by reference directly in class because there is no execution entry point. – NarendraR Jul 26 '18 at 05:01
  • 1
    Yes. Just saying that your answer could contain more explanation about why it didn't work for the OP and the rational behind your solution. Would +1 if you can edit your answer to include this. – GPT14 Jul 26 '18 at 05:13
  • @GPT14, yeah updated the same. you are open to edit if you wish to add more :) thanks – NarendraR Jul 26 '18 at 05:28
  • 1
    Hey... bad mistake bad mistake from my side... i forgot to define a method... :( very silly of me... thanks all – Arka Jul 26 '18 at 06:08
  • @Arka, Not an issue its happen thats programming. enjoy :) – NarendraR Jul 26 '18 at 06:12
0

Initialize your device capabilities like

public class FirstDemoClass{

  public static void main(String[] args){

    AppiumDriver<WebElement> driver;   
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("deviceName", "Android phone");
    caps.setCapability("udid", "your device unique id");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "phone version");
    caps.setCapability("appPackage", appPackage);
    caps.setCapability("appActivity", appActivity);
    driver=new AndroidDriver<WebElement>(new URL(
        "http://127.0.0.1:4723/wd/hub"), caps);
  }
}
Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38