The file ChromeDriver does not exist when running on Docker - c#

I'm trying to run Selenium on Docker using Azure Function in C#. I've installed Selenium.WebDriver and Selenium.WebDriver.ChromeDriver nuget packages. In docker file I've also put code for installing Chrome driver, but when I try to create ChromeDriver in code, I get exception that chromedriver can't be found.
When I list all files in directory, I can see that there is chromedriver.exe file listed:
but when I try to create a new Chrome driver using this line:
IWebDriver driver = new ChromeDriver(Environment.CurrentDirectory);
I get the following exception:
The file /home/site/wwwroot/bin/Debug/netcoreapp3.1/chromedriver does
not exist. The driver can be downloaded at
http://chromedriver.storage.googleapis.com/index.html.
Why chromedriver.exe file is not recognized? When I run the same code without Docker, everything works fine.

Add the absolute path of chromedriver.exe to container PATH environment variable

Typically Windows executables end with .exe while Linux executables have no file extension. A file being executable on Linux is a consequence of file permissions rather than some naming convention.
The file path in the exception message uses forward-slashes / as file path delimiters rather than back slashes \ leading me to believe you have downloaded a Windows-compatible ChromeDriver which you are attempting to run on a Linux machine.
Solution: download the Linux driver instead when deployed via Docker.

Related

Dotnet: Works in VSCode's OWN TERMINAL, but OMNISHARP: 'dotnet.exe' is not recognized

How is this possible?
I installed .net sdk 6.0.405: dotnet-sdk-6.0.405-win-x64.exe
I can in windows terminal and power shell run: dotnet --version: 6.0.405 ✅
I CAN ALSO IN VSCODE IN ITS BUILTIN TERMINAL, run: dotnet --version: 6.0.405 ✅✅
But in the OUTPUT tab, choosing OmniSharp Log from the dropdown, it says:
[ERROR] A .NET 6 SDK for x86_64 was not found. Please install the latest x86_64 SDK from ...
I switched vscode explorer settings to use external terminal.
And this terminal setting to command prompt:
Terminal › Integrated › Default Profile: Windows
The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.
I have dotnet in the PATH (and it works in terminals and in vscode's terminal)
I restarted vscode, AND REINSTALLED the dotnettools "C# for Visual Studio Code (powered by OmniSharp)" extension. I went to the online store and from the right column under Resources I downloaded the ms-dotnettools.csharp-1.25.2#win32-x64.vsix to make sure I get the right one. And restarted vscode.
I tried this setting:
Omnisharp: Dotnet Path
Specified the path to a dotnet installation to use when "useModernNet" is set to true, instead of the default system one. This only influences the dotnet installation to use for hosting Omnisharp itself. Example: "/home/username/mycustomdotnetdirectory".
C:/Program Files/dotnet/sdk/6.0.405
And this setting:
Omnisharp: Sdk Path
Specifies the path to a .NET SDK installation to use for project loading instead of the highest version installed. Applies when "useModernNet" is set to true. Example: /home/username/dotnet/sdks/6.0.300.
C:/Program Files/dotnet/sdk/6.0.405
And restarted vscode. And now it says:
[ERROR] Error: Command failed: dotnet.exe --version
'dotnet.exe' is not recognized as an internal or external command,
operable program or batch file.
What? W H A T? lol
What could be wrong? Why isn't it saying where it expected to find it and what to do to locate it? Is there a setting to specify the dotnet.exe path to this C# extension? Does it need always-on internet or something? Does it have DRM? Does it need Edge installed? Wtf?🙂
🙃😭 I just need intellisense; and I've wasted 2h, on only microsoft-owned products.
#Microsoft 0/5 stars
Still don't know why it happens, but here's how to solve it:
The problem was from this: I like to keep all my visual studio code extensions as .vsix files locally in folders so I can remember and get them easily & offline. Sensible enough choice, and I had the correct ms-dotnettools.csharp-1.25.2#win32-x64.vsix for my platform.
But in VSCode, when I install this particular extension via VSIX, even though it succeeds, it can't find .net. If you instead install the extension "normally", ie via vscode's own download, it seems vscode does some extra configuration steps while installing, and probably sets the .net paths correctly or something. Because now it works.
So TL;DR: don't install ms-dotnettools.csharp via vsix, it seems bugged. 😶
Would love to see an answer explaining what's wrong / how to actually do via vsix; but I don't have any more time to debug this rn.

Android_Home issue on MAC

I have set the ANDROID_HOME environment variable on my MAC but still getting an error says:
The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.[ADB] Error: Could not find adb Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
I have used the following commands in the Mac's terminal:
MacBook-Pro:~ seleniumMac$ export ANDROID_HOME=/Users/seleniumMX/Library/Android/sdk
MacBook-Pro:~ seleniumMac$ export PATH=$PATH:$ANDROID_HOME/tools
MacBook-Pro:~ seleniumMac$ export PATH=$PATH:$ANDROID_HOME/platform-tools
MacBook-Pro:~ seleniumMac$ export PATH=$PATH:$ANDROID_HOME/build-tools
Run the following commands after installing brew
brew tap caskroom/cask
and install android-sdk using
brew cask install android-sdk
Now copy the below to your ./bash_profile and save/source it.
export ANDROID_HOME=/usr/local/Caskroom/android-sdk/
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
Open a new terminal!

OpenQASeleniumWebDriver fails to start socket at 45000ms

I am new to Selenium and Web Driver and I have come across the following when using FireFox:
"OpenQA.Selenim.WebDriver Exception: Failed to start up socket within 45000ms. Attempted to connect to address 127.0.0.1.7055"
My Selenium Driver is version 2.53.1.0 and Firefox version is 48.0.1
I am only trying to open a page and type the google url just to make sure that my code works in Visual Studio 2015.
Any help would be much appreciated.
Thanks,
Tasos
I would like to write a few more details about the solution in case another stack overflow user comes across the same issue. The following steps worked for me:
1.Followed the link that Saurabh mentioned & downloaded the geckodriver exe file from https://github.com/mozilla/geckodriver/releases
2.Renamed the file from 'geckodriver' to 'wires'
3.Put the file at the Bin > Debug folder of my Visual Studio Unit Test project
4.Added the following lines of code in the cs file of my project:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service);

