blackberry java webservice error - blackberry

i didnt get the output of the code.
HttpConnection httpConn;
httpConn = (HttpConnection)Connector.open("http://mydomainname.getsample.php?getData=mydata");
httpConn.setRequestMethod(HttpConnection.GET);
int iResponseCode = httpConn.getResponseCode();
System.out.print(iResponseCode);
what is the error?. how i get the output ?
iam using blackberry simulator. on pc, the url retriving the data.

if you are using eclipse
right click on the project->run as ->run configurations->simulator
check the option for launch mds with simulator.

Related

Sendkeys not working in iOS real device using Appium

I am using appium (v1.10.0) for automating iOS native app on macOS(10.13.6) using Xcode 10.1 on a real device (iPhone 6s) of platform version 12.1.3. When I start appium server and start session, the app will open in the device. Once I run the code in eclipse to send the Username to login page of the app, mobile keyboard is not getting opened and hence sendkeys() is not working.
Tried getKeyboard() before sendkeys(). Still the error exists. Below is the code which I tried.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("device", "iPhone");
cap.setCapability("deviceName", "iPhone 6s");
cap.setCapability("platformVersion", "12.1.3");
cap.setCapability("platformName", "iOS");
cap.setCapability("app","/Users/TP/Desktop/SampleApp.ipa" );
cap.setCapability("udid", "xxxxxxxxxxxxxxxxxxx");
cap.setCapability("automationName", "XCUITest");
cap.setCapability("xcodeOrgId", "xxxxxxxx");
cap.setCapability("xcodeSigningId", "xxxxxxxx");
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]")).click();
driver.getKeyboard().sendKeys("abc");
Mobile keyboard is not getting opened and hence throwing the following error.
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.
Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "Only actions of 'pointer' type are supported. 'key' is given instead for action with id 'keyboard'" UserInfo={NSLocalizedDescription=Only actions of 'pointer' type are supported. 'key' is given instead for action with id 'keyboard'}
you don't need to use getKeyboard() you can directly send the value to the fields
Send Keys sends a sequence of key strokes to an element.
Can you replace the following two lines
driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]")).click();
driver.getKeyboard().sendKeys("abc");
with
MobileElement mobileElement = driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]"));
mobileElement.sendKeys("abc");
Try this. Worked for me:
IWebElement currentElement = driver.SwitchTo().ActiveElement();
currentElement.SendKeys("any text");

Automate launching Safari from a iOS mobile app using appium

I am doing some automation with Appium on a iOS mobile app.
I need to:
open the app
do some tasks
open safari
I looked around how to do it but I've been reading that it's impossible due to a limitation in apple's framework, it doesn't allow you to sent commands to more than one app per session.
Does anyone know a way around this? Or if what I read is just not 100% true.
it doesn't allow you to sent commands to more than one app per session
Thats true, but you can run 2 sessions in a single test:
create instance of appium driver with app-based capabilities
do what you need in the app
quit driver
create instance of appium driver with browser-based capabilities
do what you need in the safari
quit driver
In a quick way it may look like:
#Test
public void testBothAppAndSafari() throws MalformedURLException {
URL appiumServerUrl = new URL("<your appium server host>");
DesiredCapabilities appCaps = new DesiredCapabilities();
// put required native app capabilities in appCaps
DesiredCapabilities safariCaps = new DesiredCapabilities();
// put required safari capabilities in safariCaps
IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
driver.findElement(<locator for element in native app>).click();
// do whatever you want with mobile app
driver.quit();
driver = new IOSDriver(appiumServerUrl, safariCaps);
driver.findElement(<locator for element in web>).click();
// do whatever you want in safari
driver.quit();
}
You can use following approach,
Created two setup one for app and other for safari.
First launch application and perform task
clear first session
Created again new Appium object for safari ( call second setup )
Perform browser activity
Close safari appium session
You also can follow my approach without quit driver.
Go terminate application. (I've used javascript to run terminateApp cause native method not work for me.)
Find Safari on Home screen and then click on it
Use drive.get to open website as you expected.
In there you can change to WEBVIEW_*** to inspect web element.
Back to native context by NATIVE_APP keyword
Sample code:
System.out.println("Run application");
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.example");
boolean terminalApp = (boolean) driver.executeScript("mobile: terminateApp", params);
System.out.println("terminateApp: " + terminateApp);
driver.findElementById("Safari").click();
Set<String> contextNames = appDriver.getContextHandles();
// Change context to WEBVIEW_***
appDriver.context(String.valueOf(contextNames.toArray()[1]));
driver.get("https://www.google.com.vn");
Thread.sleep(20000);
// Do something.
// ...
// If you want to communicate with NATIVE context just change to NATIVE_APP.
appDriver.context("NATIVE_APP");
you can activate system apps via driver.activateApp(BUNDLE_ID);
there is no need to kill the app driver and start browser driver to access browser, just switch between apps.
safari
driver.activateApp("com.apple.mobilesafari");
Here is how I resolved the issue:
driver2.activateApp("com.apple.mobilesafari");
Thread.sleep(5000);
boolean openSafariTab =
driver2.findElements(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).size() > 0;
if (openSafariTab) {
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).click();
} else { }
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeTextField[#name=\"TabBarItemTitle\"]")).click();
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeOther[#name=\"CapsuleViewController" +
"\"]/XCUIElementTypeOther[3]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")).sendKeys("https://www.golfbpm.com");
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"Go\"]")).click();

