We are Unable to switch context from Native app to Web app.
Kindly suggest us a way to achieve this
You can use this
Set contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains(“WEBVIEW”)){
driver.context(contextName);
}
}
Related
I have to automate an UI of web application. I also need to automate an UI in mobile. Does Appium supports both the platform ???
Anyone with knowledge of Appium can comment down below.
Yes, Appium works perfectly fine for hybrid (native + web) mobile apps:
// assuming we have a set of capabilities
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1
//do some web testing
String myText = driver.findElement(By.cssSelector(".green_button")).click();
driver.context("NATIVE_APP");
// do more native testing if we want
driver.quit();
More details are available in docs
I've developed a cross platform mobile app with Xamarin.Forms. I have local services that my app hits. My Xamarin app defines the HTTPClient as shown below. When testing on BrowserStack's App Live product I can not hit my local services from my app using the BrowserStack Local app (I receive a "No Such Host Is Known" response) . I can hit my services using the device's default browser.
HTTPClient setup in Xamarin App:
public static readonly HttpClient client = new HttpClient()
My local services have internal domain names (it's not simply 'localhost:443' but it actually has a domain name like 'customservice.com')
Is it possible for a Xamarin App to use the BrowserStack App Live product while using Local Testing? If so, how?
I found a solution that works for Android and should work for iOS (but doesn't). Maybe with some tinkering it could work for iOS too, but I thought I'd share what I found:
Step 1: Create a Dependency Service
This step is loosely based on this article. The article is incomplete because it does not create a dependency service. So that's fun
In the Shared Project create a IProxyInfoProvider interface as shown:
public interface IProxyInfoProvider
{
WebProxy GetProxySettings();
}
Create the platform implementations:
(Don't forget to add the assembly tag above your namespace to export the Dependency Service!)
iOS
public class ProxyInfoProvider : IProxyInfoProvider
{
public WebProxy GetProxySettings()
{
var systemProxySettings = CFNetwork.GetSystemProxySettings();
var proxyPort = systemProxySettings.HTTPPort;
var proxyHost = systemProxySettings.HTTPProxy;
Console.WriteLine("Proxy Port: " + proxyPort.ToString());
Console.WriteLine("Proxy Host: " + Convert.ToInt64(proxyHost));
return !string.IsNullOrEmpty(proxyHost) && proxyPort != 0
? new WebProxy(proxyHost, proxyPort)
: null;
}
}
Android
public class ProxyInfoProvider : IProxyInfoProvider
{
public WebProxy GetProxySettings()
{
var proxyHost = JavaSystem.GetProperty("http.proxyHost");
var proxyPort = JavaSystem.GetProperty("http.proxyPort");
Console.WriteLine("Proxy Host: " + proxyHost);
Console.WriteLine("Proxy Port: " + proxyPort);
return !string.IsNullOrEmpty(proxyHost) && !string.IsNullOrEmpty(proxyPort)
? new WebProxy($"{proxyHost}:{proxyPort}")
: null;
}
}
Step 2: Update your HttpClientHandler
We want to consume the WebProxy that is now being returned from the dependency service. Update your HttpClient handler so it looks something like this:
var _handler = new HttpClientHandler();
_handler.Proxy = DependencyService.Get<IProxyInfoProvider>().GetProxySettings();
Ensure that your HttpClient is consuming this Handler in it's constructor like: new HttpClient(_handler.Value)
Step 3: Upload your app to BrowserStack
Boom. Then Android works with BrowserStack local testing! Why doesn't it work on iOS you ask? Good question. I'm still trying to figure that part out...
What is also weird is that if you use a proxy to debug your app in your local environment, this solution works! But it stops working when you put your app in BrowserStack.
Since you’re able to access your internal domain via their device browser, it seems that your application is not able to route traffic via BrowserStack’s Local Testing infrastructure.
If that is the case, you can reach out to the BrowserStack Support team for further assistance.
I just want to log to console and to a log file, using a standard TraceSource, in my Xamarin app that will run on UWP, Mac OS X, iOS and Android. I'm developing/debugging on UWP.
TraceSource, TraceListener, and TextWriterTraceListener are indeed all available in .Net Standard library, so perhaps I'm setting it up incorrectly? Most places on the Internet insist on setting up trace listeners in an app.config file, but this is not applicable nor possible for Xamarin apps. So here is my logging initialization code, mostly based on an example in Microsoft docs:
private void SetupLogging()
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out, "consoleTraceListener"));
string logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Application.log");
if (!File.Exists(logFilePath)) File.Create(logFilePath);
var logFileTraceListener = new TextWriterTraceListener(logFilePath, "logFileTraceListener");
Trace.Listeners.Add(logFileTraceListener);
Trace.Write("Test");
Trace.TraceInformation("Logging Initialized. Log file location: " + logFilePath);
Trace.Flush();
}
When I run this in a Xamarin UWP app, a file is created but nothing is written to it, nor can I find anything in the Output of the program (there is no ConsoleTraceListener so I'm trying to write a TextWriterTraceListener to Console.Out). Can someone provide a working example for Xamarin? (I haven't tried the Android or iOS apps yet; want to get UWP on the local machine working first.)
The problem is that you passed wrong string parameter to TextWriterTraceListener method. Please try to pass Stream parameter. You could use following code directly. by the way, you'd better use LocalApplicationData SpecialFolder that could be accessed successfully within uwp.
private void SetupLogging()
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out, "consoleTraceListener"));
string logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Application.log");
if (!File.Exists(logFilePath))
{
File.Create(logFilePath);
}
var logFileTraceListener = new TextWriterTraceListener(File.Open(logFilePath,FileMode.Open), "logFileTraceListener");
Trace.Listeners.Add(logFileTraceListener);
Trace.Write("Test");
Trace.TraceInformation("Logging Initialized. Log file location: " + logFilePath);
Trace.Flush();
}
I have an native iOS sample app installed in my iPad and also my sample xamarin.Forms App installed. I want to open native iOS app from Xamarin.forms when clicked on button. I have set URL schema in my native iOS app in info.plist.
How do I open native app from xamarin.forms on click of a button. I already tried
var request = Device.OnPlatform(
string.Format("native app url"),
string.Format("native app url"),
string.Format("native app url"));
Device.OpenUri(new Uri(request));
but its not working.
It's basically how you are doing it.
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Device.OpenUri(new Uri(request));
Be aware that each platform have some requirements in the way to url is configured and parameters are sent.
Let say to get the maps app open in each platform you would use these urls schemes:
// iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
var iOSUrl = string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc);
var androidUrl = string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name);
var winPhoneUrl = $"bingmaps:?cp={loc}&q={name}";
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Also you cannot open any arbitrary app unless you know its Url scheme.
Anyway, if the Device.OpenUri() doesn't fulfill your requirements you are good to create your own implementations using the native APIs.
Please go through the below link and attached photo
Link:-launch-an-app-from-within-another-iphone
I am using below code in xamarin forms
NSUrl request = new NSUrl("Camera://");
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(request.ToString()));
if (!canOpen)
{ Task.FromResult(false); }
else
{
Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(request.ToString())));
}
I have an Android Application that works with locals instalations and I want use it with diferents Parse applications. Each instalation administrator will contract with Parse directly. When app start it will look for the keys for parse.
I wonder how to change the Parse App linkeded in the Android App once this is running
I have tried to call Parse.initialize (context, apllicationId, clientKey) twice but it doesn't work. I have tried the app register in diferent Parse App every time you start the App link with a different Parse App
It´s always linked only with the first application
public void onCreate(final Bundle icicle){
super.onCreate(icicle);
final Context context = this;
setContentView(R.layout.ssa);
getActionBar().hide();
// Getting the global variables
fmGlobalsBean = Utilities.getGlobals(this);
if(!"".equals(fmGlobalsBean.getUrl_server())){
Parse.initialize(contexto, "p4IWkTRc0WTdKkMH6r60hjYzwX1TIXChy8VcDvPb", "KhkcX4G3dqVpRawHyIYfnHAWqj1H2vyhwD3wINlQ");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(fmGlobalsBean.getUrl_server());
}
else
{
Parse.initialize(this, "Y3xgZ58u4Qcn9TrovFqCOe4PBzhURjXooZ3vDKgB", "ealo3nm4wa4lbJ7KrSR2OSf60DZiUjEUjdUJTQzs");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("INITIAL");
}
}