Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking selenium with electron framework (c#)

I've already written few lines of code in C# using Selenium webdriver. As my application was transferred to the Electron framework everything has changed and honestly, I don't know how to cope with it right now.

Could you please clarify it to me? What steps should I take to simple start... I would like to continue my work in the current project (selenium, C#), but I'm not sure that it's possible, or I should completely start from scratch using a different language and framework?

I've read about Spectron, and checked the internet resources like stackoverflow, however I'm still in the point of unawareness...

like image 615
Ixi11 Avatar asked Aug 25 '26 18:08

Ixi11


2 Answers

Spectron with mocha is supposed to be faster.

But still here is what you need.This is Java & Selenium.

System.setProperty("webdriver.chrome.driver","C:\\electron-chromedriver\\bin\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Users\\app.exe");
chromeOptions.addArguments("start-maximized");
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capability.setCapability("chromeOptions", chromeOptions);       
driver = new ChromeDriver(chromeOptions);  

I have used the packaged electron app for binary (i.e) app.exe .

I think this is what you need.

like image 72
Bharath Kumar S Avatar answered Aug 28 '26 07:08

Bharath Kumar S


Described below is related to using of Electron with .Net C# OpenQA.Selenium.

If you want to run electron app which being developed (consists of files index.html, main.js, etc.) you have to add following options (pay attention to 'app=' in cmd argument):

var options = new ChromeOptions();
options.BinaryLocation = @"your_path_to_electron\electron.exe";
options.AddArgument(@" app=path_to_folder_with_your_electron_app_src");

But if you want to run packaged electron app (*.exe) it is enough to use:

var options = new ChromeOptions();
options.BinaryLocation = @"path_to_folder_with_your_electron_app\your_electron_app.exe";

Also you can start any version of chromedriver.exe:

var service = ChromeDriverService.CreateDefaultService(path_to_folder_with_driver);
var driver = new ChromeDriver(service, options);

It might be helpful because I know that different electron applications are built on using of different version's drivers.

like image 36
Ivan Avatar answered Aug 28 '26 07:08

Ivan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!