3

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...

4

3 回答 3

4

带有摩卡咖啡的 Spectron 应该更快。

但这里仍然是您需要的。这是 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);  

我已将打包的电子应用程序用于二进制(即)app.exe

我认为这就是你所需要的。

于 2018-07-05T08:34:47.190 回答
0

试试这个进行电子应用程序初始化:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;

namespace Selenium_Demo
{
    class Selenium_Demo
    {

        IWebDriver driver;

        [SetUp]
        public void Start_Browser()
        {

            ChromeOptions options = new ChromeOptions();
            ChromeDriverService chromeService = ChromeDriverService.CreateDefaultService(@"C:\\selenium\\chromedriver_win32v\\chromedriver.exe",
         @"C:\\Program Files\\Cerebrata\\Cerebrata.exe");

            driver = new ChromeDriver(chromeService, options);
        }

        [Test]
        public void Test()
        {
            System.Threading.Thread.Sleep(6000);

            Console.WriteLine("Test Passed");
        }

        [TearDown]
        public void Close_Browser()
        {
            driver.Quit();
        }
    }
}
于 2021-10-21T05:04:17.207 回答
0

下面的描述与使用 .Net C# OpenQA.Selenium 的 Electron 有关。

如果要运行正在开发的电子应用程序(由文件 index.html、main.js 等组成),您必须添加以下选项(注意cmd 参数中的 ' app= '):

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

但是如果你想运行打包的电子应用程序(*.exe),使用它就足够了:

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

您也可以启动任何版本的chromedriver.exe

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

这可能会有所帮助,因为我知道不同的电子应用程序是基于使用不同版本的驱动程序而构建的。

于 2021-07-01T11:47:24.677 回答