Hi All,
I can run appium test case on android emulator successfully,
but can not run it on android real devices.
I get this error:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13.50 seconds
Thanks for reply
Yes, developer mode enabled and security disabled on my device.
I have Mi Phone
My DesiredCapabilities :
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“deviceName”, “c56fgth4”);
capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”);
capabilities.setCapability(CapabilityType.VERSION, “5.0.2”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, “com.***”);
capabilities.setCapability(“appActivity”, “com.***.activities.ActivitySplashStart”);
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub ”), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
My First Launch Activity is: “com.***.activities.ActivitySplashStart”
After that i have below activity “com.***.MainActivity” started.
And ActivitySplashStart start every time when app launched.
after wait 2 sec next activity started(here is MainActivity).
If i set Next activity as appActivity here is MainActivity
then still this error comes:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 13.50 seconds
But if i set appActivity here is ActivitySplashStart
then element not available error comes.
Its problem occur only real devices perfectly run on emulator.
Aleksei
September 18, 2017, 11:27am
4
@pinak.gauswami update wait for package with “*”:
capabilities.setCapability(“appActivity”, “com.your_package_name.activities.*”);
and forget about any activity appears on start
I can not share my package name
so that i write ‘**’.
Aleksei
September 18, 2017, 11:41am
6
@pinak.gauswami i do not ask you to share something. just replace “your_package_name” with your real package name and try given code.
Thanks for reply,
But i try this already also i can run all test case in emulator but can’t in My MI Phone.
Aleksei
September 18, 2017, 12:02pm
8
@pinak.gauswami can you share appium logs in debug mode at https://gist.github.com/ ? (remove all sensitive info from logs)
Aleksei
September 18, 2017, 12:25pm
10
pinak.gauswami:
info: [debug] [BOOTSTRAP] [debug] Finding com.xyz:id/spinner_contactnumber_countries using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.xyz:id/spinner_contactnumber_countries]
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:7,“value”:“No element found”}
info: [debug] Condition unmet after 1336ms. Timing out.
info: [debug] Responding to client with error: {“status”:7,“value”:{“message”:“An element could not be located on the page using the given search parameters.”,“origValue”:“No element found”},“sessionId”:“b97db0e1-f878-4a12-9810-a7e27dbe62ef”}
info: <– POST /wd/hub/session/b97db0e1-f878-4a12-9810-a7e27dbe62ef/element 500 1338.547 ms - 195
info: –> DELETE /wd/hub/session/b97db0e1-f878-4a12-9810-a7e27dbe62ef {}
PLS remove your logs from chat. they should be in gist otherwise it is hard to read. According to logs your element with "spinner_contactnumber_countries"just not found.
yes but i know error comes there
but this element located another activity.
Aleksei
September 18, 2017, 12:30pm
12
@pinak.gauswami maybe. we do not know your code.
Ok, I share My code
package com.xyz.Registration;
/**
Created by Pinak.Gauswami on 3/17/2017.
*/
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.MobileBy;
public class SplashToDirectContactTest {
WebDriver driver;
@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "cp6fcdr4");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.0.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.xyz");
capabilities.setCapability("appActivity", "com.xyz.activities.ActivitySplashStart");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@org.junit.Test
public void testFirstCalculator() throws InterruptedException {
Thread.sleep(3000);
driver.findElement(By.name("By pressing Get Started, you agree you're 18 years or above and you accept Terms & Services and Privacy Policy")).click();
driver.navigate().back();
driver.findElement(By.id("com.xyz:id/textview_splash_iagree")).click();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
allowAppPermission();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
allowAppPermission();
driver.findElement(By.id("com.xyz:id/spinner_contactnumber_countries")).click();
driver.findElement(By.xpath("//android.widget.TextView[@text='INDIA']")).click();
driver.findElement(By.id("com.xyz:id/spinner_contactnumber_countries_code")).click();
driver.findElement(By.xpath("//android.widget.TextView[@text='+91']")).click();
driver.findElement(By.id("com.xyz:id/edittext_contactnumber")).sendKeys("8888888886");
driver.findElement(By.id("com.xyz:id/button_contactnumber_verify")).click();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
allowAppPermissionIF();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
allowAppPermissionIF();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.findElement(By.id("com.xyz:id/textview_verify_contact_edit")).click();
driver.findElement(By.id("com.xyz:id/button_contactnumber_verify")).click();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.findElement(By.id("com.xyz:id/textview_verify_contact_ok")).click();
driver.findElement(By.id("com.xyz:id/edittext_verifyotp_one")).sendKeys("0");
driver.findElement(By.id("com.xyz:id/edittext_verifyotp_two")).sendKeys("0");
driver.findElement(By.id("com.xyz:id/edittext_verifyotp_three")).sendKeys("0");
driver.findElement(By.id("com.xyz:id/edittext_verifyotp_four")).sendKeys("0");
Thread.sleep(2000);
driver.findElement(By.id("com.xyz:id/textview_next")).click();
driver.findElement(By.id("com.xyz:id/textview_next")).click();
driver.findElement(By.id("com.xyz:id/textview_next")).click();
}
public void allowAppPermission() {
while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size() > 0) {
driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click();
}
}
public void allowAppPermissionIF() {
while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size() > 0) {
driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click();
}
}
@After
public void End() {
driver.quit();
}
}
Aleksei
September 18, 2017, 12:39pm
14
pinak.gauswami:
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
allowAppPermission();
driver.findElement(By.id("com.xyz:id/spinner_contactnumber_countries")).click();
according to this “spinner_contactnumber_countries” must appear within “1” sec. may you add:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //10 sec wait for element
after last “allowAppPermission();” ?
But sir after performing below click event of this screen element
driver.findElement(By.name(“By pressing Get Started, you agree you’re 18 years or above and you accept Terms & Services and Privacy Policy”)).click();
driver.navigate().back();
driver.findElement(By.id("com.xyz:id/textview_splash_iagree")).click();
then next screen contain these element:
driver.findElement(By.id(“com.xyz:id/spinner_contactnumber_countries”)).click();
Flow like My App is :spalshstart -> Splash-> AppRegistration-> VerifyOTP -> MainActiivty
Aleksei
September 18, 2017, 12:46pm
16
@pinak.gauswami it is contain but 1 SECOND can be too little value for timeout. try to increase is e.g, to 10sec as i suggested. just give a try if it becoming better or not.
I have many try but can not launch test case on my phone
i have also try some other devices but still problem occur.
Same testcase run on nexus 5 android emulator successfully.
Thanks for Response.
Aleksei
September 18, 2017, 1:04pm
19
@pinak.gauswami you mean that “spinner_contactnumber_countries” element is visible but after 10 sec you failed click on it?
No sir,
Its visible after
driver.findElement(By.name(“By pressing Get Started, you agree you’re 18 years or above and you accept Terms & Services and Privacy Policy”)).click();
driver.navigate().back();
driver.findElement(By.id(“com.xyz:id/textview_splash_iagree”)).click();
Right Now I can not click driver.findElement(By.name("By pressing G… Element