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.