[SOLVED] How to check if File Exists locally?

Hi people! Ofesad here, new to this beautiful thing of UI.Vision and macros and stuff.

I am currently working doing a major file uploads to a platform. Over 20000 files… and yes, I already talk’d with the admins and they didn’t think of doing a massive uploader… so I have to upload 1 by 1.

Luckly the macro works amazingly well but the one think that I struggle is in the rare cases were the file ain’t found. Most of the cases the file exists and was previously generated, but in rare cases it might not exists (also, I log this cases for further checking later):
Uploading the file:

{
“Command”: “click”,
“Target”: “xpath=//*[@id="importarPlanilla"]/div/div/div[2]/div[1]”,
“Value”: “”
},
{
“Command”: “waitForElementPresent”,
“Target”: “id=file”,
“Value”: “”
},
{
“Command”: “click”,
“Target”: “id=file”,
“Value”: “”
},
{
“Command”: “pause”,
“Target”: “50”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “C:\wamp64\www\pnne\output\2017\jornada2\${globalInsp}\${cue}.xlsx”,
“Value”: “”
},
{
“Command”: “pause”,
“Target”: “50”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “${KEY_ENTER}”,
“Value”: “”
},

The pauses and waits are mostly because I struggled a lot with the site that has a lot of json requests and the only solution was to slow it down a bit.

I was thinking of using something like

{
“Command”: “executeScript”,
“Target”: “var bool = $.get("http://localhost/pnne/output/2017/jornada2/${globalInsp}/${cue}.xlsx\”, function(data, textStatus) { if (textStatus == "success") { return true; } else { return false; } } ); return Boolean(bool);",
“Value”: “archivoexiste”
},

but Chrome gives me errors when trying to access local files, even running on Wamp.

Access to XMLHttpRequest at ‘http://localhost/pnne/output/2017/jornada2/5120/140024400.xlsx’ from origin ‘https://educar.gob.ar’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Anyone had any luck or ideas of how to do this kind of validation?

It’s just to check if the file exists, returning boolean. Nothing fancy.

Thank you all!

Big hug from Argentina and sorry if my english wasn’t very good.

Ofesad

SOLVED:

First:
Install MOESIF CORS plugin on Chrome.

Make a php script that will check if the file exists and return 1 o 0 (true, false).
fileexists.php

$filename = $_GET['name'].".xlsx"; //You dont need the absolute route, can use relative if you place this php file on the root of the directory where the file(s) are.
	IF(file_exists ($filename ))
	{	echo "1";	}
else
{ echo "0"; }

finally on the macro just do an Ajax call:
I try’d using $.get but didn’t work.

  {
      "Command": "store",
      "Target": "http://localhost/exportfiles/fileexists.php?name=findthisfile",
      "Value": "fileexists"
    },
    {
      "Command": "executeScript",
      "Target": "var msg = $.ajax({type: \"GET\", url: ${fileexists}, async: false}).responseText; return Number(msg);",
      "Value": "archivoexiste"
    },
    {
      "Command": "if_v2",
      "Target": "${archivoexiste} == 1",
      "Value": "ifarchivo"
    },

This now saves me a lot of time cause the macro will check if the file exists before doing the upload or even going to the file-loading page.