Two Apps in a Single Script

Hi all,
I want to run two hybrid apps in a single script ??? How Can i do that
eg:-
Suppose i have two applications “screen recorder app” and “Skype”. On 1st go i want to open the screenrecorder Click on record button the app then lets me to nevigate to the launcher and then i have to choose my 2nd app(Skype) record the whole login to login scernerio. After that return to screen recorder app and click on stop button.

My question is how can i give 2 AppName and 2 ActivityName in a single script.

I am Using Java (Eclipse) to do so.
Please let me know the proper steps to do so…

It would be possible with single script but not sure if this can be done on a single device. You can maybe use 2 devices, create 2 appium servers and then open each app on different device/emulator.

1 Like

Hi Anish,
NO sir but ques remains the same, if i want to record the whole process from login to logout on my android device.i have to run both scripts on my single device.

Hi Tanuj,

Can you elaborate problem you are facing?

I hope you must have tried using same driver to start two different apps. Like launch app with driver d , then after clicking on record start new activity with same driver.

Regards,
AD

@dubeyabhijeet …yes can u help me out with it.

What I do is take screenshots of the entire test run… Zip it and wait X days after delete them… I think this simplifies a lot the process and is in the same level of control

1 Like

Can you try below flow?

AndoridDriver dr = new AndroidDriver(new URL(xxxxxx),capabilities);

it will launch the screen recorder. Then navigate to click and click.

Then move back to launcher screen and use dr.startnewactivityt(xx,xxx); and then do whole process of login.

Now you can you recent app list and invoke the screen recorder.

Tanuj,

Also if it not mandatory to use a app to record the screen, then you can google and check with thoughtworks.com code in github. they have used some lib to recordvideo of phone

I haven’t tried this with android but you should be able to create two instances of AndroidDriver. So the code would be something like:

File app1 = new File(appDir, "skype.apk");
DesiredCapabilities capabilities1 = new DesiredCapabilities();
capabilities.setCapability("app", app1.getAbsolutePath());
// set other capabilities here
driver1 = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities1);

File app2 = new File(appDir, "recorder.apk");
DesiredCapabilities capabilities2 = new DesiredCapabilities();
capabilities2.setCapability("app", app2.getAbsolutePath());
// set other capabilities here
driver2 = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities2);

Now you can use driver1 to control the skype and driver2 to control the recorder (you’ll have to give real APKs for the apps; I just put fake ones).

Darrell

1 Like

Hi Darrell ,
I just have one query … u have write Android Package name
But where should we write the activity name in it.

I don’t understand your question. By ‘write Android Package name’ do you mean I have created an instance of AndroidDriver for each of the Android apps (APKs)?

What do you mean by 'write the activity name in it"? Is an activity like clicking an element, scrolling the display, etc.? If that is what you mean then you would use driver1 instance to do the actions against Skype and driver2 instance to do actions against the Recorder app.

Darrell

hi Darell,
Yes that’s what i want …
Can u plz explain me the following line:- “File app1 = new File(appDir, “skype.apk”);”
what is appDir in this…

Hi Tanuj,

The example I gave you is written in Java. In the Java bindings for Appium you have to set the “app” keyword to the file location for the APK you want to test. So, for example, if my Skype app is located at /Users/darrellgrainger/workspace/skype/build/skype.apk then the appDir is “/Users/darrellgrainger/workspace/skype/build” and the binary I wish to test is “skype.apk”.

So in my example, driver1 is an instance of AndroidDriver. The line with driver1 = new AndroidDriver(…) will launch the Skype app. If I enter driver1.findElement(button).click(); it find an element using the button locator and click it.

This is all just straight forward Appium/WebDriver in Java. You can write Appium tests in .NET, Java, Node, Perl, PHP, Python or Ruby. I just used Java because it is the language I last used to write Appium tests with.

What is the language you are using to write Appium tests?

Darrell

1 Like

Hi Dareel ,
I am using Java for the same below is code hope u can help me out with the same

