How I can get real img file name by src in Selenium? - selenium-webdriver

Using LogoImg.GetAttribute("src") I get the following scr:
https://scol.stage-next.sc.local/lspprofile/5a2e7338d6e9a927741175e2/image?id=5a2fbc98d6e9a9177c8c1592
But the real name of the file is: TestImage - 9fb0c49d-69b1-49ed-8c63-4283e405b781.jpg
If i enter the src in my browser i got the file with real name downloaded.
How can I get the real name of the file in selenium as I need it for test.
Well the task is solved by other means, i just compared the differences in src. But the responce to the question would be yet interesting.

As you are able to retrieve the src attribute as follows :
https://scol.stage-next.sc.local/lspprofile/5a2e7338d6e9a927741175e2/image?id=5a2fbc98d6e9a9177c8c1592
This is the reference to the resource stored in the Database. So it wouldn't be possible to retrive the name 9fb0c49d-69b1-49ed-8c63-4283e405b781.jpg before the file gets downloaded.
To ensure the download is completed and then to read the filename you will need to use either of the following :
glob.glob() or fnmatch :
https://stackoverflow.com/a/4296148/771848
Watchdog module to monitor changes with in a directory:
python selenium, find out when a download has completed?

Related

Drupal upload then move doesn't update path or filename in file list

I have a custom form using a "managed_file" which uploads to temp folder. Programmatically, I then load that file and move it to its permanent storage (overwriting any existing file with the* name) e.g.
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
All of this works (i.e. the file physically is moved into the correct place with correct name); however, the file displayed in the listings (i.e. /admin/content/files) still shows the incorrect temporary folder as the URI.
Basically the file in the listings page seems to be showing the original filepath and name* of a previously successfully moved* file.
If I load this file with incorrect URI, i.e. using the incorrect temp path, the data loads, but then will not have a file info (as it doesn't exist. Also clicking the filename by browser under listings will show page not found and the URL showing the old URL i.e. /system/temporary?file=XYZ.pdf).
If I load this file by correct URI, i.e. using the correct destination path, file not found - same if I go to the path directly in the browser.
It appears the managed file doesn't know it was moved. How to resolve this bug?
The docs for FileSystem::move say "Moves a file to a new location without database changes or hook invocation."
So you are going to need to update the file entity with the new values..
Try this, untested:
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$newFileName = $this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
// Set the new file path on the file entity.
$upfile->setFileUri($newFileName);
// Set the file to permanent if needed.
$upfile->setPermanent();
// Save entity with changes.
$upfile->save();
I did not test this though.
You can check the functions on the file entity in the docs here
It turns out the class based methods do not update the database
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21FileSystem.php/function/FileSystem%3A%3Amove/8.9.x
The procedural version does
https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_move/8.9.x

Access image in local storage

Hi am trying to access image in assets/images/flower.png Am using react-native-fs but I tried different path but no luck. has anyone did this before and succeeded ?
var RNFS = require("react-native-fs");
this.base64RouteImage = await RNFS.readFile(
"../../../assets/images/flower.png",
"base64"
).then();
console.log("64 is " + base64data);
I tried below different path as below
/images/flower.png
app/assets/images/flower.png
/app/assets/images/flower.png
file://app/assets/images/flower.png
./assets/images/flower.png
import Flower from "../../../assets/images/flower.png";
../../../assets/images/flower.png
EDIT 1
I have added permission read/write internal/external permission in android
EDIT 2
I tried
RNFS.DocumentDirectoryPath + "/assets/images/flower.png"
but it says
error: ENOENT: /data/user/0/com.tipll/files/assets/images/flower.png (No such file or directory)
I need to access the images in react-native assets folder app/assets/images/flower.png
Still no luck
EDIT 3
my path reference from my current screen is like ../../../assets/images/flower.png
EDIT 4
EDIT 5
Am trying to access image from app/views/routes/view/Flower.js this Flower.js screen.
Any help will be appreciated.
Thanks in advance
To Access data from internal memory: Filepath "/storage/emulated/0/".
To Access data from external memory(SD-CARD): Filepath "/storage/0000-0000/".
Few questions arise here,
1) How is the SD-CARD name "0000-0000"?
Well, 0000-0000 is Volume Serial Number, it changes every time an SD-CARD is formatted. If you want to regulate it i.e you want to add your own Serial Number, check out this post Change Serial Number.
2) How do you now what your SD-CARD Serial Number is?
You can use file managers in Playstore to know your SD-Cards Serial Number and also explore this discussion.
If you want read from internal storage (of device) try this:
file:///storage/emulated/0/Pictures/flower.jpg
I guess that you want read from a folder in your rn project... You must provide the structure of your project
So try with require('../../../assets/images/flower.png')
or try with absolute path: require('MyApp/app/assets/images/flower.png')

