1

Where can i find a good example of testing an excel addin project with custom ribbon elements, using winappdriver.

What i have so far throws an exception:

System.InvalidOperationException An element could not be located on the page using the given search parameters.

I am using latest winappdriver

Code:

private const string ExcelAppId = @"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE";

private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";

DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", ExcelAppId);
            appCapabilities.SetCapability("deviceName", "WindowsPC");
            appCapabilities.SetCapability("platformName", "Windows");

session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

session.FindElementByName("Blank workbook").Click();

4 Answers4

1

I'm working on automated testing of an Excel add-in with WinAppDriver. In my case I started Excel without the splash screen. Supply /e as app parameter to achieve it.

session.SetCapability("appArguments", "/e");

From this point onward, you'll be able to find the "File" menu and "New" menu by name and click them. Add a few seconds of explicit wait and proceed to finding "Blank Workbook" WindowsElement the same way.

I hope this answers your question, post here if more help is needed. I've been experimenting with WinAppDriver for a few months now, also preparing a Udemy course on the subject which is almost ready to publish. It's an interesting toolkit.

Naeem A. Malik
  • 995
  • 4
  • 19
  • Note: The course which I mentioned in my answer above is now published and available on Udemy. If interested, please take a look here: https://www.udemy.com/course/appium-winappdriver-automation-testing/?referralCode=ED22C3A4CE5BB5E22E53 – Naeem A. Malik Jan 16 '20 at 10:17
1

You need to install Appium.WebDriver, Selenium.support, Selenium.webDriver from "Manage Nuget packages" you can use appium code like:

using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;

class Excel
        {
            public void ExcelCase() { 
        WindowsDriver<WindowsElement> driver;
            AppiumOptions desiredcap = new AppiumOptions();
            desiredcap.AddAdditionalCapability("app", @"C:\Program Files\Microsoft Office\Office16\EXCEL.EXE");
                driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredcap);
 driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

                if (driver == null)
                {
                    Console.WriteLine("App not running");
                    return;
                }
    }}

Try this code and comment if you face any issue.

Neh18
  • 152
  • 1
  • 12
0

I prefer to use: session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); instead of Thread.sleep(5).

h__g
  • 84
  • 4
  • Those are different things. One is setting the wait for the client library for all requests the other is simply pausing the test thread. – MikeJ Jun 20 '19 at 14:33
0

Does it even open the excel when you start the test?

If by Name is not working, it doens't work to me sometimes either, you can use the accessibilityId

session.FindElementByAccessibilityId("AIOStartDocument").Click();

or use the keyboard shorcut to open the blank workbook, like this:

session.Keyboard.SendKeys(Keys.Alt + "f" + "l" + Keys.Alt);
  • You can also use this key combination SendKeys($"{Keys.LeftControl}+n");. I've only used this against Excel 2016. – MikeJ Jun 20 '19 at 14:35