Search code examples
seleniumappium

Appium- Getting app configuration error while running the code


FAILED CONFIGURATION: @BeforeTest setUp org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: No app set; either start appium with --app or pass in an 'app' value in desired capabilities, or set androidPackage to launch pre-existing app on device) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 98 milliseconds Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' System info: host: 'GOD23342', ip: '10.244.46.14', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92' Driver info: org.openqa.selenium.remote.RemoteWebDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:156) at Android.firsttest.setUp(firsttest.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.TestRunner.beforeRun(TestRunner.java:647) at org.testng.TestRunner.run(TestRunner.java:615) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) at org.testng.SuiteRunner.run(SuiteRunner.java:259) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185) at org.testng.TestNG.runSuitesLocally(TestNG.java:1110) at org.testng.TestNG.run(TestNG.java:1018) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


Solution

  • package Android;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    
    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 org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;
    
    public class firsttest {
        WebDriver driver;
    
        @BeforeTest
        public void setUp() throws MalformedURLException {
            DesiredCapabilities capabilities = new DesiredCapabilities().android();
    
            capabilities.setCapability("no", true);
            capabilities.setCapability("newCommandTimeout", 100000);
            capabilities.setCapability("noReset", true);
    
            capabilities.setCapability("deviceName", "Medfield9C8687DA");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    
            capabilities.setCapability(CapabilityType.VERSION, "4.4.4");
            capabilities.setCapability("deviceName", "Venue7 3740 LTE");
            // capabilities.setCapability("app", application.getAbsolutePath());
            capabilities.setCapability("noRest", true);
            capabilities.setCapability("platformName", "Android");
    
            capabilities.setCapability("appActivity",
                    "com.android.calculator2.Calculator");
            driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                    capabilities);
            driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        }
    
        @Test
        public void Sum() {
            driver.findElements(By.xpath("//android.widget.Button")).get(0).click();
    
            driver.findElement(By.name("2")).click();
    
            driver.findElement(By.name("+")).click();
            driver.findElement(By.name("5")).click();
            driver.findElement(By.name("=")).click();
            String result = driver.findElement(
                    By.className("android.widget.EditText")).getText();
            System.out.println("Number sum result is : " + result);
        }
    
        @AfterTest
        public void End() {
            driver.quit();
        }
    }