Guillaume
Guillaume

Reputation: 3

Selenium test run with Jenkins cannot interact with element

I need to test a website on IE11, so I've made a selenium test project with IEDriver. I also use Maven. Everything works fine in local, and I now have to use Jenkins to launch my tests.

I created a simple job to try with just one of my tests. Jenkins finds my pom.xml, opens the browser with IEDriver, navigates to my url, and then the problems begin.

What my test does when run locally :

  • Clicks on the "Welcome screen" to access the next page;
  • Checks two elements on the new page with 3 assertions :

    1) element1.getText().trim().equalsIgnoreCase(myText1);

    2) element2.getText().trim().equalsIgnoreCase(myText2);

    3) element2.isEnabled();

  • Clicks on element2 to get to the next page;

  • Checks other elements.

What my test does when launched via Jenkins :

  • Clicks on the "Welcome screen" to access the next page; => this is OK, but easy, because this page only contains 1 element that takes all the screen
  • Fails at checking the 2 elements :

    1) is false, and element1.getText() is blank

    2) is false, and element2.getText() is blank

    3) is true

  • If I remove the assertions and try to directly click on element2, I have a ElementNotInteractableException

I catch any exception to get a screenshot when there is an error. Here, the screenshot is just a black screen.

So from what I understand, when launched with Jenkins, Selenium "knows" that there are some elements on the page (=> element2.isEnabled() is true), but does not "see" them (=> element2.getText() is empty) and cannot interact with them, as if they were "behind" the black screen and Selenium does not manage to focus the "real" screen.

I really don't understand what is going on. I tried to run my test with Chrome Driver, I have the same problem. I'm pretty sure I'm missing something obvious.

If you have any idea, I would greatly appreaciate it. It's my first message here, if I didn't write it in the correct way or if something is missing, you can say it too.

Here is the stacktrace of the ElementNotInteractableException :

org.openqa.selenium.ElementNotInteractableException: Cannot click on element

Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z' System info: host: 'BLABLA', ip: 'BLABLA', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_102'

Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Capabilities [{proxy=Proxy(), acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:43020/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, timeouts={implicit=0, pageLoad=300000, script=30000}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, platformName=WINDOWS, setWindowRect=true, platform=WINDOWS}]

Session ID: 50e4def1-11aa-43c6-8f9e-a52cd324a1b5

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:423)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)

at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)

at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)

at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)

at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)

at framework.elements.CustomElement.click(CustomElement.java:141)

at parionsDirect.pageObject.PageVeilleAccueil.clicPremiereVisite(PageVeilleAccueil.java:56)

at testAutomatises.TestHorsConnexion.pageVeilleVisiteur(TestHorsConnexion.java:97)

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:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)

at org.junit.rules.RunRules.evaluate(RunRules.java:20)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)

at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)

at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)

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:498)

at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)

at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)

at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Upvotes: 0

Views: 2185

Answers (2)

SerhiiBond
SerhiiBond

Reputation: 277

You said, that when you run tests on Jenkins, which is installed on your PC, browsers even can't be seen, and you tried chrome and IE.
I personally met this situation when I installed Jenkins just launching jenkins.exe. Try to run it as server using "java -jar jenkins.war" command. In my case this question helped me Jenkins : Selenium GUI tests are not visible on Windows

Upvotes: 0

Manmohan_singh
Manmohan_singh

Reputation: 1804

For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Inside this key, create a DWORD value named iexplore.exe with the value of 0.

IE also cache's the content between runs/usage and you would have to clear the cache and personal settings. I have found that the following helps ensure that the instance is clean when starting. These are options that will be passed into the IE instance when instantiating the WebDriver.

Local:

var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
//Clean the session before launching the browser
options.EnsureCleanSession = true;

Remote:

capabilities = DesiredCapabilities.InternetExplorer();
capabilities.SetCapability("ie.ensureCleanSession", true);

Upvotes: 0

Related Questions