目前,我正在对使用电子框架开发的应用程序进行端到端测试。我能够使用selenium打开应用程序,并且能够与表单控件等进行交互。当我打开应用程序时,它以最小化模式打开,我想通过执行按键来强化它 ALT + Space + X 以下是我的代码,它执行时没有任何错误,但没有最大化窗口。
[TestMethod]
public void TestDispneseLogin()
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.BinaryLocation = @"C:\CorumDispense-win32-x64\CorumDispense.exe";
chromeOptions.AddArgument("start-maximized");
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, "Chrome");
capability.SetCapability("chromeOptions", chromeOptions);
IWebDriver driver = new ChromeDriver(chromeOptions);
Thread.Sleep(2000);
//maximize the window
Actions keyAction = new Actions(driver);
keyAction.SendKeys(Keys.Alt);
keyAction.SendKeys(Keys.Space);
keyAction.SendKeys(Convert.ToString('\u0078'));
keyAction.Build().Perform();
//input the text into the patient text box
driver.FindElement(By.Id("patient")).SendKeys("bharat");
}
我也尝试了选项
keyAction.KeyDown(Keys.Alt).KeyDown(Keys.Space).SendKeys(Convert.ToString('\u0078')).Perform();
但它失败并给我以下错误
Test Name: TestDispneseLogin
Test FullName: LightHouseTestScenarios.TestScenarios.ElectronTest.TestDispneseLogin
Test Source: C:\Automation\SeleniumProjects\Lighthouse\LightHouseTestScenarios\TestScenarios\ElectronTest.cs : line 83
Test Outcome: Failed
Test Duration: 0:00:05.1098462
Result StackTrace:
at OpenQA.Selenium.Interactions.Internal.SingleKeyAction..ctor(IKeyboard keyboard, IMouse mouse, ILocatable actionTarget, String key)
at OpenQA.Selenium.Interactions.Actions.KeyDown(IWebElement element, String theKey)
at OpenQA.Selenium.Interactions.Actions.KeyDown(String theKey)
at LightHouseTestScenarios.TestScenarios.ElectronTest.TestDispneseLogin() in C:\Automation\SeleniumProjects\Lighthouse\LightHouseTestScenarios\TestScenarios\ElectronTest.cs:line 99
Result Message:
Test method LightHouseTestScenarios.TestScenarios.ElectronTest.TestDispneseLogin threw exception:
System.ArgumentException: key must be a modifier key (Keys.Shift, Keys.Control, or Keys.Alt)
Parameter name: key
我也试过以下但没有成功
keyAction.SendKeys(Keys.Alt + Keys.Space + Convert.ToString('\u0078')).Perform();
以及此选项
driver.Manage().Window.Maximize();
有人可以提前帮助我解决这个问题。 干杯, 巴拉德瓦。
答案 0 :(得分:0)
当您需要使用电子特征时,简单的方法是使用executeScript方法。
代替:
driver.Manage().Window.Maximize();
替换为:
driver.executeScript("require('electron').remote.BrowserWindow.getFocusedWindow().maximize();");
答案 1 :(得分:0)
试试这段代码..它为我工作......
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("require('electron').remote.BrowserWindow.getFocusedWindow().maximize();");