Is there any possibility to switch from one application to another application at run time using Appium.
Thanks
Finally I found accurate answer, May it will be usefull for some one
source https://www.linkedin.com/grp/post/6669152-6027319885992841219?trk=groups-post-b-title
// App1 capabilities
String calculatorAppPackageName="com.android.calculator2";
String calculatorAppActivityName="com.android.calculator2.Calculator";
// App2 capabilities
String settingsAppPackageName="com.android.settings";
String settingsAppActivityName="com.android.settings.Settings";
#Before
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.215.101:5555");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, calculatorAppPackageName);
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, calculatorAppActivityName);
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testApp() throws InterruptedException, MalformedURLException
{
//Perform calculation in calculator
driver.findElement(By.name("4")).click();
driver.findElement(By.name("×")).click();
driver.findElement(By.name("3")).click();
driver.findElement(By.name("=")).click();
//launch settings App
driver.startActivity(settingsAppPackageName, settingsAppActivityName);
//Switch OFF WIFI
driver.findElement(By.id("com.android.settings:id/switchWidget")).click();
//Re launch calculator App
driver.startActivity(calculatorAppPackageName, calculatorAppActivityName);
//Validate results
String result = driver.findElement(By.className("android.widget.EditText")).getText();
System.out.println("Result : " + result);
Assert.assertEquals("Incorrect Result", "12", result);
}
You can change applications by re-instantiating the webdriver with the new application's attributes.
driver = webdriver.Remote(appiumUrl,dcapabilityApp1)
[Your tests]
driver = webdriver.Remote(appiumUrl,dcapabilityApp2)
[New app tests]
As long as you don't close/disconnect the emulator/simulator/device then your user data will be maintained.
You can use:
driver.startActivity(settingsAppPackageName, settingsAppActivityName);
to invoke another app withing the same code.
Going through question , i have an assumption that it might break your driver current session.and if the driver command failed there is no fall back for it.
Can't it been done with adb command .
One can use above solution or might use abd command
adb shell am start -d <YOUR_ACTIVITY_NAME>
And this will open directly appActivity without fail.
driver.startActivity() method can be used to switch between apps. For more details how it works you can check below video.
Watch "Appium Tutorial- Switching between apps (Contact and SMS)" on YouTube
https://youtu.be/sH1bHeDDj8U
Related
As far as I looked, there's no answered question about QTP's Ext. sdk on stackoverflow (and almost anywhere else on the net; there isn't even a appropriated tag for it...), so I'm aware it's unlikely I get my problem solved by asking , but whatever, it worth trying.
Anyway, before I lose the attention of anyone who never heard or used the Ext. sdk, maybe I will have more luck asking you to help me figure out how to locate the error log file QTP produces at run-time. I know such a file exists in the new UFT 11.5 version, but I couldn't locate it in QTP 10 or 11 (For the record, I don't talk about QTP's Log Tracking feature, but about the "meta" error log of errors/exceptions produced by QTP itself).
Now for the question:
I'm developing an extension for QTP to support native record and run tests on my application.
I'm currently able to import an object repository, and write test steps using The COM object testing agent I developed.
Problem started when I was trying to implement the IRecordable interface; I'm getting the IRecorder object from qtp, and even able to use it as ISuppressor object to exclude redundant steps from being recorded, but all my attempts to record a step (that is, to add new recorded objects to the repository, and add steps to the test) simply failed.
This is the code that I'm using:
public class MyTestingAgent :
AutInterface.ITestable,
AutInterface.IRecordable
{
QTPInterface.IRecorder recorder;
...
public void AutInterface.IRecordable.BeginRecording(object recorder)
{
IRecordSuppressor recordSuppressor = recorder as IRecordSuppressor;
recordSuppressor.Suppress(MyTestingAgentId,
"<Suppress><Item type=\"HWND\" value=\"[#HWND]\" /></Suppress>".Replace("[#HWND]", getMyAppHWND().ToString()));
this.recorder = recorder as QTPInterface.IRecorder;
...
}
public void recordNewObjStep(string parentName, string objName, string method, Object[] arguments)
{
object[] objectHyrarchy = new object[] { findObjectId(objName), findObjectId(parentName) };
string externalParent = null;
string appDescriptionXml = getDescriptionXml(parentName, objName);
try
{
recorder.Record(MyTestingAgentId, objectHyrarchy , appDescriptionXml, externalParent, method, arguments);
Trace.TraceInformation("Record successfully done.");
}
catch (Exception e)
{
Trace.TraceError("TEAAgent.recordSTElement: " + e.ToString());
}
}
...
}
I'm pretty sure all the arguments I send with the call to Record() are accurate. getDescriptionXml() and findObjectId() are used in different cases in the code, and works fine, the method name and argument are correct.
The annoying thing is that the call to Record doesn't even throw exception, and I get "Record successfully done." in the trace log. Needless to say no new object is created in the repository, and no step is added to the test.
As I can't debug QTP, I'm pretty much in the dark with what I'm doing wrong. That's why I'm asking for help with finding QTP's log file, or any other approach that might shed some light on the subject.
For QTP 11 you can turn on the logs by going to QTP's bin directory and running ClientLogs.exe.
Specifically for TEA extensibility do the following.
select the QTP node from the list on the left
find the LogCatPackTEA from the Available Categories list
Click the > button to move it to Selected Categories
Change TEAs level to Debug2 by selecting the category and changing the level
Click OK and run QTP
The logs will show up as QTP.log in the diretory specified in Path:
I'm curious on what the problem you're facing is, please update if you find the cause.
I have a background function listening for push messages. I need to handle though the push. I created the function to take any actions when the push arrives and it works pretty well. For example when a push arrives i increment a number etc etc.
However what would be the code to actually make the application start , when the user presses ok to the push?
I just need to make the application start normally , like the user just pressed on the icon of the app.
I am using OS < 7.X
One typical pattern is to build an application that has two entry points. That is, it can be started in two different ways. One way, would be the normal UiApplication. That's the standard BlackBerry app that can be started with a home screen icon press.
The other way would be to define a background service, that handles push notifications, and is started by the OS as soon as the device boots.
You'll define the background/push entry point by adding an Alternate Entry Point in your app's BlackBerry_App_Descriptor.xml file. Make sure to check Auto-run at Startup and Do not display the application icon .... Your app descriptor xml file should then contain something like this, in addition to the normal entry point for the UiApplication:
<AlternateEntryPoints>
<AlternateEntryPoint Title="PushService" MainMIDletName=""
ArgumentsForMain="-push" HomeScreenPosition="0"
StartupTier="7" IsSystemModule="true"
IsAutostartup="true" hasTitleResource="false"
TitleResourceBundleKey="" TitleResourceBundleName=""
TitleResourceBundleClassName="" TitleResourceBundleRelativePath="">
<Icons/>
<KeywordResources KeywordResourceBundleName="" KeywordResourceBundleRelativePath="" KeywordResourceBundleClassName="" KeywordResourceBundleKey=""/>
</AlternateEntryPoint>
</AlternateEntryPoints>
Then, you'll have a main program like this:
public class MyApp extends UiApplication
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("-push")) {
// this is the push service
PushAgent pa = new PushAgent();
pa.enterEventDispatcher();
} else {
// UiApplication
MyApp app = new MyApp();
app.enterEventDispatcher();
}
}
}
Where PushAgent is a class that extends Application, not UiApplication.
Then, when your push agent receives a notification and you decide you want to show the UI, use something like this:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
ApplicationManager.getApplicationManager().runApplication(ui);
try this -
When you click the ok button use the following code to run your ui application.
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
try {
ApplicationDescriptor[] appDescriptors =CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("BlackBerryCity")); //here BlackBerryCity is the COD module Name
ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[] {"BlackBerryCity"});
ApplicationManager.getApplicationManager().runApplication(appDescriptor);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case Dialog.CANCEL:
break;
default:
break;
}
}
class EntryPointForApplication extends UiApplication {
private static EntryPointForApplication theApp;
public EntryPointForApplication() {
GUIApplication scr = new GUIApplication();
pushScreen(scr);
}
}
Read this also How to setup alternate entry point in Blackberry application?
For sake of completeness here are all the options that you can use to launch an application:
I am assuming that you already have multiple entry points - one for the background listener and one for the UI Application. Also assuming that you are not passing any Application Arguments for the UI App. (See Nate's answer for full description of how to do this.)
Using runApplication() method:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
//Launch the application and ask it to come in foreground
ApplicationManager.getApplicationManager().runApplication(ui, true);
Using launch() method:
String modulename = "mymodule";
ApplicationManager.launch(modulename);
Using launchApplication() method:
String modulename = "mymodule";
ApplicationManager.launchApplication(modulename);
One thing to note is that if your UI app is already open, all these methods will simply bring it to foreground in whatever condition it it. If you require the click of button to open a new instance of your app, you will have to pass some random parameter as the application arguments and then ignore it in the main method.
Am trying to build a window phone 7.1 application where in am getting a username from db to my xaml.cs file through webservice. Now, I need to access that username to scheduledtaskagent(backgroundprocess). am unable to achieve it even if I used PhoneApplicationService.Current.State["username"] to store my variable value.
the following is my code for xaml.cs file:
private void tservice_InsertUserCompleted(object sender, UTservice.InsertUserCompletedEventArgs e)
{
if (e.Result != string.Empty)
{
username = e.Result.ToString();
PhoneApplicationService.Current.State["uname"] = username;
StartPeriodicAgent();
}
}
the below is the code in scheduledtaskagent.cs
protected override void OnInvoke(ScheduledTask task)
{
string uname;
uname = PhoneApplicationService.Current.State["uname"].ToString();
}
am getting a "NullReference" exception in the above statement.
Could someone please let me know the way out to reslove my issue? Thanks in advance.
The PhoneApplicationService.Current.State is local to the process; AFAIK, you cannot pass values to the background agent directly!
You can however, save some info to a file in IsolatedStorage, and when the agent runs read that file contents and use it somehow!
I want to make Blackberry application that can restart the blackberry it self (after doing some task)
for example, i make this little application using the dummy
dummy : (after it becomes dummy.cod, i move it to the res folder and rename it to dummy, not using .cod anymore)
public class Dummy extends Application{
public static void main( String[] args ) {
new Dummy().enterEventDispatcher();
}
public Dummy(){
}
}
application sample code :
(description of my application : just have 1 button to call the reset method)
public void reset() throws Exception {
// load the dummy cod file
byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));
// create new module
int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length);
// install the module
if (newHandle != 0) {
int savecode = CodeModuleManager.saveNewModule(newHandle, true);
if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
// now run the dummy application in background
ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
ApplicationManager.getApplicationManager().runApplication(appDesc, false);
CodeModuleManager.deleteModuleEx(newHandle, true);
}
// restart the blackberry if required
CodeModuleManager.promptForResetIfRequired();
}
When I run my code to Simulator (SimPackage 6.0.0.587 - 9780 & SimPackage 5.0.0.977 - 9300) the code was running well, it shows a message to "Restart Now / Restart Later".
But when I’ve load my code to real device 9780 OS 6.0.0.570 and device 9300 OS 5.0.0.846, the code is still won’t work.
Any idea why is it happen ? or I just make a simple but fatal mistake ?
Thanks :)
Your code is correct, but you need to sign your code to be able to execute CodeModuleManager.deleteModuleEx on a real device.
Please refer to the CodeModuleManager documentation for more information.
I've been trying to use ffmpeg with an air app that I made in flash cs5.5. I have it so that ffmpeg.exe needs to be located in the directory where the air app is installed (File.applicationDirectory.nativePath).
For some reason this only works when I run the program through the flash dev environment. But when I actually deploy the app, I get error #3219:The NativeProcess could not be started. ffmpeg.exe is located in the same folder.
I actually don't know the full message that it gives...not sure what the property of the error that will give me that message when I catch it. All I know is that it's error 3219.
Would this be a profile issue? If i didn't have the extended desktop desktop profile, I don't think I would be able to get this error, I'd get a profiling error wouldn't I?
I've disabled user access control as well...I'm using windows 7.
So I'm the OP, and I just realized that you can't use native process calls if you do not install the air application through the exe installer, which is an option in publish settings. I've been using the air installer.
one thing to mention is that (I'm sure you already know) the NativeProcess works only on that OS where it was compiled, so if you compile on a windows box your NativeProcess will only work on windows and not on unix/mac.
I don't know how you call the native process, but here is a code snippet that I extracted of one of my working Classes, maybe comparing it with your aproach it will give you some hint to find the problem :)
import flash.desktop.*;
import flash.errors.*;
import flash.events.*;
import flash.filesystem.*;
public function execute():void
{
var executablePath:String = "C:\ffmpeg.exe";
var parametersString:String = "-i input.avi -b 64k output.avi";
if(NativeProcess.isSupported) {
var args:Vector.<String> = new Vector.<String>();
var file:File = new File(String(executablePath));
var parameters:Array;
parameters = parametersString.split(" ");
for each ( var parameter:String in parameters ) {
args.push(parameter);
}
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = args;
startExecution(nativeProcessStartupInfo);
}
private function startExecution(nativeProcessStartupInfo:NativeProcessStartupInfo):void
{
var nativeProcess:NativeProcess = new NativeProcess();
nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
var msg:String = "";
try {
nativeProcess.start(nativeProcessStartupInfo);
trace("Trying to start process");
} catch (error:IllegalOperationError) {
trace("Illegal Operation: "+error.toString());
} catch (error:ArgumentError) {
trace("Argument Error: "+error.toString());
} catch (error:Error) {
trace("Error: "+error.toString());
}
if (nativeProcess.running) {
trace("Native Process Support");
}
}
public function onExitError(event:NativeProcessExitEvent):void
{
trace("Native Process Exit code: "+event.exitCode);
}