Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
How to upload a file on browserstack with selenium scripts?

Solved 1 Answers 606 Views
0 1
I am using browserstack with selenium. but i am unable to upload any file/image on browserstack. Do let me know how i can upload a file/image on browser stack.

I am using a third party tool name 'AutoIT' on my system to upload any file/image, but it is not working on browserstack. Please help me as soon as possible.

1 Answer

1
Best answer
1

When you execute tests on browser stack, you are actually executing on a remote grid. Everything happens via JSON over HTTP protocol. So, you can you execute any executable file on their remote machine.

AutoIT executes on local machine. For remote machine, you will have to upload file via JavaScript by altering existing elements on the page.

Can you edit this question and update below things?

  • HTML source of the page.
  • Screenshot of the page.
  • And your existing code using which you are uploading the image.
answered by (192 points)
selected by
6Comments
commented by (324 points)
<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="fnApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="fnApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="fnApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="fnApp" class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>FoodNiche</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="/">

    <link rel="shortcut icon" type="image/png" href="/images/favicon.png"/>
    <!-- 3rd css -->
    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/wro/allLibs.css">
    <!-- Our css-->
    <link rel="stylesheet" href="/wro/all.css">
    <link href="https://vjs.zencdn.net/5.4.4/video-js.css" rel="stylesheet">

    <!-- Google analytics -->
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
              (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

        ga('create', 'UA-71082601-1', 'auto');
        ga('send', 'pageview');

    </script>
    <script type="text/javascript">
      _atrk_opts = { atrk_acct:"mFGjo1IW18106C", domain:"foodniche.me",dynamic: true};
      (function() { var as = document.createElement('script'); as.type = 'text/javascript'; as.async = true; as.src = "https://d31qbv1cthcecs.cloudfront.net/atrk.js"; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(as, s); })();
    </script>
    <noscript><img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=mFGjo1IW18106C" style="display:none" height="1" width="1" alt="" /></noscript>
</head>
<body>

<div growl></div>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div fn-header></div>
<ui-view></ui-view>
<div fn-footer></div>

<script src="/wro/allLibs.js"></script>

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script src="/app/app.jsp"></script>
<script src="/wro/all.js"></script>
<script type="text/javascript" src="/scripts/html2canvas.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCWhvvcHNGEYJRTwunB_5Ar9B3paqu4Tqs&libraries=places"></script>
<script src="https://vjs.zencdn.net/5.4.4/video.js"></script>
</body>
</html>
commented by (324 points)
commented by (192 points)
I see your screenshot. Usually so far we are executing this kind of test cases in local grid where we can have our own executable running. So far browser stack does not support uploading of file and execution of file in their VM. Even if you could figure out JavaScript which takes file to upload. It will be very tedious to upload file to VM. So, test case like this has to be executed on local machine or local grid.

Hope that answers your question.
commented by (324 points)
Thank you sir for such a good information.
Please can you tell me, how i can use javaScript to upload the file?
commented by (324 points)
edited by
Hi Sir, i found the solution for this problem.

((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        Thread.sleep(2000);
        driver.findElement(By.xpath(".//*[@id='content']/div[2]/div/div[2]/div/div/form/div/div/div[3]/div[1]/input")).sendKeys("file\\path");
commented by (192 points)
Thank you for posting your solution. You can not really use JavaScript to upload file. Uploading of file is prevented to avoid possible hacking on the computer.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...