Selenium 2.53.1 does not work on FireFox 48

I am using selenium to test our websites. When I build the project, there is an Exception :-
OpenQA.Selenium.WebDriverException: Failed to start up
socket within 45000 milliseconds. Attempted to connect to the
following addresses: 127.0.0.1:7055 and the problem is from the code
IWebDriver driver = new FirefoxDriver();
Anybody knows how to solve this problem?
Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable that will run alongside the browser.
You can download the latest executable geckodriver from here
Add downloaded executable geckodriver to system path
The Selenium client bindings will try to locate the geckodriver (or wires) executable from the system path. You will need to add the directory containing the executable to the system path.
On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
On Windows you need to update the Path system variable to add the full directory path to the executable geckodriver. The principle is the same as on Unix.
After all above stuff you need to Initialize FireFoxDriver as below :-
var driver = new FirefoxDriver(new FirefoxOptions());
Note :- Follow this link for the solution of this problem with other programming language.
This answer didn't worked with me. Running selenium 2.53.6 and firefox 47 n 48.
I would recommend downloading firefox 46 which seems to be the best match for selenium 2.53.x.
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
Once I downgraded to firefox 46.0.1 everything was working as expected.

Can't find initialization file gs_init.ps

I have a .net windows form application that uses ghostscript. Only on 1 machine do i get an error message. On all others (100s) it works find. This is in a Citrix environment.
The error is "AFPL Ghostscript 8.53: Can't find initialization file gs_init.ps"
I have checked and the file does exist.
I've had a similar problem when compiling a latex file on OSx (pdflatex *.tex).
The problem arose because of gs installed by MacTeX.
The command pdflatex was using the command gs installed by MacTex and not the one installed by brew.
I fixed the problem by running the following command brew link --overwrite ghostscript
I've had a similar problem when calling the GS dll from a Delphi application; I solved it by setting the environment variable.
From the documentation: Ghostscript tries directories in this order:
The current directory (unless disabled by the -P- switch);
The directories specified by -I switches in the command line, if any;
The directories specified by the GS_LIB environment variable, if any.

Categories