public class GmailPageTestWithBO { private static Logger log = Logger.getLogger(GmailPageTestWithBO.class); private WebDriver driver = DriverManager.getInstance(); private LoginBO loginBO; private GmailMainContentBO mainContentBO; private GmailLeftPanelBO leftPanelBO; public static String USER_LOGIN = "******"; public static String USER_PASSWORD = "******"; @BeforeTest public void setUp() { driver.get(GmailLoginPage.LOGIN_URL); driver.manage().window().maximize(); loginBO = new LoginBO(); loginBO.login(USER_LOGIN, USER_PASSWORD); } @Test(groups = "GMAIL_PAGE") public void testIfDraftFolderContainsSavedAndClosedDraft() { mainContentBO = new GmailMainContentBO(); mainContentBO.saveAndCloseDraftMessage(TestUtils.TEST_MESSAGE_FOR_GMAIL_PAGE_TEST); leftPanelBO = new GmailLeftPanelBO(); leftPanelBO.clickDraftLink(); List<WebElement> allMessages = mainContentBO.takeAllLettersFromPage(); Assert.assertTrue( letterContainsTextMessage(allMessages, TestUtils.TEST_MESSAGE_FOR_GMAIL_PAGE_TEST), "any letter doesn't contain test message"); } @AfterTest public void tearDown() { DriverManager.closeQuietly(); } /** * Check if list of letters from page contains text message. * * @param webElementList list of web elements. * @param message test message. * @return if letter contain message true, otherwise false. */ public boolean letterContainsTextMessage(List<WebElement> webElementList, String message) { for (WebElement element : webElementList) { if (element.getText().contains(message)) { return true; } } return false; } }
@AfterTest public void tearDown() { DriverManager.closeQuietly(); }