0

I am new to Selenium and I need help whatever I can get. I will try to provide detailed info as much as I can. I need to call the object imgBtn01 or imgBtn02 inside the FIRST Class (ImagesRepo) from the SECOND Class. The reason I want to separate it, I want all to store all the image objects from a different class.

Selenium + Sikuli > Java > Maven Project

First Class from different Package

public class ImagesRepo {

    public void imageRepoApp() {  

    //Images assigning object
     Screen screen = new Screen();
     Pattern imgBtn01 = new Pattern("/Images/Btn_ButtonName01.png");
     Pattern imgBtn02 = new Pattern("/Images/Btn_ButtonName02.png");
}

Second class, from a different package:

public class testBed {


    public static void callRepoImages() throws FindFailed {
        ReporImages();
    }


    @Test       
    public static void ReporImages() {
        Screen screen = new Screen();
        screen.click(imgBtn01); //the imgBtn01 has a redline
        screen.click(imgBtn02); //the imgBtn02 has a redline
        return;
    }
}
Das_Geek
  • 2,775
  • 7
  • 20
  • 26
jyllana24
  • 1
  • 1

1 Answers1

2

This looks to be more of a how to code in java type question.

One way to do this is to create public variables to your first class and fetch these from the second class.

Change 1st class to something like;

public class ImagesRepo {

    public Pattern imgBtn01;
    public Pattern imgBtn02;

public void imageRepoApp() {  

//Images assigning object
 Screen screen = new Screen();
 imgBtn01 = new Pattern("/Images/Btn_ButtonName01.png");
 imgBtn02 = new Pattern("/Images/Btn_ButtonName02.png");
}

You can then get these public variables in Second class as;

public class testBed{


    public static void callRepoImages() throws FindFailed {
        ReporImages();
    }


@Test       
public static void ReporImages() {
    ImagesRepo imgrepo = new ImagesRepo();
    imgrepo.imageRepoApp();   //So that pattern assignment is done.
    Screen screen = new Screen();
    screen.click(imgrepo.imgBtn01); //the imgBtn01 has a redline
    screen.click(imgrepo.imgBtn02); //the imgBtn02 has a redline
    return;

}
}

Also, add import for the class ImagesRepo appropriately in the class testBed

Code untested.

There are better ways to do it, but this seems the way to go with minimal changes to your code.

Shivam Puri
  • 1,578
  • 12
  • 25
  • 1
    dude you are really good at it. I tried it and it is working. KUDOS TO YOU! I may need your help again in the future. =) Have a great day! – jyllana24 Dec 05 '19 at 18:15
  • Glad I could help. If this answer worked for you, please click on the grey tick Mark and mark this as the answer. Also, don't forget to vote up! – Shivam Puri Dec 05 '19 at 18:50
  • I did click the check icon. Also, I voted, but since I have less than post it doesn't appear the vote. – jyllana24 Dec 05 '19 at 18:52