Есть отличная удаленная работа для php+codeception+jenkins+allure+docker спецов. 100% remote! Присоединиться к проекту

[Resolved] Используя обертку EventFiringWebDriver не выполняется isElementPresent


(Alex) #1

Дан следующий код:

***
@Test 
       public void testLogin(){
                pageManager.loginPage.isLogginVisible()
}
***
       public boolean isLogginVisible(){		
		return isElementPresent(By.id("loginModal"));	
	}	
***
       protected boolean isElementPresent(By by) {	
         try {	    	
    	  driver.findElement(by);
            return true;
          } catch(NoSuchElementException e) {    	
            return false;
       }

Когда доходит до driver.findElement(by);

Выдает 2 exception: org.openqa.selenium.NoSuchElementException и java.lang.ClassCastException. Мое исключение не срабатывает и браузер вылетает. Если поменять обертку на WebDriver, то все выполняется нормально. В чем может быть проблема?

P.S. Stacktrace:

12:18:23.641 [main] INFO com.sl.utils.WebDriverLogger - org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:“id”,“selector”:“loginModal”}
Command duration or timeout: 1.05 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.44.0’, revision: ‘76d78cf323ce037c5f92db6c1bba601c2ac43ad8’, time: ‘2014-10-23 13:11:40’
System info: host: ‘sml-pc-017’, ip: ‘10.65.5.162’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_20’
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=34.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: f6e711e3-acaa-427b-ad5e-83879eacf7e1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
at com.sun.proxy.$Proxy7.findElement(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:184)
at com.sl.pages.Page.isElementPresent(Page.java:86)
at com.sl.pages.LoginPage.isLogginVisible(LoginPage.java:47)
at com.sl.test.TestVideomovies.createAudioPIDinAssetsWithFillForm(TestVideomovies.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:“id”,“selector”:“loginModal”}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.44.0’, revision: ‘76d78cf323ce037c5f92db6c1bba601c2ac43ad8’, time: ‘2014-10-23 13:11:40’
System info: host: ‘sml-pc-017’, ip: ‘10.65.5.162’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_20’
Driver info: driver.version: unknown
at .FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/DGRIGO~1/AppData/Local/Temp/anonymous323681795684095520webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9641:26)
at .fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/DGRIGO~1/AppData/Local/Temp/anonymous323681795684095520webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:548:5)

createAudioPIDinAssetsWithFillForm================================
FAILED: createAudioPIDinAssetsWithFillForm
java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.support.events.EventFiringWebDriver
at com.sl.utils.WebDriverLogger.onException(WebDriverLogger.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.openqa.selenium.support.events.EventFiringWebDriver$1.invoke(EventFiringWebDriver.java:78)
at com.sun.proxy.$Proxy6.onException(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:103)
at com.sun.proxy.$Proxy7.findElement(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:184)
at com.sl.pages.Page.isElementPresent(Page.java:86)
at com.sl.pages.LoginPage.isLogginVisible(LoginPage.java:47)
at com.sl.test.TestVideomovies.createAudioPIDinAssetsWithFillForm(TestVideomovies.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@33065d67: 17 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@3ba987b8: 7 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@18271936: 5 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@75437611: 33 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@68c9133c: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 5 ms


(Alexey Lakovych) #2

Можете выложить кусок кода где инициализируете драйвер и обертку для него?)


(Alex) #3
***
public class ConfigBase{
protected ApplicationManager app;
@BeforeClass
public void init(){
app = new ApplicationManager();
}
}
***
public class ApplicationManager {
	private String baseUrl;
	private Capabilities firefox;
	private WebDriver webdriver;
	private EventFiringWebDriver driver;	
	
	public ApplicationManager(){
		
		firefox = DesiredCapabilities.firefox();		
		webdriver = WebDriverFactory.getDriver(firefox);
		driver = new EventFiringWebDriver(webdriver);
		driver.register(new WebDriverLogger());
		baseUrl =ConfigProperties.getProperty("url");		
		driver.manage().window().maximize(); 
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.get(baseUrl); 
}
***

(Alex) #4

Ответ найден: я использую слушатель, в котором была строка ((EventFiringWebDriver) driver).register(new WebDriverLogger());. То есть после первого исключения NoSuchException listener выполнял выше названную строку.