@Ignore abstract public class AbstractWebTest { protected static RemoteWebDriver _driver; // private String testPageLocation = String.format( "http://%s:%s/test.html", System.getProperty("test.httproot"), // Web- ... System.getProperty("test.httpport", "80") // ); // WebDriver private static String driverName = System.getProperty( "test.driver", "org.openqa.selenium.firefox.FirefoxDriver"); /** * - . * */ @BeforeClass public static void setUpDriver() throws ClassNotFoundException, IllegalAccessException, InstantiationException { _driver = (RemoteWebDriver) Class.forName(driverName).newInstance(); } /** * - */ @Before public void setUp() { _driver.get(testPageLocation); } /** * - ( ) */ @AfterClass public static void tearDown() { _driver.close(); } }
public class TestMoneyField extends AbstractWebTest { /** * 0.00 */ @Test public void testRendering() { WebElement content = _driver.findElementByCssSelector("#FieldMoney .input-text-field"); Assert.assertEquals("0.00", content.getValue()); } /** * "" */ @Test public void testInputWithoutDot() { WebElement content = _driver.findElementByCssSelector("#FieldMoney .input-text-field"); content.sendKeys("999999"); Assert.assertEquals("999 999.00", content.getValue()); } }
<target name="integrationtest" depends="init, buildtests, deploytests"> <junit haltonfailure="false"> <sysproperty key="test.driver" value="org.openqa.selenium.firefox.FirefoxDriver" /> <classpath> <pathelement location="${path.to.tests.jar}"/> </classpath> <batchtest> <fileset dir="${path.to.compiled.test.classes}"> <include name="**/tests/Test*.class" /> </fileset> </batchtest> </junit> <junit haltonfailure="false"> <sysproperty key="test.driver" value="org.openqa.selenium.ie.InternetExplorerDriver" /> <classpath> <pathelement location="${path.to.tests.jar}"/> </classpath> <batchtest> <fileset dir="${path.to.compiled.test.classes}"> <include name="**/tests/Test*.class" /> </fileset> </batchtest> </junit> </target>
@Ignore abstract public class AbstractWebTest { // private String screenshotDir = System.getProperty("test.screenshotDir", ""); @Rule public MethodRule watchman = new TestWatchman() { /** * "" * @param e * @param method - */ @Override public void failed(Throwable e, FrameworkMethod method) { if(_driver instanceof TakesScreenshot && !screenshotDir.equals("")) { String browserName = _driver.getClass().getName(); String testSuiteName = method.getMethod().getDeclaringClass().getName(); browserName = browserName.substring(browserName.lastIndexOf('.') + 1); testSuiteName = testSuiteName.substring(testSuiteName.lastIndexOf('.') + 1); byte[] screenshot = ((TakesScreenshot)_driver).getScreenshotAs(OutputType.BYTES); try { FileOutputStream stream = new FileOutputStream( new File( String.format("%s/screenshot_%s_%s_%s.png", screenshotDir, browserName, testSuiteName, method.getName()))); stream.write(screenshot); stream.close(); } catch (IOException e1) { e1.printStackTrace(System.out); } } } }; // ... }
<junit haltonfailure="false"> <sysproperty key="test.driver" value="org.openqa.selenium.firefox.FirefoxDriver" /> <sysproperty key="test.screenshotDir" value="${screenshotsDir}" /> <classpath> <pathelement location="${path.to.tests.jar}"/> </classpath> <batchtest> <fileset dir="${path.to.compiled.test.classes}"> <include name="**/tests/Test*.class" /> </fileset> </batchtest> </junit>
Source: https://habr.com/ru/post/114145/
All Articles