I am currently developing a Selenium script to automate testing of a Chrome app that relies on the Chrome.fileSystem.chooseEntry API for selecting a directory. Interestingly, manual selection using this API works perfectly fine. However, when I attempt to do the same operation within my Selenium script, an error is thrown:
Unchecked runtime.lastError while running fileSystem.chooseEntry: Invalid calling page. This function can't be called from a background page.
Has anyone encountered similar issues with Selenium and chooseEntry integration, and if so, how did you resolve them?
Despite updating to the latest Chromedriver and exploring potential solutions like ChromeOptions, I have yet to find a resolution. I've noticed a lack of information online regarding using Selenium in conjunction with chooseEntry, adding to the complexity of solving this problem. For context, I am working with Chrome version 51.
At this point, I'm considering implementing a custom javascript entry point to manage path values during testing instead of relying on chooseEntry. However, I would prefer avoiding divergent code paths exclusively for testing purposes. If anyone has a more streamlined approach, please share your insights.
To provide further context based on a request, I am sharing the snippet of code causing the issue:
chrome.fileSystem.chooseEntry({type:'openDirectory'},function(entry) {
chrome.fileSystem.getWritableEntry(entry,function(writeable_entry) {
console.log("got writeable entry");
});
}, function(e) { errorHandler(e); });
Update: I have decided to implement a workaround by introducing a special javascript entry point. In essence, outside of Selenium automation, I manually execute code invoking chooseEntry and utilize the retainEntry API to retrieve the entry id. Subsequently, I redefine my codebase to reference this entry object rather than triggering chooseEntry afresh. Additionally, I have adjusted my Selenium script to invoke the restoreEntry entry point ahead of continuing script execution.
While this solution introduces discrepancies between test code execution and standard operational flow, it enables me to effectively run Selenium scripts. Nonetheless, if anyone can propose a more elegant resolution, I welcome your suggestions.
Correction: Following feedback from @Xan, I have amended my terminology from "extension" to "Chrome App."