I have executed this code:
package org.test;
import static org.junit.Assert.assertEquals;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.functions.ExpectedCondition;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.JavascriptException;
import org.testng.Assert;
import org.openqa.selenium.InvalidSelectorException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.TouchAction;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test {
static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException {
//Before
setUp();
sampleTest();
tearDown();
}
//Test
public static Boolean sampleTest() {
MobileElement el1 = (MobileElement) driver.findElementById("---:id/username");
el1.sendKeys("eleve5");
MobileElement el2 = (MobileElement) driver.findElementById("----:id/password");
el2.sendKeys("eleve5");
MobileElement el3 = (MobileElement) driver.findElementById("---:id/loginButton");
el3.click();
FluentWait wait = new FluentWait<AndroidDriver>(driver);
Boolean element = (Boolean) wait.until(new ExpectedCondition<Boolean>() {
//@Override
public Boolean apply(WebDriver arg0) {
// TODO Auto-generated method stub
return driver.findElementById("c----:id/errorMessage").isDisplayed();
}
});
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
if (element == true) {
driver.executeScript("client:client.setTestStatus(false,'msg : test fail')");
return false;
}
else {
driver.executeScript("client:client.setTestStatus(true,'msg : test passed')");
return true;
}}
public static void tearDown() {
driver.quit();
}
//After
public static void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("deviceName", "----");
desiredCapabilities.setCapability("platformName", "Android");
desiredCapabilities.setCapability("appPackage", "----");
desiredCapabilities.setCapability("appActivity", "-----.LauncherActivity");
desiredCapabilities.setCapability("udid", "77671609090020523");
desiredCapabilities.setCapability("platformVersion", "5.0");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), desiredCapabilities);
}}
When i run, return this error:
Exception in thread “main” java.lang.ExceptionInInitializerError
at javax.crypto.JceSecurity.loadPolicies(JceSecurity.java:378)
at javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:323)
at javax.crypto.JceSecurity.access$000(JceSecurity.java:50)
at javax.crypto.JceSecurity$1.run(JceSecurity.java:85)
at java.security.AccessController.doPrivileged(Native Method)
at javax.crypto.JceSecurity.(JceSecurity.java:82)
at javax.crypto.JceSecurityManager.(JceSecurityManager.java:65)
at javax.crypto.Cipher.getConfiguredPermission(Cipher.java:2586)
at javax.crypto.Cipher.getMaxAllowedKeyLength(Cipher.java:2610)
at sun.security.ssl.CipherSuite$BulkCipher.isUnlimited(CipherSuite.java:535)
at sun.security.ssl.CipherSuite$BulkCipher.(CipherSuite.java:507)
at sun.security.ssl.CipherSuite.(CipherSuite.java:614)
at sun.security.ssl.SSLContextImpl.getApplicableCipherSuiteList(SSLContextImpl.java:294)
at sun.security.ssl.SSLContextImpl.access$100(SSLContextImpl.java:42)
at sun.security.ssl.SSLContextImpl$AbstractTLSContext.(SSLContextImpl.java:425)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.security.Provider$Service.getImplClass(Provider.java:1634)
at java.security.Provider$Service.newInstance(Provider.java:1592)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)
at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:54)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(SSLConnectionSocketFactory.java:172)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:72)
at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:58)
at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:61)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:253)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.(ApacheHttpClient.java:224)
at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:73)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:93)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:77)
at org.test.Test.setUp(Test.java:109)
at org.test.Test.main(Test.java:42)
Caused by: java.lang.SecurityException: Framework jar verification can not be initialized
at javax.crypto.JarVerifier.(JarVerifier.java:228)
… 34 more
Caused by: java.security.PrivilegedActionException: java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: java.lang.IllegalArgumentException: Illegal base64 character -2
at java.security.AccessController.doPrivileged(Native Method)
at javax.crypto.JarVerifier.(JarVerifier.java:186)
… 34 more
Caused by: java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: java.lang.IllegalArgumentException: Illegal base64 character -2
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:110)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
at javax.crypto.JarVerifier.parseCertificate(JarVerifier.java:242)
at javax.crypto.JarVerifier.access$100(JarVerifier.java:37)
at javax.crypto.JarVerifier$1.run(JarVerifier.java:193)
at javax.crypto.JarVerifier$1.run(JarVerifier.java:187)
… 36 more
Caused by: java.io.IOException: java.lang.IllegalArgumentException: Illegal base64 character -2
at sun.security.util.Pem.decode(Pem.java:49)
at sun.security.provider.X509Factory.readOneBlock(X509Factory.java:638)
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:96)
… 41 more
Caused by: java.lang.IllegalArgumentException: Illegal base64 character -2
at java.util.Base64$Decoder.decode0(Base64.java:714)
at java.util.Base64$Decoder.decode(Base64.java:526)
at sun.security.util.Pem.decode(Pem.java:47)
… 43 more