0

I get up to a certain point in a desktop app that I'm automating and I need to click a link and continue automating in a browser. The link automatically goes to internet explorer.(suggestions on how to copy and paste that into chrome would be appreciated). I need to know how to switch from the desktop to the webview, automate the web view and go back to the desktop view.

So far this is the closest thing I've found that solves the problem. I'm newer to c# so I know the theory of what I'd like to do, just not how to implement it. http://appium.io/docs/en/writing-running-appium/web/hybrid/. I've got so far as to log the context to my output. I haven't been able to set or reset it yet.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;

namespace UnitTestProject2
{
    [TestClass]
    public class GoldTrakPCTest
    {
        [TestMethod]
        public void TestMethod1()
        { 
            AppiumOptions options = new AppiumOptions();
            options.AddAdditionalCapability("deviceName", "WindowsPC");
            options.AddAdditionalCapability("platformName", "Windows");
            options.AddAdditionalCapability("app", "XXXX -Path to desktop app");
            WindowsDriver<WindowsElement> windowsDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/"), options);
            Thread.Sleep(1500);
            windowsDriver.FindElementByAccessibilityId("1006").SendKeys("Username");
            windowsDriver.FindElementByAccessibilityId("1003").SendKeys("Password");
            windowsDriver.FindElementByAccessibilityId("1001").SendKeys("354 - B - Mariner");
            windowsDriver.FindElementByAccessibilityId("1").Click();
            var myVar = windowsDriver.FindElementByAccessibilityId("59393");
            Thread.Sleep(4200);
            //Trace.WriteLine(windowsDriver.FindElementByName("WILLY WONKA"));
            windowsDriver.FindElementByName("WILLY WONKA").Click();
            Thread.Sleep(1000);
            windowsDriver.FindElementByAccessibilityId("1310").Click();
            Thread.Sleep(4000);
            windowsDriver.FindElementByName("Documents").Click();
            Thread.Sleep(4000);
            windowsDriver.FindElementByAccessibilityId("1011").Click();
            windowsDriver.FindElementByAccessibilityId("1011").Click();
            windowsDriver.FindElementByName("Doc Set - WI Esign Documents").Click();
            windowsDriver.FindElementByAccessibilityId("4750").Click();
            Thread.Sleep(4000);
            windowsDriver.FindElementByName("OK").Click();
            windowsDriver.FindElementByAccessibilityId("2034").Click();
            Thread.Sleep(4000);
            string Context = windowsDriver.Context;
            Trace.WriteLine(Context);
            /*List<string> AllContexts = new List<string>();
            foreach (var context in (windowsDriver.Contexts))
            {
                AllContexts.Add(context);
                Trace.WriteLine(context);
            }*/
            //Trace.WriteLine(AllContexts, "Hello");
            //options.AddAdditionalCapability("")
            //windowsDriver.FindElementByName("WILLY WONKA").Click();
            //windowsDriver.FindElementByName("Next").Click();



            Thread.Sleep(6000);

            //windowsDriver.Close();
        }
    }
}

I need to know how to change context and if it's possible to switch between native windows desktop apps and browsers and how to do this.

Jackson
  • 51
  • 9

1 Answers1

0

It is possible. I have 2 desktop application and 1 web application all running in tandem. However, I have one question regarding "The link automatically goes to internet explorer.(suggestions on how to copy and paste that into chrome would be appreciated)."

is it because Internet Explorer is the default explorer in windows?

Switching context between apps.

As soon as u click the windowselement that opens Web (IE or chrome), you'll need to create Webdriver instance (IE/chrome)and attach it to the browser process

A test initialize method which launches/attaches to an existing session : How to use/attach an existing browser using Selenium?

Avinash
  • 188
  • 5
  • Thank you. It's not the OS's default browser. It's the only link that will work for the application I'm testing. – Jackson Jun 14 '19 at 14:27