I am new to appium. I am getting below error when i Run appium code in eclipse:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=D:\Workspace\Mobile\Apps\ATT\AT.apk, appPackage=com.atp.android, appActivity=Splash, appium-version=1.6.4, platformVersion=6.0, platformName=Android, deviceName=Test}], required capabilities = Capabilities [{}]
Code:
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
AppiumDriver driver;
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/AST/");
File app = new File(appDir, "AT.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.6.4");
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Test");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.atp.android");
capabilities.setCapability("appActivity", "Splash");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
Selenium version is 3.4
Please help to resolve this issue. Thanks
You can try to comment the following two lines and see how does it work:
capabilities.setCapability("appPackage", "com.atp.android");
capabilities.setCapability("appActivity", "Splash");
since when you run test on a complicate app, it's hard to make sure the content of apppackage and app are set right. Appium will help you to find the correct content automatically instead.
Related
I have created an automation project to test a flutter app using appium flutter driver.
But I cannot use flutter driver.
My automation project does not detect automationName as flutter.
Even if I try driver.context("FLUTTER"); I get NoSuchContextException error.
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(
new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress("127.0.0.1").usingPort(4723));
service.start();
DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File(System.getProperty("user.dir")+"/app");
File app = new File (appDir,"app-debug.apk");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability("automationName", "Flutter");
capabilities.setCapability("appPackage", "com.example.flutter_intellij_test");
capabilities.setCapability("appActivity","com.example.flutter_intellij_test.MainActivity");
driver = new AndroidDriver<MobileElement>(service.getUrl(), capabilities);
wait = new WebDriverWait(driver, 10);
find = new FlutterFinder(driver);
Make sure your Appium server version is above 1.6
There shouldn't be anything specific with Java client, just try to change your capabilities this way:
DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File(System.getProperty("user.dir")+"/app");
File app = new File (appDir,"app-debug.apk");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Flutter");
capabilities.setCapability("retryBackoffTime", "500");
capabilities.setCapability("deviceName", <value from `adb devices`>);
driver = new AndroidDriver<MobileElement>(service.getUrl(), capabilities);
Next time post Appium server log :)
Selenium headless chrome testing with java in unix returns empty page source as
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>
which was due to accessing the secure http (https) website.
Is there a way to ignore the ssl certificate issue? Please let me know how to ignore it.
Selenium Version 3.7.1..java version 1.8.0.144 chrome driver version 2.33
Chrome Version 62+
I gave a try with options below..but it doesn't seem to work.
1. ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
options.setHeadless(true);DesiredCapabilities capabilities =
DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--
ignore-certificate-errors,--web-security=false,--ssl-
protocol=any,--ignore-ssl-errors=true"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
2. DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
Am i doing this in a right way? Let me know the trick to make it work
Thanks in advance
Complete Code:
WebDriver driver = null;
try {
String filePath = "Path to driver";
System.setProperty("webdriver.chrome.driver", filePath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.setAcceptInsecureCerts(true);
options.addArguments("test-type");
String[] switches = {"--ignore-certificate-errors"};
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList(switches));
capabilities.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://meta.stackexchange.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("PAGE SOURCE : \n" + driver.getPageSource());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
driver.close();
driver.quit();
}
Now you can add capabilities in option. please try following:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--no-sandbox");
options.addArguments("--headless", "--window-size=1920,1200", "--ignore-certificate-errors");
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
driver = new ChromeDriver(options);
WebDriver opens browser window, but I get SEC_ERROR_UNKNOWN_ISSUER.
I tried to add this site as an exception in browser, but when new browser window opened I get the same message again instead of the website.
FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
options.setLogLevel(Level.ALL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
WebDriver driver = new FirefoxDriver(capabilities);
You need to set setAcceptInsecureCerts Capabilities as true
This simple code work for me :-
System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://self-signed.badssl.com/");
OR
System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("acceptInsecureCerts", true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://self-signed.badssl.com/")
Change your gecko path in first line of code. Update gecko driver and firefox
I am new to appium.I would like to use driver.hideKeyboard() and drive.swipe() comments in appium.However when I try to use these comments in eclipse,it is thorowing error as
The method swipe() is undefined for the type WebDriver
Hide also I am getting same error.I think I need to import something in the drive.Could you please guide me what I need to do?
public void Appium() throws MalformedURLException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
Change your driver type to AppiumDriver. Like this:
AppiumDriver driver;
and then
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
I have tried following.It is working fine.
AppiumDriver driver;
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
public void()
{
driver.hideKeyboard();
}
Above appium driver I am able to get swipe and hide functions.
Saucelabs:-
https://saucelabs.com/
Am creating the firefox driver on saucelabs using the following:-
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("version", "5");
capabilities.setCapability("platform", Platform.XP);
// Create the connection to Sauce Labs to run the tests
this.driver = new RemoteWebDriver(
new URL("http://YOUR_USERNAME:YOUR_ACCESS_KEY#ondemand.saucelabs.com:80/wd/hub"),
capabilities);
}
I want to use the mobile user agent using firefox driver. How can i do it.
Have you tried creating a new profile and setting the user agent string on the profile?
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "UA-STRING");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);