import java.util.concurrent.TimeUnit; import java.util.*; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import org.openqa.selenium.chrome.ChromeDriver; public class SeleniumTest { private static ChromeDriver driver; String username = "testuser3@inbox.ru"; String password = "Ooy1eimu"; void login(String user, String pass) { List addr_parts = Arrays.asList(user.split("@")); String user_prefix = addr_parts.get(0); String user_suffix = addr_parts.get(1); driver.get("https://mail.ru"); driver.findElement(By.id("mailbox__login")).clear(); driver.findElement(By.id("mailbox__login")).sendKeys(user_prefix); Select mbtype = new Select(driver.findElement(By.id("mailbox__login__domain"))); mbtype.selectByVisibleText("@" + user_suffix); driver.findElement(By.id("mailbox__password")).sendKeys(pass); driver.findElement(By.id("mailbox__auth__button")).click(); } void logout() { driver.findElement(By.id("PH_logoutLink")).click(); } @BeforeClass public static void openBrowser(){ driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @Test public void valid_UserCredential(){ login(username, password); logout(); WebElement element = null; try{ element = driver.findElement(By.id("mailbox__auth__button")); }catch (Exception e){ } Assert.assertNotNull(element); } @Test public void inValid_UserCredential(){ login(username, password + "_false"); WebElement element = null; try{ element = driver.findElement(By.className("login-page__external_error")); }catch (Exception e){ } Assert.assertNotNull(element); } @Test public void search_Google(){ driver.get("https://mail.ru"); driver.findElement(By.id("q")).sendKeys("google"); driver.findElement(By.id("search__button__wrapper__field")).click(); WebElement element = null; try { element = driver.findElement(By.linkText("Google")); } catch (Exception e){ } Assert.assertNotNull(element); } @Test public void mailDelivers() throws InterruptedException { login(username, password); driver.findElement(By.xpath("//span[contains(text(), 'Compose')]")).click(); driver.findElement(By.xpath("//textarea[contains(@data-original-name, 'To')]")).sendKeys(username); driver.findElement(By.xpath("//input[contains(@name, 'Subject')]")).sendKeys("So long"); driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id, 'composeEditor_ifr')]"))); driver.findElement(By.id("tinymce")).sendKeys("And thanks for all the fish"); driver.switchTo().defaultContent(); driver.findElement(By.xpath("//span[contains(text(), 'Send')]")).click(); Thread.sleep(10000); driver.get("https://e.mail.ru/messages/inbox"); driver.findElement(By.xpath("//a[contains(@data-subject, 'So long')]")).click(); logout(); } @AfterClass public static void closeBrowser(){ driver.quit(); } }