Здравствуйте.
Использовался saucelabs и в скриншотах не было необходимости. В связи с настройкой своего сервера нужно мне научиться делать скриншоты.
Прошу сильно не пинать, но я только начинаю автоматизировать и программировать.
Тесты я записываю в selenium builder и там есть команда снятия скриншота, но она не работает в RemoteWebDriver
Ниже код одного теста. Мне нужна помощь:
-
как сделать скриншот при фейле данного теста?
-
как сделать скриншот в любом произвольном месте теста командой?
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;
import java.util.Date;
import java.io.File;import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.;
import static org.openqa.selenium.OutputType.;public class firefox_Test {
public WebDriver wd;@Before public void setUp() throws Exception { DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("name", "just test"); wd = new RemoteWebDriver( new URL("http://********:4444/wd/hub"),caps); } @Test public void firefox_Test() { wd.get("http://*******"); wd.findElement(By.name("_username")).click(); wd.findElement(By.name("_username")).click(); wd.findElement(By.name("_username")).clear(); wd.findElement(By.name("_username")).sendKeys("test@********"); wd.findElement(By.name("_password")).click(); wd.findElement(By.name("_password")).clear(); wd.findElement(By.name("_password")).sendKeys("666"); wd.findElement(By.id("enter")).click(); assertTrue(wd.findElement(By.tagName("html")).getText().contains("Неверно указана пара логин/пароль")); //wd.getScreenshotAs(FILE).renameTo(new File("/home/black/Pictures/555.png")); wd.findElement(By.linkText("Забыли пароль?")).click(); if (!wd.findElement(By.tagName("html")).getText().contains("Восстановить")) { System.out.println("verifyTextPresent failed"); } wd.findElement(By.linkText("Я вспомнил!")).click(); wd.findElement(By.name("_password")).click(); wd.findElement(By.name("_password")).clear(); wd.findElement(By.name("_password")).sendKeys("555"); wd.findElement(By.id("enter")).click(); if (!wd.findElement(By.tagName("html")).getText().contains("Реклама")) { System.out.println("verifyTextPresent failed"); } wd.get("https://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"); wd.findElement(By.linkText("Случайная статья")).click(); String superlink = wd.getCurrentUrl(); wd.get("http://******"); wd.findElement(By.id("insertLink")).click(); wd.findElement(By.id("insertLink")).click(); wd.findElement(By.id("insertLink")).click(); wd.findElement(By.id("insertLink")).clear(); wd.findElement(By.id("insertLink")).sendKeys(superlink); wd.findElement(By.id("cutter")).click(); try { Thread.sleep(200l); } catch (Exception e) { throw new RuntimeException(e); } wd.findElement(By.id("copyLink")).click(); String supershort = wd.findElement(By.cssSelector("div.short-link > a")).getText(); wd.get(supershort); if (!wd.findElement(By.tagName("html")).getText().contains("Описание Википедии")) { System.out.println("verifyTextPresent failed"); } } @After public void tearDown() { wd.quit(); } public static boolean isAlertPresent(FirefoxDriver wd) { try { wd.switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } }
}