HI Lasantha,

I think you can get some input form Dev mail thread "Unable to automate a
UI test case with Selenium for a file uploading in Jaggery"

Thanks and Best Regards,

Saneth Dharmakeerthi
Senior Software Engineer
WSO2, Inc.
Mobile: +94772325511

On Fri, Oct 9, 2015 at 11:54 AM, Lasantha Samarakoon <[email protected]>
wrote:

> Hi all,
>
> I am working in Selenium based UI automation testing for the UES. In the
> scenario which I am working on, I need to upload an image when I click on a
> button. The code for the functionality as follows.
>
> *HTML:*
>
>
> <!-- this entire form is hidden --><form method="post" 
> id="ues-dashboard-upload-banner-form" action="/path/to/form" class="hidden">
>     <input type="file" id="file-banner" name="banner" accept="image/*" />     
>     ...</form>
> <div class="ues-banner-placeholder">
>     <button type="button" id="btn-edit-banner" class="btn 
> btn-primary">Edit</button>
>     ...
>  </div>
>
>
> *Javascript:*
>
> (function() {
>     var initBanner = function() {
>
>         // clicking the edit button will trigger the click event of the 
> input[type=file] field and opens the file browser
>         $('.ues-banner-placeholder').on('click', '#btn-edit-banner', 
> function(e) {            $('#file-banner').click();
>         });
>                   // once the value of the input[type=file] field changed, do 
> some processing         
> document.getElementById('file-banner').addEventListener('change', function 
> (e) {
>             ...
>         });
>         ...
>     }
>
>     initBanner();     
>     ...
> })();
>
>
> Here when I tried to automate the functionality using Selenium, seems like
> it cannot manipulate the file browser. Instead they are suggesting to
> inject the path of the file directly into the input[type=file] field as
> below.
>
> driver.findElement(By.id("file-banner")).sendKeys(Keys.DELETE);
> driver.findElement(By.id("file-banner")).sendKeys(pathToFile);
>
>
> But this works only when the form field is visible. While it is hidden,
> Selenium gives the following exception.
>
> org.openqa.selenium.ElementNotVisibleException: Element is not currently
> visible and so may not be interacted with
> Command duration or timeout: 30.07 seconds
> Build info: version: '2.43.0', revision:
> 'accb3003b9fb8f7cae30f9669b4c594a065396a6', time: '2014-09-09 22:22:51'
> System info: host: 'lasanthas-Latitude-E6540', ip: '127.0.1.1', os.name:
> 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version:
> '1.7.0_80'
> Session ID: 4f035f7f-f554-4206-a94c-5b0f79d5d0a5
> Driver info: org.openqa.selenium.firefox.FirefoxDriver
> Capabilities [{platform=LINUX, acceptSslCerts=true,
> javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true,
> browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true,
> webStorageEnabled=true, nativeEvents=false, rotatable=false,
> locationContextEnabled=true, applicationCacheEnabled=true,
> takesScreenshot=true, version=28.0}]
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
> 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.RemoteWebElement.execute(RemoteWebElement.java:268)
> at
> org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
> at
> org.wso2.ues.ui.integration.test.dashboard.BannerTest.testCreateDashboard(BannerTest.java:190)
> at
> org.wso2.ues.ui.integration.test.dashboard.BannerTest.testRunner(BannerTest.java:94)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> 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.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:177)
> at
> org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
> at
> org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:105)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> 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:103)
> at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
>
> Can anyone please advice me on a workaround for this?
>
>
>
> Thanks,
>
> *Lasantha Samarakoon* | Software Engineer
> WSO2, Inc.
> #20, Palm Grove, Colombo 03, Sri Lanka
> Mobile: +94 (71) 214 1576
> Email:  [email protected]
> Web:    www.wso2.com
>
> lean . enterprise . middleware
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to