appium safari ios gives error: The environment unavailable - appium

I run appium iphone test with command mocha ios-safari.js and it gives error:
The environment you requested was unavailable
Where ios-safari.js is example downloaded from appium samples:
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("ios safari", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").ios81);
desired.browserName = 'safari';
if (process.env.SAUCE) {
desired.name = 'ios - safari';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should get the url", function () {
return driver
.get('https://www.google.com')
.sleep(1000)
.waitForElementByName('q', 5000)
.sendKeys('sauce labs')
.sendKeys(wd.SPECIAL_KEYS.Return)
.sleep(1000)
.title().should.eventually.include('sauce labs');
});
it("should delete cookie passing domain and path", function () {
var complexCookieDelete = function(name, path, domain) {
return function() {
path = path || '|';
return driver.setCookie({name: name, value: '', path: path,
domain: domain, expiry: 0});
};
};
return driver
.get('http://en.wikipedia.org')
.waitForElementByCss('.mediawiki', 5000)
.allCookies() // 'GeoIP' cookie is there
.deleteCookie('GeoIP')
.allCookies() // 'GeoIP' is still there, because it is set on
// the .wikipedia.org domain
.then(complexCookieDelete('GeoIP', '/', '.wikipedia.org'))
.allCookies() // now 'GeoIP' cookie is gone
.sleep(1000);
});
});
The appium log is the following:
info: [debug] Error: Could not find a device to launch. You requested
'iPhone 6 (8.1 Simulator)',
but the available devices were: [
"iPad 2 (8.3 Simulator) [2F86D724-B8D6-4F22-B5E8-97B437C9ACFB]",
"iPad Air (8.3 Simulator) [8A07B826-AF59-4FC4-BC8E-21B37ADAF539]",
"iPad Retina (8.3 Simulator) [9C589CB6-1CF4-437E-83DB-1270DB1599FC]",
"iPhone 4s (8.3 Simulator) [31F567A4-5346-4E1A-B414-C45062105964]",
"iPhone 5 (8.3 Simulator) [E820B152-B5B4-4A79-B9DE-3A1F49859662]",
"iPhone 5s (8.3 Simulator) [5A07EBE7-264A-4571-BA9E-1F17C882ADE3]",
"iPhone 6 (8.3 Simulator) [58856942-BD3F-45C6-9B1B-93102851B37E]",
"iPhone 6 Plus (8.3 Simulator)
Since I recenlty have updated X code to last version seemingly I should change device name somewhere in config from iPhone 6 (8.1 Simulator) to iPhone 6 (8.3 Simulator) [58856942-BD3F-45C6-9B1B-93102851B37E]. But where exactly should I do this - cannot figure out.

You specify the target device when you start an Appium session. On the command line, use '--device-name' parameter. In the Appium UI, you specify which device you want there in the iOS tab. I've found it to be a bit finicky about the name. I've had the most success being as general as necessary to differentiate between devices. IOW, try 'iPhone 6' or 'iPhone 5 (8.3 simulator)' instead of the entire string.

Related

Flutter (IOS) SqfliteDatabaseException: DatabaseException(open_failed only on IOS 16.2

After upgrading to IOS 16.2 getting below exception when trying to access database.
on IOS version 16.1 and below everything works fine.
SqfliteDatabaseException: DatabaseException(open_failed /var/mobile/Containers/Data/Application/494EB596-3835-462C-8164-2B773A19A1C4/Documents/main.db)
File "exception_impl.dart", line 11, in wrapDatabaseException
File "database_mixin.dart", line 737, in SqfliteDatabaseMixin.openDatabase
File "database_mixin.dart", line 839, in SqfliteDatabaseMixin.doOpen
File "database.dart", line 46, in SqfliteDatabaseOpenHelper.openDatabase
File "factory_mixin.dart", line 110, in SqfliteDatabaseFactoryMixin.openDatabase.\<fn\>
...
20 additional frame(s) were not displayed)
Platform: IOS
IOS version: 16.2
Device: iPhone 13 pro max.
flutter: 3.3.3
Code: databaseFactory.openDatabase(path, options: options);
Plugin: sqflite
On first launch this exception is thrown, but if I close app and relaunch it then it works fine.
I checked if database exists also I added additional catch to get database path from both path_provider and sqflite plugin.
var documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "main.db");
try
{
await databaseFactory.openDatabase(path, options: options);
} catch(_) {
try
{
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'main.db');
return await databaseFactory.openDatabase(path, options: options);
} catch(e, stackTrace){
reportException(e, stackTrace);
}
}

karate mobile testing with a real device, not an emulator. I can't connect to a real device

#android_sample_test
Feature: Simple test with appium
Scenario: launch chrome in appium
* configure driver =
"""
{
type: 'android',
webDriverPath : "/wd/hub",
start: true,
httpConfig : { readTimeout: 120000 }
}
"""
* def desiredConfig =
"""
{
"app":"/home/yabesh/Downloads/UiDemo.apk",
"newCommandTimeout" : 300,
"platformVersion" : "9.0",
"platformName" : "Android",
"connectHardwareKeyboard" : true,
"deviceName" : "emulator-554",
"avd": "Galaxy_Nexus_API_33",
"automationName" : "UiAutomator2",
}
"""
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)"} }
* delay(5000).screenshot()
* delay(2500)
* close()
This is my test case for android. It works in android emulator. It works on avd not adb. I don't know how to connect a real device through (usb debugging or wifi debugging). Need help

All storyboard, xib file don't update the frame or constraint on Macbook Pro M1 with rosetta (Encountered an error communicating with IBAgent-iOS)

I try to add constraint or load some of the storyboards or XIB files in my project but the storyboard doesn't update and can't see anything.
This is my error screen capture:
In the first picture, the label is shown in the simulator but the storyboard doesn't.
In the second picture, The .xib file can't load any UI items
This is my error log:
=================================
DATE:
=================================
Monday, 21 December 2020 at 14:22:27 Japan Standard Time 2020-12-21
05:22:27 +0000
=================================
XCODE VERSION INFO:
=================================
Version = 12.3 (12C33) Plugin Version = 17701 Beta Version = 1 OS
Version = 11.1 (20C69)
=================================
ERROR:
=================================
Encountered an error communicating with IBAgent-iOS. (Failure reason:
IBAgent-iOS (-1) failed to launch): Failed to launch IBAgent-iOS via
CoreSimulator spawn (Failure reason: Failed to spawn IBAgent-iOS on
iPhone 12 Pro Max (D81D1F57-170A-4089-843E-1D1E58B049C6, iOS 14.3,
Booted)): Invalid device state
Error Domain=com.apple.InterfaceBuilder Code=-1 "Encountered an error
communicating with IBAgent-iOS."
UserInfo={NSLocalizedFailureReason=IBAgent-iOS (-1) failed to launch,
NSUnderlyingError=0x7fea6c306aa0 {Error
Domain=com.apple.CoreSimulator.SimError Code=405 "Failed to launch
IBAgent-iOS via CoreSimulator spawn"
UserInfo={NSLocalizedFailureReason=Failed to spawn IBAgent-iOS on
iPhone 12 Pro Max (D81D1F57-170A-4089-843E-1D1E58B049C6, iOS 14.3,
Booted), NSLocalizedDescription=Failed to launch IBAgent-iOS via
CoreSimulator spawn, NSUnderlyingError=0x7fea689e0de0 {Error
Domain=com.apple.CoreSimulator.SimError Code=405 "Invalid device
state" UserInfo={NSLocalizedDescription=Invalid device state}}}},
NSLocalizedRecoverySuggestion=Please check Console.app for crash
reports for "IBAgent-iOS" for further information.,
NSLocalizedDescription=Encountered an error communicating with
IBAgent-iOS.}
=================================
TOOL DESCRIPTION:
=================================
<IBCocoaTouchPlatformToolDescription: 0x7feaaba355a0> { |
targetRuntime.identifier: IBCocoaTouchFramework-fourteenAndLater |
_roleString: System content | deviceTypeDescription: <IBSimulatorDeviceTypeDescription: 0x7fea6a16c000>
deviceType=com.apple.CoreSimulator.SimDeviceType.iPhone-12-Pro-Max }
=================================
LAUNCH CONTEXT:
=================================
<IBCocoaTouchToolLaunchContext: 0x7fea6c3fbbb0> { |
toolDescription.ib_verboseDescription:
<IBCocoaTouchPlatformToolDescription: 0x7feaaba355a0> { | |
targetRuntime.identifier: IBCocoaTouchFramework-fourteenAndLater | |
_roleString: System content | | deviceTypeDescription: <IBSimulatorDeviceTypeDescription: 0x7fea6a16c000>
deviceType=com.apple.CoreSimulator.SimDeviceType.iPhone-12-Pro-Max | }
| launchPath:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays/IBAgent-iOS
| frameworkSearchPaths: (
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks"
) | toolName: IBAgent-iOS | platformName: iphonesimulator |
applicationTool: 0 | processIdentifier: -1 | exitStatus: (null) |
signalStatus: (null) }
=================================
EXECUTION CONTEXT:
=================================
<IBSimulatorToolCoreSimulatorBootedCLIExecutionContext: 0x7fea6c11b010
busyCount=0, Idle for 0.0 secs> { | device: iPhone 12 Pro Max
(D81D1F57-170A-4089-843E-1D1E58B049C6, iOS 14.3, Booted) }
=================================
DEVICE:
=================================
iPhone 12 Pro Max (D81D1F57-170A-4089-843E-1D1E58B049C6, iOS 14.3,
Booted)
=================================
TOOL MANAGER:
=================================
<IBCocoaTouchToolManager: 0x7fea6a150100>
=================================
REASON FOR REQUESTING TOOL:
=================================
Preflighting tools for opening document <IBStoryboardDocument:
0x7fea69139a00>: <IBCocoaTouchTargetRuntime: 0x7fea6a1525d0>
=================================
XCODE BACKTRACE:
=================================
0 +[IBPlatformToolFailureHandler
failureHandlerWithContext:failure:diagnosticsHandlerBlock:] (in
IDEInterfaceBuilderKit) 1
+[IBAbstractInterfaceBuilderPlatformToolManager _THREADSAFE_injectDiagnosticsHandlerWithFailureContext:intoError:forLaunchingToolWithError:]
(in IDEInterfaceBuilderKit) 2
+[IBAbstractInterfaceBuilderPlatformToolManager _THREADSAFE_launchNewToolWithLaunchContext:executionContext:toolProxyClass:proxyDelegate:failureContext:requestingMethod:error:forReason:]
(in IDEInterfaceBuilderKit) 3
__117-[IBAbstractInterfaceBuilderPlatformToolManager asyncLaunchNewToolWithDescription:queue:completionHandler:forReason:]_block_invoke.429
(in IDEInterfaceBuilderKit) 4 _dispatch_call_block_and_release (in
libdispatch.dylib) 5 _dispatch_client_callout (in
libdispatch.dylib) 6 _dispatch_lane_serial_drain (in
libdispatch.dylib) 7 _dispatch_lane_invoke (in libdispatch.dylib)
8 _dispatch_workloop_worker_thread (in libdispatch.dylib) 9
_pthread_wqthread (in libsystem_pthread.dylib) 10 start_wqthread (in libsystem_pthread.dylib)
=================================
SDKS:
=================================
Simulator - watchOS 7.2 (watchsimulator7.2): version = 7.2 platform =
com.apple.platform.watchsimulator versionInfo = {
BuildID = "8D9D1CD2-32F3-11EB-B18E-209C67F7BDAB";
ProductBuildVersion = 18S561;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Watch OS";
ProductVersion = "7.2"; }
Simulator - watchOS 7.2 (watchsimulator7.2): version = 7.2 platform =
com.apple.platform.watchsimulator versionInfo = {
BuildID = "8D9D1CD2-32F3-11EB-B18E-209C67F7BDAB";
ProductBuildVersion = 18S561;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Watch OS";
ProductVersion = "7.2"; }
tvOS 14.3 (appletvos14.3): version = 14.3 platform =
com.apple.platform.appletvos versionInfo = {
BuildID = "E3F85AF8-32C4-11EB-9F1B-1F54C5D7F887";
ProductBuildVersion = 18K559;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Apple TVOS";
ProductVersion = "14.3"; }
Simulator - iOS 14.3 (iphonesimulator14.3): version = 14.3 platform =
com.apple.platform.iphonesimulator versionInfo = {
BuildID = "88F866D8-32D9-11EB-997E-99E30E3CEA69";
ProductBuildVersion = 18C61;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "iPhone OS";
ProductVersion = "14.3"; }
Simulator - tvOS 14.3 (appletvsimulator14.3): version = 14.3 platform
= com.apple.platform.appletvsimulator versionInfo = {
BuildID = "E3F85AF8-32C4-11EB-9F1B-1F54C5D7F887";
ProductBuildVersion = 18K559;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Apple TVOS";
ProductVersion = "14.3"; }
watchOS 7.2 (watchos7.2): version = 7.2 platform =
com.apple.platform.watchos versionInfo = {
BuildID = "8D9D1CD2-32F3-11EB-B18E-209C67F7BDAB";
ProductBuildVersion = 18S561;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Watch OS";
ProductVersion = "7.2"; }
Simulator - tvOS 14.3 (appletvsimulator14.3): version = 14.3 platform
= com.apple.platform.appletvsimulator versionInfo = {
BuildID = "E3F85AF8-32C4-11EB-9F1B-1F54C5D7F887";
ProductBuildVersion = 18K559;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Apple TVOS";
ProductVersion = "14.3"; }
macOS 11.1 (macosx11.1): version = 11.1 platform =
com.apple.platform.macosx versionInfo = {
ProductBuildVersion = 20C63;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = macOS;
ProductUserVisibleVersion = "11.1";
ProductVersion = "11.1";
iOSSupportVersion = "14.3"; }
iOS 14.3 (iphoneos14.3): version = 14.3 platform =
com.apple.platform.iphoneos versionInfo = {
BuildID = "88F866D8-32D9-11EB-997E-99E30E3CEA69";
ProductBuildVersion = 18C61;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "iPhone OS";
ProductVersion = "14.3"; }
watchOS 7.2 (watchos7.2): version = 7.2 platform =
com.apple.platform.watchos versionInfo = {
BuildID = "8D9D1CD2-32F3-11EB-B18E-209C67F7BDAB";
ProductBuildVersion = 18S561;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Watch OS";
ProductVersion = "7.2"; }
iOS 14.3 (iphoneos14.3): version = 14.3 platform =
com.apple.platform.iphoneos versionInfo = {
BuildID = "88F866D8-32D9-11EB-997E-99E30E3CEA69";
ProductBuildVersion = 18C61;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "iPhone OS";
ProductVersion = "14.3"; }
macOS 11.1 (macosx11.1): version = 11.1 platform =
com.apple.platform.macosx versionInfo = {
ProductBuildVersion = 20C63;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = macOS;
ProductUserVisibleVersion = "11.1";
ProductVersion = "11.1";
iOSSupportVersion = "14.3"; }
tvOS 14.3 (appletvos14.3): version = 14.3 platform =
com.apple.platform.appletvos versionInfo = {
BuildID = "E3F85AF8-32C4-11EB-9F1B-1F54C5D7F887";
ProductBuildVersion = 18K559;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "Apple TVOS";
ProductVersion = "14.3"; }
Simulator - iOS 14.3 (iphonesimulator14.3): version = 14.3 platform =
com.apple.platform.iphonesimulator versionInfo = {
BuildID = "88F866D8-32D9-11EB-997E-99E30E3CEA69";
ProductBuildVersion = 18C61;
ProductCopyright = "1983-2020 Apple Inc.";
ProductName = "iPhone OS";
ProductVersion = "14.3"; }
DriverKit 20.2 (driverkit.macosx20.2): version = 20.2 platform =
com.apple.platform.macosx versionInfo = { }
Please help me.
I fixed this by not using Rosetta.
Not using Rosetta. It worked for me. But the Cocoapods need to use Rosetta on Macbook Pro M1. This drives me crazy. Hope this will be fixed in next Xcode release.
To solve the problem on Apple Silicon:
With Rosetta enabled, just add arm64 in the excluded architectures on any iOS Simulator SDK in Build Setting section and build the project.
Then close Xcode, disable Rosetta and re-open Xcode.
Please relaunch Xcode and clean build everything. It worked for me.
Close the simulator app.
Restart xcode.
Run.
If the problem persists, "erase content and settings" on the used sim.
Make sure the latest Xcode version is installed. Make sure the version of the used command line tools fits the used X code version (Xcode preferences).

get device uuid ionic ios app

In my app i want to get the device uuid or udid so that i can save it in my database.
for my android app when i run this code in my js file
.factory('Service', function($state) {
var service = {
login: function(user, new_device_status) {
if(window.cordova) {
var params = {
organization: user.orgCode.$modelValue,
email: user.email.$modelValue,
password: user.password.$modelValue,
device_uuid: window.device.platform == 'Android' ? window.device.uuid : window.device.udid,
new_device: new_device_status
};
}
}
}
})
it works and returns the uuid of the device but in my ios app when i try this it doesnt work or when i try
window.device.udid
it still doesnt work in my ios simulator. what can i do?
Solution 1 :
Add device plugin :
cordova plugin add org.apache.cordova.device
In your controller :
module.controller('MyCtrl', function($scope, $cordovaDevice) {
var uuid = $cordovaDevice.getUUID();
});
Answer from : How to get the device UUID in ionic framework
Solution 2 :
Use IDFVPlugin :
cordova plugin add https://github.com/jcesarmobile/IDFVPlugin.git
In your controller :
window.IDFVPlugin.getIdentifier(function(result){
alert(result);
},function(error){
alert(error);
});
Sources :
https://github.com/jcesarmobile/IDFVPlugin
http://forum.ionicframework.com/t/how-to-get-iphone-unique-id-udid-in-ionic-framework-script/9575
I hope it will help you.
but be aware, the UUID is not the same thing as the UDID.
Differences between UDID and UUID
the UUID is the app specific id that changes when you remove the app or update it sometimes even, and the UDID is the unique id from the phone itself.

How do I detect what iOS device my function tests are running on?

I currently have a number of function tests written in javascript using Apple's UIAutomation API. The tests are written for iPhone, but the application also supports the iPad.
To extend my tests to run on an iPad I need to make some adjustments in the code, but first I need to find out what device is running the tests.
How do I detect what device/simulator is running the tests? when I'm running the javascript tests from the Automation tool.
UIATarget.localTarget().model() holds the information about which device the tests are running on.
I have discovered Alex Vollmer's tuneup_js library. It allows for device independent code to some extent as least.
e.g.)
test("my test", function(target, app) {
assertWindow({
"navigationBar~iphone": {
leftButton: { name: "Back" },
rightButton: { name: "Done" }
},
"navigationBar~ipad": {
leftButton: null,
rightButton: { name: "Cancel" }
},
});
});
edit
Found the following in tuneup_js:
/**
* A convenience method for detecting that you're running on an iPad
*/
isDeviceiPad: function() {
return this.model().match(/^iPad/) !== null;
},
/**
* A convenience method for detecting that you're running on an
* iPhone or iPod touch
*/
isDeviceiPhone: function() {
return this.model().match(/^iPhone/) !== null;
}
With these I'll be able to write device specific code.
Follow the documentation provided here, you will get all the information:
https://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIATargetClassReference/UIATargetClass/UIATargetClass.html
//Here is the script I am using to get the device name, os version, bundle id, target etc..
#import "tuneupjs/Utilities.js"
var target = UIATarget.localTarget();
var app_bundle_id = target.frontMostApp().bundleID();
UIALogger.logDebug("App Bundle Id : " + app_bundle_id);
if(app_bundle_id.strContains("ShazamDev"))
UIALogger.logDebug("Running UIA Scripts for ShazamDev");
var device_name = target.name();
UIALogger.logDebug("Phone Name : " + target.name());
var device_model = target.model();
UIALogger.logDebug("Device Model: " + device_model);
//UIALogger.logDebug("System Name: " + target.systemName());
var ios_version = target.systemVersion();
UIALogger.logDebug("IOS Version: " + ios_version);
Here is the code for StrContains method in my Utilities file
String.prototype.strContains = function(value, ignorecase) {
if (ignorecase) {
return (this.toLowerCase().indexOf(value.toString().toLowerCase()) != -1);
}
else {
return this.indexOf(value) != -1;
}
};

Resources