0

Page Object Class

public class Transactions {
    WebDriver driver;
    boolean result1;
public Transactions(WebDriver driver) {
        //super();
        this.driver = driver;
    }

public void click_on_transaction()
{
    driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/div[3]/button[1]")).click();
}
public boolean display_transaction()
{

    List<WebElement> element= driver.findElements(By.id("anchor0"));
    Integer trsize= element.size();
    //System.out.println(trsize);
    String[] current_transaction = {"Oct 25, 2018 12:07:52 PM 1200 Credit", "Oct 25, 2018 12:07:56 PM 200 Debit"};
    int i;
    for(i=0;i<=trsize;i++)
    {
        WebElement transaction_table= driver.findElement(By.id("anchor"+i));
        String table_data= transaction_table.getText();
        @SuppressWarnings("unlikely-arg-type")
        boolean result1 = (table_data.equals(current_transaction));

    }
    return result1;

}

}  

Here is my Test Class

public class TestTransactionDetails extends BaseTest {
  @Test
  public void view_complete_transaction() throws Exception {
      TestWithdrawl testwithdrawl= new TestWithdrawl();
      Transactions transaction= new Transactions(driver);
      testwithdrawl.valid_ammount_withdrawl();
      transaction.click_on_transaction();

      ScreenShot.takeSnapShot(driver, "D:\\Images\\Test4");
      Assert.True(transaction.display_transaction());
  }
}

Here is my Base Class

public class BaseTest {
    public static WebDriver driver;
  @BeforeTest
  public void launchBank() {
      //System.setProperty("webdriver.chrome.driver", "C:\\Intel\\chromedriver.exe");
      //driver = new ChromeDriver(); 
      driver= new FirefoxDriver();
      driver.get("http://www.way2automation.com/angularjs-protractor/banking/#/login");
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  }
  @AfterTest
  public void QuitLaunch()
  {
      driver.close();
      driver.quit();
  }
}  

I'm new to Automation so i'm not able to verify that my test is fail or pass and how to verify this.Plz someone help me to get out of it.

  • Can you explain your code? What is happening and when and in which order? So that we do not spend time on your code debugging to make our advice more effective. – Alexey R. Oct 25 '18 at 12:34
  • Why would you suppress the unlikely arg-type warning? You are attempting to compare a text string to a string array - it will always return false. – Bill Hileman Oct 25 '18 at 14:04
  • @AlexeyR., In the page object class i have defined all the element and in display_transaction method i have used the table so by table id i'm picking up the each table record then i had compared the string with array, then there is Base class where i have defined the method for driver & browser launch, then i have inherit that in TestTransactionDetails class and i have make the object of page object class and call the all methods ob page object class then at last using the Assert for true & false , – Upkar Singh Oct 25 '18 at 14:37
  • @BillHileman i used suppress the unlikely arg-type warning because just eclipse was suggesting me to do that. – Upkar Singh Oct 25 '18 at 14:39
  • Eclipse provides that as a solution option because in rare instances a warning is just that, a warning and does not affect code, but the compiler has no way of knowing if it will adversely affect your code or not. In this case, it does. If I understand your code correctly, you are attempting to compare some text to one of two possible values, but you are doing it by comparing one text string to an array of two text strings with only one compare (equal). It will always fail because a single string will never match a string array - they are not the same "type" – Bill Hileman Oct 25 '18 at 14:47
0

I found my answer it is working for me, i just tried a very simple way to verify small table data

Now my Page Object Class method look like this

public String display_transaction()
{
    List<WebElement> element= driver.findElements(By.tagName("tr"));
    Integer trsize= element.size(); 
    String reult_set = null;
    int j;
    String[] ammountmessage= {"1200","200"};    
    for(j=0;j<trsize-1;j++)
    {
    WebElement transaction_table1= driver.findElement(By.xpath(".//*[@id='anchor"+j+"']/td[2]"));
    String data1=transaction_table1.getText();
    if (data1.equals(ammountmessage[j]))
    {
    reult_set="Transaction Pass";   
    }
    else
    {       
        reult_set=null;
        break;      
    }
    }   
    return reult_set;
}  

And my Test Class

public class TestTransactionDetails extends BaseTest {
  @Test
  public void view_complete_transaction() throws Exception {
      TestWithdrawl testwithdrawl= new TestWithdrawl();
      Transactions transaction= new Transactions(driver);
      testwithdrawl.valid_ammount_withdrawl();
      Thread.sleep(1000);
      transaction.click_on_transaction();     
      ScreenShot.takeSnapShot(driver, "D:\\Images\\Test4");
      Assert.assertEquals( transaction.display_transaction(),"Transaction Pass");
  }
}  

Thank you all who response for this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.