Revert "BAEL-4134"

This commit is contained in:
Loredana Crusoveanu
2020-07-07 14:18:10 +03:00
committed by GitHub
parent dffa1f64e6
commit 485b4e3e99
2477 changed files with 9477 additions and 547819 deletions

View File

@@ -1,4 +1,4 @@
package java.com.baeldung.selenium.clickusingjavascript;
package com.baeldung.selenium.clickusingjavascript;
import org.junit.After;
import org.junit.Before;
@@ -14,16 +14,18 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class SeleniumJavaScriptClickTest {
import java.io.File;
public class SeleniumJavaScriptClickLiveTest {
private WebDriver driver;
private WebDriverWait wait;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
System.setProperty("webdriver.chrome.driver", new File("src/main/resources/chromedriver.mac").getAbsolutePath());
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 5000);
wait = new WebDriverWait(driver, 20);
}
@After
@@ -37,19 +39,21 @@ public class SeleniumJavaScriptClickTest {
String title = driver.getTitle();
assertEquals("Baeldung | Java, Spring and Web Development tutorials", title);
wait.until(ExpectedConditions.elementToBeClickable(By.className("menu-search")));
WebElement searchButton = driver.findElement(By.className("menu-search"));
wait.until(ExpectedConditions.elementToBeClickable(By.className("nav--menu_item_anchor")));
WebElement searchButton = driver.findElement(By.className("nav--menu_item_anchor"));
clickElement(searchButton);
wait.until(ExpectedConditions.elementToBeClickable(By.id("search")));
WebElement searchInput = driver.findElement(By.id("search"));
searchInput.sendKeys("Selenium");
wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-search")));
WebElement seeSearchResultsButton = driver.findElement(By.className("btn-search"));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn-search")));
WebElement seeSearchResultsButton = driver.findElement(By.cssSelector(".btn-search"));
clickElement(seeSearchResultsButton);
int seleniumPostsCount = driver.findElements(By.className("post")).size();
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("post")));
int seleniumPostsCount = driver.findElements(By.className("post"))
.size();
assertTrue(seleniumPostsCount > 0);
}

View File

@@ -1,4 +1,16 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.cookies;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import java.io.File;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@@ -9,12 +21,6 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class SeleniumCookiesJUnitLiveTest {
private WebDriver driver;
@@ -22,11 +28,21 @@ public class SeleniumCookiesJUnitLiveTest {
@Before
public void setUp() {
System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac"));
Capabilities capabilities = DesiredCapabilities.firefox();
driver = new FirefoxDriver(capabilities);
navUrl = "https://baeldung.com";
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
}
private static String findFile(String filename) {
String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here.
for (String path : paths) {
if (new File(path + filename).exists())
return path + filename;
}
return "";
}
@After

View File

@@ -1,16 +1,21 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.junit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.testng.Assert.*;
import com.baeldung.selenium.SeleniumExample;
public class SeleniumWithJUnitLiveTest {
private static SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
private String expectedTitle = "About Baeldung | Baeldung";
@BeforeClass
public static void setUp() {
@@ -18,17 +23,17 @@ public class SeleniumWithJUnitLiveTest {
}
@AfterClass
public static void tearDown() {
public static void tearDown() throws IOException {
seleniumExample.closeWindow();
}
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(expectedTitle, actualTitle);
assertTrue(seleniumExample.isAuthorInformationAvailable());
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(expectedTitle, actualTitle);
assertTrue(seleniumExample.isAuthorInformationAvailable());
}
}

View File

@@ -1,9 +1,9 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.pages;
import main.java.com.baeldung.selenium.config.SeleniumConfig;
import main.java.com.baeldung.selenium.models.BaeldungAbout;
import main.java.com.baeldung.selenium.pages.BaeldungHomePage;
import main.java.com.baeldung.selenium.pages.StartHerePage;
import com.baeldung.selenium.config.SeleniumConfig;
import com.baeldung.selenium.models.BaeldungAbout;
import com.baeldung.selenium.pages.BaeldungHomePage;
import com.baeldung.selenium.pages.StartHerePage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@@ -0,0 +1,85 @@
package com.baeldung.selenium.screenshot;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
public class TakeScreenShotSeleniumLiveTest {
private static ChromeDriver driver;
@BeforeClass
public static void setUp() {
System.setProperty("webdriver.chrome.driver", resolveResourcePath("chromedriver.mac"));
Capabilities capabilities = DesiredCapabilities.chrome();
driver = new ChromeDriver(capabilities);
driver.manage()
.timeouts()
.implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://www.google.com/");
}
@AfterClass
public static void tearDown() throws IOException {
driver.close();
System.clearProperty("webdriver.chrome.driver");
}
@Test
public void whenGoogleIsLoaded_thenCaptureScreenshot() throws IOException {
takeScreenshot(resolveTestResourcePath("google-home.png"));
assertTrue(new File(resolveTestResourcePath("google-home.png")).exists());
}
@Test
public void whenGoogleIsLoaded_thenCaptureLogo() throws IOException {
WebElement logo = driver.findElement(By.id("hplogo"));
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))
.coordsProvider(new WebDriverCoordsProvider())
.takeScreenshot(driver, logo);
ImageIO.write(screenshot.getImage(), "jpg", new File(resolveTestResourcePath("google-logo.png")));
assertTrue(new File(resolveTestResourcePath("google-logo.png")).exists());
}
public void takeScreenshot(String pathname) throws IOException {
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File(pathname));
}
private static String resolveResourcePath(String filename) {
File file = new File("src/main/resources/" + filename);
return file.getAbsolutePath();
}
private static String resolveTestResourcePath(String filename) {
File file = new File("src/test/resources/" + filename);
return file.getAbsolutePath();
}
}

View File

@@ -1,16 +1,19 @@
package test.java.com.baeldung.selenium.testng;
package com.baeldung.selenium.testng;
import com.baeldung.selenium.SeleniumExample;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class SeleniumWithTestNGLiveTest {
private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
private String expectedTitle = "About Baeldung | Baeldung";
@BeforeSuite
public void setUp() {