How to find current url for mobile testing in appium

I am doing automation testing using appium selenium .Can anybody help me with finding current url for mobile driver . Tried with driver.getCurrentUrl() . it's not working
You need to check the context of the app :
If context is native app , you cant get url of any screen.
If App context is having WEBVIEW you will get URL
How to check context :
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames);
}
You can switch to WEBVIEW using following code :
if (contextName.contains("WEBVIEW")) {
driver.context("WEBVIEW");
driver.getCurrentUrl()
}

PDF file download not working only for iPad specific browsers

A PDF file is generated on server side and pushed to client end for download. While the download works in all browsers on windows , fails on IPAD.
Please advise.
Specification : OS 6, Safari 6.1 , Chrome 23.0.1271.100
Please note: In this application pdf is not downloaded on to a new url (NO REDIRECTION).
General behavior: IPad browser (safari / chrome) does not support the download window, hence its expected to open the pdf and provides option to view in pdf compatible apps. Which is not currently happening.
When i debug the below servlet action code for download, the pdf file is successfully generated on server but browser on Ipad does not show :-(
Code sample :
/** Setting response Header **/
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=sample.pdf");
response.setHeader("Connection", "close");
response.setHeader("Cache-Control","cache");
response.setHeader("Pragma","cache");
response.setDateHeader ("Expires", dt.getTime() + 100000);
/** Writing to output **/
InputStream stream = info.getInputStream();
OutputStream os = response.getOutputStream();
try {
response.setContentType(contentType);
copy(stream, response.getOutputStream());
}
finally {
if (stream != null) {
stream.close();
}
}
After testing, the download action code pasted above appeared to be working fine as the issue was BROWSER specific.
Andriod Tablet - Firefox browser downloads the pdf onto pop up window.
IPad : Safari - FIX: Forced the content to open up in a new tab, something like this :
window.open(print_url);
where print_url is the baseurl+action.do+additional_parameter.
To display a pdf instead of asking the browser to save it, use "inline" instead of "attachment".
response.setHeader("Content-Disposition", "inline;filename=sample.pdf");
Also, you're setting content type twice, once in the header and once using setContentType().
I'm not sure if those two headers interact or cancel each other out, so can't say for sure that it's a source of error, but it seems like something to consider changing.

about blackberry development

I started in blackberry development.
Currently, I try to develop App with:
Blackberry Widget API (Javascript + CSS) and Eclipse (JAVA)
1/
When I try with Blackberry Widget API, I try to load a webservice in .NET, I try to run this in simulator 8520 curve... and the connect to the webservice not works, I use the config.xml to set the domains but nothing happends, later I test in 9800 simulator and works fine... but I have some fear because this app is for run in any device :(
2/
When I try with Eclipse and kSOAP2 Library,
This is my code:
String WSD_URL = "http://service.com/service.asmx";
String WSD_NAMESPACE = "http://service.com/GetInfo";
String WSD_ACTION = "http://service.com/GetInfo/fGetInfo";
SoapObject soap = new SoapObject(WSD_NAMESPACE, "fGetInfo");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.bodyOut = soap;
envelope.encodingStyle = SoapEnvelope.XSD;
HttpTransport ht = new HttpTransport(WSD_URL);
try {
ht.call(WSD_ACTION, envelope);
} catch (Exception e){
}
When I launch the app in simulator... nothing happend, few minutos after I see a error in the white screen with message "controlled access exception" :(
I have doubt here because I dont know how to solve this and if this app run in any devive.
In eclipse I see JRE 6.0
To access dot net webservice, instead of Ksoap method, try this one.. http://whatpaulhaslearnt.wordpress.com/2011/04/19/consuming-a-net-web-service-from-a-blackberry-native-application-using-the-java-me-platform-sdk-3/ .. this is the best way of accessing dot net webservice..

Resources