How to check if file got downloaded from browser using selenium2library

Can someone help me How to check if file got downloaded from browser using selenium2library,RobotFramework.In my current test I am able to click the download button and file is getting downloaded but what happens if the file didn't get downloaded eventhough button is clicked. Any sample code is helpful.
In chrome I open the chrome://downloads page and then retrieve the downloaded files list from shadow DOM like this:
const docs = document
.querySelector('downloads-manager')
.shadowRoot.querySelector('#downloads-list')
.getElementsByTagName('downloads-item');
This solution is restrained to chrome, the data also contains information like file path and download date.
Check out this link -
http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html
Also, here's how you can auto-download the file to a particular directory -
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.folderList",2);
profile.SetPreference("browser.download.dir", #"c:\path\to\downloads \folder");
FirefoxDriver driver = new FirefoxDriver(profile);
u can use following python function to download file without showing dialog box.
Also u can set preference for which type of files save file dialog box should not get displayed.
def create_profile():
from selenium import webdriver
fp =webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",'C:/Users/mra001/Downloads/Cambium_Builds')
fp.set_preference("browser.helperApps.neverAsk.saveToDisk",'text/csv/xls')
fp.update_preferences()
return fp.path

Loading uncompressed js file in debug mode

Joomla has a feature where it loads the a minified javascript file and the uncompressed version when the site is in debug mode.
I have named both my files correctly and am include it as follows:
JHtml::_('script', JUri::root() . 'path_to_file/jquery-sortable.js');
When I put the site in debug mode, it does not load the uncompressed file.
However, If I use the following instead, it works fine:
JHtml::_('script', 'path_to_file/jquery-sortable.js');
Now I'm not sure whether this is a bug in Joomla or not, but I cannot find any information online regarding this. I would like to use JURI::root() in the path.
Does anyone have any information on this?
Indeed, if the script URL begins with http, the code that is responsible for including the uncompressed version (i.e, remove the min. segment if such exists or add -uncompressed otherwise) is ignored.
The source for this behavior:
JHtml::includeRelativeFiles() in libraries/cms/html/html.php:298
protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug)
{
// If http is present in filename
if (strpos($file, 'http') === 0)
{
$includes = array($file);
}
else
//process the script sourch.
}
...
}
Most of the script files, including frameworks, are included as relative paths. I guess that this behavior is meant to prevent remote resources from getting 404ed.

Qt SQLite database without absolute path

Is there a way to reference the database.sqlite file without knowing the absolute path?
_db = QSqlDatabase::addDatabase("QSQLITE");
_db.setDatabaseName("/the/path/i/dont/know/database.sqlite");
I already tried to add the database.sqlite to the Resources folder and call it via qrc:, but apparently it is not possible to write to a resource file.
I also tried using QApplication::applicationDirPath();, but this would result in different paths depending on the user's OS. E.g. it appends MyApp.app/Contents/MacOS to the actual directory.
When you create a QSqlDatabase with SQLite as a backend you have two options:
Give an absolute path as a db name
Give a relative path: in this case the database will be saved in the directory of your binary.
So you must know absolute path of your db in your case.
edit
In the case you initially know where the database should be located you can either hardcode it (which is never wise) or you can create a configuration and load it using QSettings. For example:
QSettings settings;
QString dbPath = settings.readValue("DBPath", QString(/*fallback path*/)).toString();
//do smth with dbPath
Take a look further here
if you want to store the db per user you shout use this:
QDesktopServices::storageLocation(QDesktopServices::DataLocation)
this method returns the location where persistent application data can be stored.
for more information check this: http://doc.trolltech.com/4.5/qdesktopservices.html#storageLocation

Resources