public class DualApplication {
AndroidDriver driver1,driver2;

@BeforeTest
public void setUp1() throws Exception {

File app1 = new File(“com.android.calculator2”);
{
DesiredCapabilities capabilities1 = new DesiredCapabilities();
//capabilities1.setCapability(“app”, app1.getAbsolutePath());

capabilities1.setCapability(“deviceName”, “SQ4818D49224”);
capabilities1.setCapability(“browserName”, “Android”);
capabilities1.setCapability(“platformVersion”, “4.4.4”);
capabilities1.setCapability(“platformName”, “Android”);
// set other capabilities here
driver1 = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities1);
}

File app2 = new File(“com.android.calendar”);
{
DesiredCapabilities capabilities2 = new DesiredCapabilities();
// capabilities2.setCapability(“app”, app2.getAbsolutePath());

capabilities2.setCapability(“deviceName”, “SQ4818D49224”);
capabilities2.setCapability(“browserName”, “Android”);
capabilities2.setCapability(“platformVersion”, “4.4.4”);
capabilities2.setCapability(“platformName”, “Android”);

// set other capabilities here
driver2 = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities2);
}

// DesiredCapabilities capabilities1= new DesiredCapabilities();
// capabilities1.setCapability(“deviceName”, “7676767676”);
// capabilities1.setCapability(“browserName”, “Android”);
// capabilities1.setCapability(“platformVersion”, “4.4.4”);
// capabilities1.setCapability(“platformName”, “Android”);
//
// capabilities1.setCapability(“appPackage”, “com.android.calculator2”);
// capabilities1.setCapability(“appActivity”,“com.android.calculator2.Calculator”);
//
// driver1 = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities1);
// driver1.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// WebDriverWait wait = new WebDriverWait(driver1, 300);

// DesiredCapabilities capabilities2= new DesiredCapabilities();
// capabilities2.setCapability(“deviceName”, “7676767676”);
// capabilities2.setCapability(“browserName”, “Android”);
// capabilities2.setCapability(“platformVersion”, “4.4.2”);
// capabilities2.setCapability(“platformName”, “Android”);

// capabilities2.setCapability(“appPackage”,“com.android.calendar”);
// capabilities2.setCapability(“appActivity”,“com.android.calendar.AllInOneActivity”);
// driver2 = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities2);
// driver2.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// WebDriverWait wait1 = new WebDriverWait(driver1, 300);
//
//wait.until(ExpectedConditions.elementToBeClickable(By.className(“android.widget.RelativeLayout”)));
}

@Test(priority=0)
public void Calculator() throws InterruptedException {

// new TouchAction(driver1).press(101,414).waitAction(1000).moveTo(275,0).waitAction(1000).moveTo(-265,260).moveTo(270,0).waitAction(2000).release().release().perform();
// Thread.sleep(5000);

 driver1.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'com.android.calculator2:id/digit1')]")).click();
 Thread.sleep(3000);
 
 driver1.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'com.android.calculator2:id/plus')]")).click();
 Thread.sleep(3000);
 
 driver1.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'com.android.calculator2:id/digit5')]")).click();
 Thread.sleep(3000);
 
 driver1.findElement(By.xpath("//android.widget.Button[contains(@resource-id,'com.android.calculator2:id/equal')]")).click();
 Thread.sleep(3000);

}

@Test(priority=1)
public void Calender() throws InterruptedException {
driver2.findElement(By.xpath("//android.widget.Spinner[contains(@resource-id,‘android:id/action_bar_spinner’)]")).click();
Thread.sleep(3000);

 driver2.findElement(By.xpath("//android.widget.Spinner[contains(@resource-id,'android:id/action_bar_spinner')]")).click();
 Thread.sleep(3000);
 
 driver1.findElement(By.xpath("//android.widget.Button[@text='9']")).click();
 Thread.sleep(3000);	 

}

@AfterTest
public void End() {
// driver1.quit();
//driver2.quit();
}