|
| 1 | +package com.example.tests; |
| 2 | + |
| 3 | +import java.util.regex.Pattern; |
| 4 | +import java.util.concurrent.TimeUnit; |
| 5 | +import org.junit.*; |
| 6 | +import static org.junit.Assert.*; |
| 7 | +import static org.hamcrest.CoreMatchers.*; |
| 8 | +import org.openqa.selenium.*; |
| 9 | +import org.openqa.selenium.firefox.FirefoxDriver; |
| 10 | +import org.openqa.selenium.support.ui.Select; |
| 11 | + |
| 12 | +public class DesktopTest { |
| 13 | + private WebDriver driver; |
| 14 | + private String baseUrl; |
| 15 | + private boolean acceptNextAlert = true; |
| 16 | + private StringBuffer verificationErrors = new StringBuffer(); |
| 17 | + |
| 18 | + @Before |
| 19 | + public void setUp() throws Exception { |
| 20 | + driver = new FirefoxDriver(); |
| 21 | + baseUrl = "https://www.zalando.co.uk"; |
| 22 | + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testDesktopTest() throws Exception { |
| 27 | + driver.get(baseUrl + "/customer-logout"); |
| 28 | + driver.get(baseUrl + "/category/women-shoes/products?gender=FEMALE"); |
| 29 | + assertTrue(isElementPresent(By.xpath("//div[7]/div/div[3]"))); |
| 30 | + assertTrue(isElementPresent(By.xpath("//div[18]/div[3]"))); |
| 31 | + assertTrue(isElementPresent(By.xpath("//div[@id='slider-range']/div/div"))); |
| 32 | + assertTrue(isElementPresent(By.cssSelector("div.filter-checkbox-wrapper > div.checkbox > label"))); |
| 33 | + driver.findElement(By.cssSelector("div.filter-checkbox-wrapper > div.checkbox > label")).click(); |
| 34 | + driver.findElement(By.cssSelector("div.filter-apply")).click(); |
| 35 | + try { |
| 36 | + assertTrue(driver.findElement(By.cssSelector("input.filter-tag-id")).isSelected()); |
| 37 | + } catch (Error e) { |
| 38 | + verificationErrors.append(e.toString()); |
| 39 | + } |
| 40 | + String url = driver.getCurrentUrl(); |
| 41 | + // ERROR: Caught exception [ERROR: Unsupported command [getEval | new RegExp(‘tags=attribute_tag.([0-9]+)’).exec(‘${url}’)[1] | ]] |
| 42 | + System.out.println("$(urlHasTags)"); |
| 43 | + } |
| 44 | + |
| 45 | + @After |
| 46 | + public void tearDown() throws Exception { |
| 47 | + driver.quit(); |
| 48 | + String verificationErrorString = verificationErrors.toString(); |
| 49 | + if (!"".equals(verificationErrorString)) { |
| 50 | + fail(verificationErrorString); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + private boolean isElementPresent(By by) { |
| 55 | + try { |
| 56 | + driver.findElement(by); |
| 57 | + return true; |
| 58 | + } catch (NoSuchElementException e) { |
| 59 | + return false; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private boolean isAlertPresent() { |
| 64 | + try { |
| 65 | + driver.switchTo().alert(); |
| 66 | + return true; |
| 67 | + } catch (NoAlertPresentException e) { |
| 68 | + return false; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private String closeAlertAndGetItsText() { |
| 73 | + try { |
| 74 | + Alert alert = driver.switchTo().alert(); |
| 75 | + String alertText = alert.getText(); |
| 76 | + if (acceptNextAlert) { |
| 77 | + alert.accept(); |
| 78 | + } else { |
| 79 | + alert.dismiss(); |
| 80 | + } |
| 81 | + return alertText; |
| 82 | + } finally { |
| 83 | + acceptNextAlert = true; |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments