org.openqa.selenium.UnsupportedCommandException for appium (devices) for sauce labs - appium

I am trying to upgrade from Selenium 3 to Selenium 4. The capabilities and everything works fine for all the browsers remotely on sauce labs and works well even on local but when it comes to devices(Android Ipad/Mobile and iOS Ipad/Mobile) I am getting org.openqa.selenium.UnsupportedCommandException. Can someone help out?
Selenium Version: 4.1.0
Chrome Driver: 100.0 (latest)
Capabilities
else if (!BaseTest.isLocal && BaseTest.Devices) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appiumVersion", "1.17.1");
capabilities.setCapability("deviceOrientation", "portrait");
capabilities.setCapability("browserName", browser);
capabilities.setCapability("browserVersion", version);
capabilities.setCapability("platformName", os);
capabilities.setCapability("seleniumVersion", "4.1.0");
capabilities.setCapability("deviceName", devicename);
capabilities.setCapability("platformVersion", platformversion);
capabilities.setCapability("name", methodName);
capabilities.setCapability("autoAcceptAlerts", "true");
System.out.println("pop-up alerts disabled for IOS");
if (browser.toLowerCase().contains("chrome")) {
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-translate");
options.addArguments("disable-translate-new-ux");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
}
if (buildTag != null) {
capabilities.setCapability("build", buildTag);
}
// Launch remote browser and set it as the current thread
webDriver.set(new RemoteWebDriver(
new URL("https://" + username + ":" + accesskey + "#ondemand.saucelabs.com:443/wd/hub"),
capabilities));
Code
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
public WebDriver getWebDriver() {
if (!BaseTest.isLocal) {
return webDriver.get();
} else {
return localWebDriver;
}
}
Error
FAILED: Selenium4("Chrome", "latest-1", "Android", "7.1", "Samsung Galaxy Tab A 10 GoogleAPI Emulator", public void com.dell.tnt.tests.WFTTests.Selenium_4_Test.Selenium4(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.reflect.Method) throws java.lang.InterruptedException,com.dell.tnt.exceptions.OfferNotFoundException,java.io.IOException,java.lang.NullPointerException,java.lang.IndexOutOfBoundsException,java.lang.ArrayIndexOutOfBoundsException)
org.openqa.selenium.UnsupportedCommandException: The URL '/wd/hub/session/XXXXXXXX-XXXX-XXXX-XXXX-XXXXf7ad4561/window/new' did not map to a valid resource
[ErrorImage][1]
Tried Version:
// Mobile Devices
MutableCapabilities caps = new MutableCapabilities();
caps.setCapability("platformName", os);
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", browser);
caps.setCapability("appium:deviceName", devicename);
caps.setCapability("appium:platformVersion", platformversion);
MutableCapabilities sauceOptions = new MutableCapabilities();
sauceOptions.setCapability("name", methodName);
sauceOptions.setCapability("appiumVersion", "1.17.1");
caps.setCapability("sauce:options", sauceOptions);
if (buildTag != null) {
caps.setCapability("build", buildTag);
}
// Launch remote browser and set it as the current thread
webDriver.set(new RemoteWebDriver(
new URL("https://" + username + ":" + accesskey + "#ondemand.saucelabs.com:443" + "/wd/hub"),
caps));
**Error
Error1
Saucelab: Saucelab

UPDATE:
I got caught up in making sure settings were giving you a valid w3c session, which is required for that command to work in Desktop tests.
Apparently the issue is that Appium does not have the window/new route supported at all right now. The Appium team has been made aware of it, and they'll get it added for a future release (and then it will only work on Android, not iOS).
Appium issue: https://github.com/appium/appium/issues/16749
So a few things here.
For mobile browsers, you can use Selenium code locally, but your code is getting sent to an Appium server not a Selenium server on Sauce Labs VMs/Devices. It is expecting to see valid w3c compliant capabilities with Selenium 4.
For w3c & Selenium 4 everything should theoretically be using the browser options class directly; no DesiredCapabilities, just ChromeOptions, etc.
As for what capabilities are available on Sauce and how they get used,
I recently updated this documentation, so it should be up to date: https://docs.saucelabs.com/dev/test-configuration-options/
A good way to start is with using the Sauce Labs Platform Configurator to get your baseline: https://saucelabs.com/platform/platform-configurator
Note that this is for using Selenium code, not Appium code. Also, this is for emulator/simulator code. Real devices are similar just with a different device name. Finally it uses MutableCapabilities instead of Browser Options classes because that was easier to generate on the back end not because it is preferred.
It'll look something like this:
MutableCapabilities caps = new MutableCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "Safari");
caps.setCapability("appium:deviceName", "iPhone Simulator");
caps.setCapability("appium:platformVersion", "15.4");
MutableCapabilities sauceOptions = new MutableCapabilities();
sauceOptions.setCapability("appiumVersion", "1.22.3");
caps.setCapability("sauce:options", sauceOptions);
Finally, you should update your endpoint, as the old endpoint has some issues with w3c + Real Devices:
https://docs.saucelabs.com/basics/data-center-endpoints/#us-west-data-center

Related

