Can you automate ui based web app with appium? - user-interface

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

Related

How to switch context from Native App to Web App in Appium

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);
}
}

Can Xamarin apps use App Live Local Testing on BrowserStack

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.

Is there any better way to Launch UWP apps from Console application

I tried to launch the UWP application from c# console application. It tried with below code which uses APPID
Process.Start(#"C:\Program Files (x86)\Windows Kits\10\App Certification Kit\microsoft.windows.softwarelogo.appxlauncher.exe", "1a75- 6f75 - 5ed3 - 8944 - 6b7df2bee095");
Is there any better way to launch UWP application programatically.
To launch any UWP app on the system you can use the following API:
AppListEntry.LaunchAsync Method
To get the AppListEntry for the desired application, use the PackageManager APIs:
PackageManager.FindPackageForUser(String, String) Method
Package.GetAppListEntriesAsync Method
Alternatively, you can use the following Win32 API insteadp of the AppListEntry API:
IApplicationActivationManager::ActivateApplication method
And when your console application is written in some exotic languages, for example Java, you can do something like
https://www.c-sharpcorner.com/article/launch-uwp-app-via-commandline/
For better results do omit these two attributes:
<!-- Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$"-->
Then carry on as described here.
I tried to launch the UWP app through Protocol. The below link will help how to create a protocol
Automate launching Windows 10 UWP apps
Now you can launch your application by using
Process.Start("URL:myapplication://");
The process class is available in System.Diagnostics. And also need to add the following method in App.xaml.cs file
protected override void OnActivated(IActivatedEventArgs args)
{
Initialize(args);
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
// Always navigate for a protocol launch
rootFrame.Navigate(typeof(MainPage), eventArgs.Uri.AbsoluteUri);
// Ensure the current window is active
Window.Current.Activate();
}
}

Logging via TraceSource in Xamarin (UWP)

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();
}

Change Parse Application when App is running

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");
}
}

Resources