Appium - Close one iOS application and reopen another application - appium

I have the following scenario to be automated. How this could be achieved through Appium.
1. Launch my application register a user with an gmail id.
2. Close the application.
3. Launch Safari browser and navigate to gmail login
4. Click on the registration link.
Here, challenging part is point number 2 and 3.
Can Appium session be disconnected?
Can Appium start a new session for a pre installed application like Safari?

You can just use the same appium server instance. No need to kill the server, but you will want to probably use two different driver instances.
AppiumDriverLocalService service;
IOSDriver iosDriver;
public void setUp() throws IOException {
service = AppiumDriverLocalService.buildDefaultService();
service.start();
}
public void startMyApplication(){
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");
dc.setCapability(MobileCapabilityType.UDID, "3838n838fn38jf8n838ffabcdefg");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
dc.setCapability(MobileCapabilityType.APP, "com.your_package.name");
iosDriver = new IOSDriver("http://localhost:4723/wd/hub", dc);
}
public void testMyGoogleLoginOnMyApplication(){
//I intend to do something here
//Once i am finished, I close my application
iosDriver.quit();
}
public void startSafari(){
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");
dc.setCapability(MobileCapabilityType.UDID, "3838n838fn38jf8n838ffabcdefg");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
dc.setCapability(MobileCapabilityType.APP, "com.safari_package.name");
iosDriver = new IOSDriver("http://localhost:4723/wd/hub", dc);
}
public void testSafari(){
//I intend to go to google and do stuff
//Once i am finished, I close my application
iosDriver.quit();
}
public void finished(){
service.stop();
}

Just came across a solution that works for all iOS versions and Xcode versions:
driver.background_app(-1)
From the springboard, find the Icon and click it!

Related

How to Switching between two native apps using appium

I would like to switch between two apps without loosing the previous state of the application. How can we achieve this using appium.
Scenario:
1. Launch any application which requires OTP to login ( Ex:filpkart)
2. Launch SMS application and read the OTP
3. Close SMS application and Switch back to first app and enter OTP which we read it from SMS application.
Could some one help me on this.
Regards,
Shiva Oleti
Well if you want to send an app in background then simply use driver.CloseApp() function and relaunch it by driver.OpenApp()
You can also use press keycode method Below are the codes
Home Menu Button - 82
Back Button - 4
Recent app - 187
and then perform the getOTP activity from message then switch back to main app
Step1:- Launch app normally passing all the desired capabilities(For e.g Flipkart app)
Step2):- perform action to get OTP
Step3):- Once OTP received try to pass th AppPacakge and AppActivity of the messaging app where you get otp to below method(you get app pacakage and activity by adb shell command)
public String startNewAndroidActivity(String AppPacakge, String AppActivity) throws
Exception{
String actvty = null;
Activity activity = new Activity(AppPacakge, AppActivity);
activity.setAppWaitPackage(AppPacakge);
activity.setAppWaitActivity(AppActivity);
activity.setStopApp(false);
try {
((AndroidDriver<MobileElement>) driver).startActivity(activity);
Thread.sleep(1000);
actvty = ((StartsActivity) driver).currentActivity();
System.out.println(actvty);
}
catch (Exception e) {
System.out.println("Error occured while starting new Activity
"+e.getMessage());
e.printStackTrace();
}
return actvty;
}
Step4). Once message(OTP) is read close the message application by below method.
public boolean closeApplication() throws Exception {
boolean flag = false;
if(driver!=null) {
driver.closeApp();
flag = true;
}
return flag;
}
Step5). Once this is close find the Xpath of the field where you need to copy the otp. Paste it and go ahead.
P.S:- This work well with Android app.
Updated
For that you need to define two AppiumServer with different port, two AppiumDriver (one for sms app and another for another app).
Start appium driver with 2 different port eg: 4723 and 4724. Define 2 drivers:
public static AppiumDriver<MobileElement> driver1;
public static AppiumDriver<MobileElement> smsDriver;
Define DesiredCapabilities for both app and initialize both driver.
First open and do Login.
public void startApp1(){
DesiredCapabilities cap1 = new DesiredCapabilities();
cap1.setCapability(MobileCapabilityType.NO_RESET, true);
cap1.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
cap1.setCapability(MobileCapabilityType.DEVICE_NAME, "android device");
cap1.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap1.setCapability("appPackage", "your app1 package name");
cap1.setCapability("appActivity", "your app1 package name");
cap1.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
driver1 = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
}
After that start sms and perform the action
public void startApp2(){
DesiredCapabilities cap2 = new DesiredCapabilities();
cap2.setCapability(MobileCapabilityType.NO_RESET, true);
cap2.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
cap2.setCapability(MobileCapabilityType.DEVICE_NAME, "android device");
cap2.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap2.setCapability("appPackage", "your app1 package name");
cap2.setCapability("appActivity", "your app1 package name");
cap2.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
smsDriver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4724/wd/hub"), caps);
}
Now to switch from app1 to app2 you can use call startApp2 method. Now if you want to switch back again to switch to app1. Use:
driver1.activateApp(appPackage of app1);
now if you again want to switch to app2 use:
driver2.activateApp(appPackage of 2nd app);

tcpListener on Win 10 iOT not working