End to end test of electron app on Windows

What I am trying to achieve:
I'd like to set up an electron project with a proper headless end-to-end testing configuration.
Issues encountered
Spectronjs seems to be the solution to achieve so. However there is no configuration to prevent the window from opening on each test. Reading some of the threads on the repository + the documentation of electron in regards to testing mentions Xvfb. I've tried to get my head around this but understand so far that this cannot be installed on Windows? And that there is no alternative.
The list on the page includes other options such as Appvoyer or CicleCI but these again are new and I am barely able to find a guide around these not to mention, I am not really liking that I have to do all these steps (link to github/bitbucket account, etc).
I've also tried to go through demo applications from the electronjs list page, but not all of them do have tests, and when they do, they are sometime written in what seems to be a different programming language, or specifically aimed for angular or react, while on my end I am aiming to use vuejs.
Can anyone point me to a clean example of an offline end to end headless test of an electron app on Windows?
There are several options how to E2E test an Electron app, unfortunately none of them is truly headless. On Windows you do not need Xvfb, it is a Linux thing. On Windows there is a "screen" available even in CI environments (I have experience with Appveyor and Azure Pipelines).
Puppeteer-core (Puppeteer-core does not contain chromium)
Spectron
Selenium-webdriver
Webdriver.io
In the past I used Spectron, but I recently switched to Puppeteer and I am very happy with the switch.
Short Puppeteer try out test file:
const electron = require("electron");
const puppeteer = require("puppeteer-core");
const delay = ms =>
new Promise(resolve => {
setTimeout(() => {
resolve();
}, ms);
});
(async () => {
try {
const app = await puppeteer.launch({
executablePath: electron,
args: ["."],
headless: false,
});
const pages = await app.pages();
const [page] = pages;
await page.setViewport({ width: 1200, height: 700 });
await delay(5000);
const image = await page.screenshot();
console.log(image);
await page.close();
await delay(2000);
await app.close();
} catch (error) {
console.error(error);
}
})();
I am testing and building an electron app in Azure Pipelines (free for open-source projects) on Win, Linux and MacOS with this config:
azure-pipelines.yml

iOS ionic 3 - CORS error on iOS iphone device - Origin localhost:8080 is not allowed by Access-Control-Allow-Origin

I cannot access REST API. CORS problem on ionic 3 iOS build
Below is a screenshot of the problem. I use Safari to check the console messages of the iOS ionic app
https://imgur.com/a/WO3M5
Here is how I made the api call
var url = this.baseurl.baseurl();
var data = "username=" + this.username + "&password=" + this.password + "&device_uuid=ionic";
this.http.post(url + 'parent/parent_login_with_companyname', encodeURI(data), { headers: new __WEBPACK_IMPORTED_MODULE_4__angular_common_http__["c" /* HttpHeaders */]().set('Content-type', 'application/x-www-form-urlencoded') })
.subscribe(function (res) {
loading_1.dismiss();
window.localStorage.setItem('parent_info', JSON.stringify(res));
_this.navCtrl.setRoot(__WEBPACK_IMPORTED_MODULE_2__tabs_tabs__["a" /* TabsPage */]);
}, function (err) {
SOLUTION
After a very long search I found this holy grail! Hope this works for you as it did for me:
http://uncaughterror.com/programming/ionic3/preflight-response-issue-with-ionic3-app-on-ios-build-only-resolved/
You can disable the same-origin policy on Safari , in order to disable it you only need to enable the developer menu, and select "Disable Cross-Origin Restrictions" from the develop menu.
This you can do when you are in development phase. You will not get this issue when you will move application to live server and can access it without disabling cross -origin restrictions.

Cannot call a webapi from mac simulator when debugging from visual studio 2015 ionic apache cordova app

Let me tell you my steps.
we are creating an iOS app using ionic framework template from Visual studio 2015
we created a asp.net webapi 2 with CORS enabled.we publish that into a public domain to access from anywhere.
we created a login page which will post userid and password to web api via http$ code is written below
when we are running from VS2015 with ripple emulator we are able to see connection ok and api returning success data while pressing Login button
we started remotebuild in our development mac machine
remotebuild --secure false
we configure VS2015 with remote agent configuration.
we started debugging and can see remotebuild is responding and our app with all images loaded successfully in ios simulator.
when we press login button on simulator debug point also comes to visual studio in windows machine.
after api call result is null and status is 0
we tried every possible combination with local ip,global ip,dns names
we tried installing cordova whitelist plugin.but same problem.
Please help.
var Paramdata = {
USER_ID: data.username,
COUNTRY_ID: data.CountryId.ID,
PASSWORD: data.password
};
$http.get('http://www.myapp.com/AppApi/api/users?id=' + JSON.stringify(Paramdata)).success(function(data, status, headers, config) {
console.log("**** SUCCESS ****");
console.log(status);
})
.error(function(data, status, headers, config) {
console.log("**** ERROR ****");
console.log(status);
})
.then(function(response) {
var jsonData = response.data;
$scope.LoginData = jsonData;
if ($scope.LoginData[0].isvalid == 'Y') {
var alertPopup = $ionicPopup.alert({
title: 'Login Sucessful!',
template: LoginData[0].MESSAGE_LOGIN
}
} else {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: LoginData[0].MESSAGE_LOGIN
})
}
});

How to send text from Windows Phone 8.1 via HttpWebRequest / POST?

I have a web service that expects (unicode UTF-8 encoded) text data as an HTTP POST message.
I'd like to use it from a Windows Phone 8.1 runtime client.
I created the client, but it does not invoke the web URI.
Here's the code I use on the client:
Can anyone tell what am I missing?
Thanks,
B
{
...
SendText("http://192.168.1.107:58709/UploadText.aspx"); // The IP belongs to the web server, port is correct. I can invoke it from a browser.
...
}
string StringToSend = "This is a test string uploaded via HTTP POST from WP8";
private void SendText(string Url)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(Url);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.BeginGetRequestStream(new AsyncCallback(UploadText_GetRequestStreamCallback), request);
}
public void UploadText_GetRequestStreamCallback(IAsyncResult asyncResult)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)asyncResult.AsyncState;
Stream postStream = request.EndGetRequestStream(asyncResult);
byte[] postDataAsBytes = System.Text.Encoding.UTF8.GetBytes(StringToSend);
postStream.Write(postDataAsBytes, 0, postDataAsBytes.Length);
postStream.Flush();
// postStream.Close(); // Close is not available in Windows Phone 8.1 runtime project.
// request.ContentLength = postDataAsBytes.ToString(); // request.ContentLength is not available in Windows Phone 8.1 runtime project.
request.Headers["Content-length"] = postDataAsBytes.ToString();
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
OK, it seems the code was correct...
Problem was, that the phone emulator could not connect to the development server (IIS Express). I searched the web over, tried a number of solutions, but I could not make it happen. In the meantime I trashed my wifi connection, had to remove and reinstall Hyper-V to make it work again.
The workaround was to publish the test web app to the local IIS (make sure it is the Debug version that is published) then attach to it from the debugger, call from WP8.1 emulator - and it works.

