mercredi 9 octobre 2019

How to recognize whether is it successfully find the values for the 'asserEquals' in Selenium(POM)?

Here mentioned code successfully passed by the test run.But it was not showed the login button click and the logged-user name.(I have try to print the messages by try-catch ).but result shows as passed without those messages.

I just wanted to why can't I see the button click and assertEqual messages? is there any coding issue or practice should be able to use to overcome this?

I have used the xml file to send the browser type.Further,I pasted only the relevant code sections.

1.TestCommands.java

public class TestCommands {
public void assertText(By locator,WebDriver driver,String expectedValue){
try {
    WebElement element = driver.findElement(locator);
    assertEquals(element.getText(), expectedValue);         
} catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    System.out.println("Not equal");
}
System.out.println("Equal");
System.out.println("captured web element: "+ locator);
System.out.println("captured expectedValue: "+ expectedValue);
}
}

2.LoginPage.java

public class LoginPage extends TestCommands{
public void loginToApplication(WebDriver driver,String userName,String  password,String loggedUser){
type(userName(),driver,userName);
type(password(),driver,password);
click(loginButton(),driver);
selectByVisibleText(loggedUser(),driver,loggedUser);

}

3.TC_LoginToTest.java

public class TC_LoginToTest {
 WebDriver driver ;
 String baseUrl;
 LoginPage login = new LoginPage(); 

@Parameters("browser")
@BeforeMethod
 public void beforeMethod(String browser) {

   if (browser.equals("firefox")) {
    System.setProperty("webdriver.gecko.driver", "drivers\\geckodriver.exe");
    driver = new FirefoxDriver();
    //baseUrl = "https://test.com";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
   } else if (browser.equals("chrome")) {
    System.setProperty("webdriver.chrome.driver", "drivers\\chromedriver.exe");
    driver = new ChromeDriver();
    //baseUrl = "https://test.com";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
   }
 }  
 @DataProvider
 public Object[][] tc001() {
 return new Object[][] {
        new Object[] {"nadee","12345678","Testnadee"},      
 };
}

 @Test(dataProvider="tc001")
  public void tc001(String userName , String password ,String loggedUser)        { 
    login.openApplication("https://test.com", driver);
    login.loginToApplication(driver, userName, password, loggedUser);
  }
 }

Aucun commentaire:

Enregistrer un commentaire