I have a UWA on RPi 3 with Win 10 version 10.0.14393.0 and VS 2015 Update 3. I'm trying to run a TCPListener on my RPi, code runs with no exception but never can connect it, seems that some things block my connection. there is no hardware or software Firewall in path. I tried both background and foreground app but no result.
My code is as below :
namespace TestBackPort
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
TcpListener tcpListener = null;
tcpListener = new TcpListener(IPAddress.Parse("192.168.1.9"), 1100);
tcpListener.Start();
var task = HandleConnectionsAsync(tcpListener);
task.Wait();
}
int connectionNumber = 0;
async Task HandleConnectionsAsync(TcpListener listener)
{
while (true)
{
var client = await listener.AcceptTcpClientAsync();
// Console.WriteLine("OK #" + connectionNumber);
connectionNumber++;
}
}
}
}
First of all, check your network state using "netstat" utility.
Connect to your raspberry pi using putty or powershell
Do "netstate -a" to verify that the TCP server is actually listening on that port.
When you have your server running, you should see something similar to below
Secondly, make sure you have the Internet Server capability enabled in the project manifest file. It could be either the Internet or the Private Networks, like below.

Message hangs (timeout) when sending from Azure Web App to Azure IoT Hub Devices

Below I present a part of an Azure Web App that handles a device notification logic. What I'm doing is invoking the code shown below from a ASP MVC Controller.
But when I run it I get an hung (ever-pending) request from the browser.
I thought I've found a workaround by wrapping the SendAsync call in a BackgroundWorker thread. It's better, but I doesn't work right. For first couple of times (one or two) it works ok, but then it happens again, the wrapped thread hangs.
The code is not far different from the one on MSDN for a console application. What am I missing?
using System.Web.Configuration;
using Microsoft.Azure.Devices;
namespace MyTest
{
public class Sender
{
private readonly string connectionString;
private readonly Microsoft.Azure.Devices.ServiceClient serviceClient;
public Sender()
{
connectionString = WebConfigurationManager.AppSettings["ConnectionString"];
serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
}
public async void SendRequest(string deviceId, string msgText)
{
var message = new Message();
message.Properties.Add("text", msgText));
await serviceClient.SendAsync(deviceId, message);
}
}
}
The problem was caused by inappropriate usage of ASP MVC framework.
It turned out that AsyncController has to be used instead of just Controller when a long running async\await is utilized. The pipeline must be async all the way.

No wifi connection blackberry simulator

I want to download data using HttpConnection , see the example below
class ConnectionThread extends Thread
{
public void run()
{
try{
showToast("in the run method");
HttpConnection conn = null;
String URL = "http://xxxxxxx.com/api/api.php?func=showAllCountries;interface=wifi";
conn = (HttpConnection)Connector.open(URL);
}catch(Exception e){
showToast(e+"");
}
}
while running above code , on simulator it says Java.io.IOException No Wi-Fi connection found , Though in manage connection i can see simultor is conncted with Wifi ,
please why this is happening
Please
use deviceside= false;
in simulator wifi is not possible, simulator will access your system network , once you are on real device wifi will work if it is enabled in device.
Follow this link on how to make connections.

Using a WISON OR200 in web application ( MVC )

Few days ago i bought a WISON OR200 sensor for a web system that i am developing.
I used the SDK that sent to me the enterprise and was been testing in a window application and worked fine but i need it into a web application and i don´t know how to do it..
this is the windows form application:
WisSensorN WisObj = new WisSensorN(); // instance of wison object
objects in form:
private System.Windows.Forms.Button Enroll;
private System.Windows.Forms.Button Identify;
private System.Windows.Forms.PictureBox FingerPic;
private System.Windows.Forms.Button Stop;
private System.Windows.Forms.TextBox Status;
Load method() //Open() .DataEvent and SetDisplay are needed for the fingerprint
private void Form1_Load(object sender, EventArgs e)
{
WisObj.Open();
WisObj.DataEvent += new _IWisSensorNEvents_DataEventEventHandler(WisObj_DataEvent);
WisObj.SetDisplay((int)FingerPic.Handle);
// i can´t do WisObj.SetDisplay((int)FingerPic.Handle) on mvc web app
// because i can't get FingerPic object from view.
}
private void WisObj_DataEvent(WisSensorNLibLib.DATA data, string str)
{
switch (data)
{
case DATA.DATA_ENROLL:
// save the base 64 string of finger image
break;
case DATA.DATA_IDENTIFY_CAPTURE:
//validation
break;
case DATA.DATA_VERIFY_CAPTURE:
break;
}
}
private void Enroll_Click(object sender, EventArgs e)
{
WisObj.StartEnroll(); // it used for save the fingerprint
}
private void Identify_Click(object sender, EventArgs e)
{
WisObj.IdentifyCapture();
// it used to activate the sensor. When i did this on controller action,
// nothing happen. This is because the property setDisplay was not set
}
Any suggestions?
What can i do?
I asked to the company where i bought the fingerprint reader if have a SDK for web applications and never answered.
Help please!
Thnxs!
I think you are on a very wrong path. You can't simply use a device from a browser. The HTML/javascript 'application' that runs in the browser cannot connect to any local resource like I/O ports or Windows events. You will need special techniques, like ActiveX or Java applet to communicate with a device on a client machine.
Whether your website is MVC or plain ASP.NET or even PHP is irrelevant. If you don't know what ActiveX (and alumni) is used for and what drawbacks it has, you should look for a professional who can help you explain the situation and possibly develop a suitable solution.

Resources