0

i have two methods in same class method1() and method2(). method 1() is to read a 'String' and extract integers from that string and method2 () is to perform a click operation. This click operation changes the 'string' which is the input of method1 () . Evreythign is working fine but my problem is Case 1 When i am calling these two methods from another class in following way -

method1();-------- 1
method2();-------- 2
method1();---------3

i get a clear result which shows the result of line 1 is different from line 3 becuase the string was changed by line 2 BUT

Case 2 when i am calling method1() inside method2 () in the same class in the following way -

method2();{
method1();---------1
click statement of method2;
method1();---------2
}

and calling this method2(); from another class it doesnt work line 1 and line 2 gives same result.

where i am wrong in case 2 or its not possible to call a public method of the same class twice in another public method ?? please guide.

if you need code details here it is :-

 public void clickOnFaces(int n) {
       ArrayList<Integer> ratingLikes = ratingLikes(n);
        int likes = ratingLikes.get(0);
        int total = ratingLikes.get(1); 

        seleniumclient.elements(Mappings.face).get(n).click();

       ArrayList<Integer> updatedRatingLikes = ratingLikes(n);

            int c = updatedRatingLikes.get(0);
        int d = updatedRatingLikes.get(1);
    }





    public ArrayList ratingLikes(int n) {
        seleniumactions.waitForElement(Mappings.ratingLikes);
        ArrayList<Integer> likes = new ArrayList<>();
        Pattern p = Pattern.compile("\\d+");
        Matcher m = p.matcher(seleniumclient.elements(Mappings.ratingLikes).get(n).getText());
            while (m.find()) {
                likes.add(Integer.parseInt(m.group()));
                 }
            return likes;

Issue is the value of 'c' and 'd' is same as 'likes' and 'total'. how ever they change when i keep only the click statement in clickonfaces() and call these mthods from different class example :

object.ratingLikes(int 0);
object.clickOnFaces(int 0);
object.ratingLikes(int 0);
5
  • 1
    Post your code. Commented May 2, 2020 at 22:43
  • i have added the code details @ArvindKumarAvinash Commented May 2, 2020 at 22:51
  • I can't understand it. Where is method 1. And where is method 2. clickOnFace do almost nothing except seleniumclient.elements. So, c and d for what Commented May 3, 2020 at 0:46
  • @LêHoàngDững . method 1 is rating likes() this find out the integers from a string "seleniumclient.elements(Mappings.ratingLikes).get(n).getText()" and method two is clickonFace() this method click on a webelement "(Mappings.face).get(n)", when this click happens the input string of method 1 "seleniumclient.elements(Mappings.ratingLikes).get(n).getText()" changes . so basically i want to know the integers in the string before and after the click. am i making any sense :( @ Lê Hoàng Dững Commented May 3, 2020 at 6:56
  • Try to set ratingList to a class variable. set ratingLikes method to void. It will save changes of list to ratingList. If not success, you can run the debug to see what is going on your code Commented May 3, 2020 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.