JQuery AJAX call to web on iOS stopped working using Phonegap web app

I have an app written in HTML5, Javascript, css3 using PhoneGap to compile for iOS and Android. It collects survey information and uploads this via Ajax call to online host. It has been working really well until recently the upload code appeared to stop working. WELL NOT QUITE! On the iPad it says successful but in fact nothing ever makes it to the host. This is VERY strange. I've tried re-writing the Ajax call based on articles on here but no luck.
iOS - 6.1.3, PhoneGAP 2.7.0, PhoneGap/Adobe Build used.
This is the upload piece...
function sendToWeb(){
var errorflag = false;
db.transaction(function (tx) {
tx.executeSql("SELECT weburl FROM settings", [], function(tx, results){
var webURL = results.rows.item(0).weburl;
tx.executeSql("SELECT * FROM surveypretransfer WHERE uploaded = '0'",[], function(tx, results){
if (results.rows.length == 0) {
alert("You have no surveys waiting to upload");
} else {
alert("You have " + results.rows.length + " surveys waiting to upload");
for (var i=0; i < results.rows.length; i++) {
var responseURL = webURL + "/feeds/saveinfo.php";
var responseString = results.rows.item(i).responsestring;
var localid = results.rows.item(i).id;
//alert(localid);
$.ajax({
type: 'POST',
data: responseString,
url: responseURL,
timeout: 30000,
success: function(data) {
alert('Success!' + data.join('\n'));
},
error: function(data) {
alert(data.join('\n'));
console.log("Results: " + localid);
alert("Error during Upload. Error is: "+ data.statusText);
}
}); //ajax
}; //for loop
alert("You have successfully uploaded "+ results.rows.length + " survey results");
tx.executeSql("UPDATE surveypretransfer SET uploaded = '1' WHERE uploaded = '0'");
}; //if statement
}); //tx.execute
});
}, errorCB);
}
Neither of the two alerts fire when loaded on iPad. Works fine on Android and has previously worked on iPad so I can't find what has changed.
UPDATE: Appears that this only applies to WiFi only iPads. All the 3G ones I tested were fine. Figure that!
Config.XML contains app id = "com.mydomain.myapp" (as an example)
URL for upload is "http://customer.mydomain.com/feeds/saveinfo.php?..."
Also added line 'access origin="http://mydomain.com" subdomains="true" '
Still no results. Is anyone seeing/having similar issues? Anyone see my mistake?
For iOS you might want to try <access origin="http://*.mydomain.com" />, as iOS is not documented in the PhoneGap API to support the subdomain property.
If that doesn't solve your issues, you will probably want to look into CORS (Cross Origin Resource Sharing). I had issues trying to do a POST request from my app to a local port on iOS. The W3C has a great article on how to enable CORS that will probably help. I know in my case, the system would attempt to do an OPTIONS request first, and if it didn't work, the whole thing would fail.
Another tool that you will probably find useful (if not now, in the future) is Fiddler. You can set up an iPad to proxy through your desktop, and then you will be able to observe all of the requests going to and from the device. This is how I found the OPTIONS request noted above.

Resources