Перейти к содержимому

contestar

Регистрация: 11 дек 2007
Offline Активность: 04 дек 2020 10:35
-----

Мои темы

Запуск тестов Selenium 2.0 на другом хосте

21 октября 2010 - 14:21

Привет,
Сейчас пробую selenium 2.0 (Webdriver) для тестирования web-приложений. До этого использовал seleniumRC + java +junit. Тесты запускал на виртульной машине путём указания её ip в setUp(). Каким образом запустить тесты не на localhost, а допустим на виртуалке с ip 192.168.1.51?

Вывод в файл AssertionError

06 июля 2010 - 13:36

Всем привет.
Использую seleniumRC(1.0.3) + Java + JUnit + IDEA.
Прикрутил для логирования log4j. Возник вопрос, при использовании verifyTrue/False в лог вывожу printStackTrace. Но в нём содержится достаточно много бесполезной информации. Есть возможность каким-либо распарсить это сообщение и выводить в лог только нужную строку. Приведу пример.

Example.class
public class Example extends TestsBase {
static Logger log = Logger.getLogger(Example.class);
public void testExample() throws Exception {
log.info("Test is running…");
try {
		verifyTrue(selenium.isElementPresent(buttonSaveTask));
		verifyTrue(selenium.isElementPresent(buttonReset));
		checkForVerificationErrors();
	 }
		catch (Throwable ex) {
				log.error(ex);
				ex.printStackTrace();
				throw new Exception(ex);		   
}

В случае отсутствия buttonSaveTask или buttonReset в логе имеем следующее:
INFO : Test is running…
ERROR: java.lang.AssertionError: java.lang.AssertionError: null
	at com.thoughtworks.selenium.SeleneseTestBase.fail(SeleneseTestBase.java:356)
	at com.thoughtworks.selenium.SeleneseTestBase.assertTrue(SeleneseTestBase.java:361)
	at com.thoughtworks.selenium.SeleneseTestBase.assertTrue(SeleneseTestBase.java:365)
	at com.thoughtworks.selenium.SeleneseTestBase.verifyTrue(SeleneseTestBase.java:125)
	at com.thoughtworks.selenium.SeleneseTestCase.verifyTrue(SeleneseTestCase.java:119)
	at tests.tests.CreateTaskScreen.UI.Buttons.testExample(Example.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:168)
	at junit.framework.TestCase.runBare(TestCase.java:134)
	at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at com.intellij.junit3.TestRunnerUtil$SuiteMethodWrapper.run(TestRunnerUtil.java:259)
	at junit.textui.TestRunner.doRun(TestRunner.java:116)
	at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108)
	at junit.textui.TestRunner.doRun(TestRunner.java:109)
	at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)

Я хочу получить в логе только это:
INFO : Test is running…
ERROR:at tests.tests.CreateTaskScreen.UI.Buttons.testExample(Example.java:34)

Это возможно?

Может вообще применить иной подход к логированию? Например, чтобы лог был таким:
INFO : Test is running…
ERROR: Button Save Task doesn't exist

В таком случае как добиться такого вывода.

Спасибо.