Set an item from localStorage in a protractor test - javascript

describe('The feature', function() {
beforeEach(function () {
browser.executeScript('localStorage.setItem("key","value");');
});
it('should do this', function() {
});
});
but i get this error when the test is run against selenium with chromedriver 2.10 and chrome 37
Executing: [execute script: window.localStorage.setItem("key","value");, []])
15:31:29.747 WARN - Exception thrown
org.openqa.selenium.WebDriverException: <unknown>: Failed to read the 'localStorage'
property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: chrome=37.0.2062.120)
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-26-generic x86_64) (WARNING:
The server did not provide any stacktrace information)
Any idea where the problem cam from ?

According to one of the answers at Remove an item from localStorage in a protractor test, this happens when you try to access localStorage without hitting the browser (say, browser.get) first when you are using the Chrome driver. The solution seems to be to hit the browser first (maybe your root page) to get a page loaded in Chrome so that you can manipulate the localStorage. That at least is what I have been doing for our project. Hope this helps!

Related

How to catch user even (click on a button) from windows UWP app while running WinAppDriver (Appium)

I need to catch user even and perform some script after it while driver is running
What I want to solve:
Run auto test on UWP app via WinAppDriver
Perform some steps
Wait for user input
If button clicked -> do script, else user continue using app
import { driver, By2, windowsAppDriverCapabilities } from 'selenium-appium'
const capabilites = windowsAppDriverCapabilities(<WinAppId>);
driver.startWithCapabilities(capabilites, 'http://localhost:4723/wd/hub');
...
let someButton = driver.findElement(By2.nativeXpath("//*/ButtonPosition"))
while (true){
someButton.addEventListener('click', function() {
<somelogic>
})
TypeError: test.addEventListener is not a function
● Test suite failed to run
WebDriverError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: read ECONNRESET

appium-uiautomator2-server-v0.1.8.apk' exited with code 1" while getting badging info

I am trying to learn Appium, using the instructions given in the documentation:
http://appium.io/docs/en/about-appium/getting-started/?lang=en
I have put this code into a file called AppiumTest.js
const wdio = require('webdriverio');
const opts = {
port: 4723,
desiredCapabilities: {
platformName: "Android",
platformVersion: "8.0",
deviceName: "Pixel_API_26",
app: "C:/Users/SStaple/AppData/Local/Android/Sdk/ApiDemos-debug.apk",
automationName: "UiAutomator2"
}
};
const client = wdio.remote(opts);
client
.init()
.click("~App")
.click("~Alert Dialogs")
.back()
.back()
.end();
I am running it from the Node.js command prompt, using the command: node AppiumTest.js, after starting the Appium Server. It was also necessary to have an Android 8 emulator running.
(Appium Server v1.7.1)
I am getting an output in the Appium Server window. There are a number of errors. The first error shown is this:
Error "Command 'C\:\\Users\\SStaple\\AppData\\Local\\Android\\Sdk\\build-tools\\26.0.2\\aapt.exe d badging C\:\\Users\\SStaple\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\node_modules\\appium\\node_modules\\appium-uiautomator2-driver\\uiautomator2\\appium-uiautomator2-server-v0.1.8.apk' exited with code 1" while getting badging info
I have tried running this command on its own in the Command Prompt:
C:\Users\SStaple\AppData\Local\Android\Sdk\build-tools\26.0.2\aapt.exe d badging C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk
The result I get here is this:
W/zipro (13656): Error opening archive C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk: Invalid file
ERROR: dump failed because no AndroidManifest.xml found
Any ideas?
Update 28/12/2017 - I found the solution!
The file in question looked suspect. It was 0Kb in size!
I downloaded the apk file from https://github.com/appium/appium-uiautomator2-server/releases and used that instead.
This one is 1,518 KB in size.
(Apparently there is some problem with npm not putting that apk file into the right place while beta is installed.)
Having fixed that, I can move on to the next problem!
Its a known issue with apk signing.
You can start with trying to update dependencies:
npm install appium-uiautomator2-driver
npm install appium-adb
If it didn't help, there is more you can try (but that was for Linux):
modify
./node-v6.11.4-linux-armv7l/lib/node_modules/appium/node_modules/appium-adb/build/lib/tools/apk-signing.js so it would return a true even if it looks not signed.
case 20:
context$1$0.prev = 20;
context$1$0.t0 = context$1$0’catch’;
_loggerJs2[‘default’].debug(“App not signed with debug cert.”);
return context$1$0.abrupt(‘return’, true);

Appium error: uncaughtException: Cannot read property 'executeAtom' of null

I am doing iOS Mobile Application Testing using Selenium. I am using respectives
Appium version 1.3.7
Node JS version 2.7.5
ios webkit debug proxy
iPhone 5c
Xcode version 6.1
I am using a shell script which is helping me to check the ios_webkit_debug_proxy is available or not. If not exists, within 2 seconds, it will start the ios_webkit_debug_proxy.
My testing is working well. But still facing some problem in appium that Appium is stopped certainly giving an uncaught exception: Cannot read property 'executeAtom' of null
I have tried to solve in various ways.
Restart Appium and run again.
Update the appium version to stable latest version 1.4.0. But the
error is still remaining.
Update the Node JS.
Xcode is always opened in run execution time.
Nullify the implicitly wait before every WebDriverWait happens.
Link: http://chon.techliminal.com/ajax_wait/#/intro
Using java uncaught exception handler in every related class. Link:
https://bharatonjava.wordpress.com/2012/09/04/uncaughtexceptionhandler-in-java/
But still error is remaining. Would you please suggest me how I can solve this problem??
For your better understanding I am attaching the log file below.
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Remote debugger data sent [{"method":"Runtime.evaluate","params":{"objectGroup":"console","includeCommandLineAPI":true,"doNotPauseOnExceptionsAndMuteConsole":true,"expression":"(function(){return function(){function h(a){return...]
Debugger web socket received data : {"result":{"result":{"type":"string","value":"{\"status\":0,\"value\":[]}"},"wasThrown":false},"id":57}
info: [debug] Waited for 7659ms so far
info: --> POST /wd/hub/session/d102c79f-f695-4fbb-a020-45caf2af7b05/context {"name":"NATIVE_APP"}
info: [debug] Attempting to set context to 'NATIVE_APP'
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"d102c79f-f695-4fbb-a020-45caf2af7b05"}
info: POST /wd/hub/session/d102c79f-f695-4fbb-a020-45caf2af7b05/context {"name":"NATIVE_APP"}
info: [debug] Attempting to set context to 'NATIVE_APP'
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"d102c79f-f695-4fbb-a020-45caf2af7b05"}
info: POST /wd/hub/session/d102c79f-f695-4fbb-a020-45caf2af7b05/context 200 0.862 ms - 74 {"status":0,"value":"","sessionId":"d102c79f-f695-4fbb-a020-45caf2af7b05"}
error: uncaughtException: Cannot read property 'executeAtom' of null date=Fri May 22 2015 11:40:38 GMT+0600 (BDT), pid=9153, uid=501, gid=20, cwd=/Applications/Appium.app/Contents/Resources/node_modules/appium, execPath=/Applications/Appium.app/Contents/Resources/node/bin/node, version=v0.12.1, argv=[/Applications/Appium.app/Contents/Resources/node/bin/node, /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/main.js, --command-timeout, 7200, --platform-version, 7.1, --platform-name, iOS, --app, com.bjitgroup.putter, --udid, 0b72ccc692943f83fa2f83e78e8b3030a760fa5f, --device-name, iPhone 5], rss=218198016, heapTotal=187542272, heapUsed=76792360, loadavg=[1.51611328125, 1.689453125, 1.67431640625], uptime=71672, trace=[column=14, file=/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-controller.js,
function=iOSController.executeAtom, line=647, method=executeAtom, native=false, column=10, file=/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-controller.js,
function=, line=311, method=null, native=false, column=13, file=/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/common.js,
function=, line=90, method=null, native=false, column=5, file=/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/common.js,
function=, line=66, method=null, native=false, column=15, file=timers.js, function=Timer.listOnTimeout, line=110, method=listOnTimeout, native=false],
stack=[TypeError: Cannot read property 'executeAtom' of null,
at iOSController.executeAtom (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-controller.js:647:14),
at null. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-controller.js:311:10),
at null. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/common.js:90:13),
at null. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/common.js:66:5),
at Timer.listOnTimeout (timers.js:110:15)]
please follow this link in github. I have got a solution that is happening because of async error.
https://github.com/appium/appium/issues/5177

Node.js Selenium IPv6 Issue (SocketException Protocol family unavailable)

This error only happens when I spawn the ios-driver jar as a Node.js child.
The error is java.net.SocketException: Protocol family unavailable
selenium-test.js:
var spawn = require('child_process').spawn;
var selenium = spawn('java', ['-jar', './ios-server-standalone-0.6.6-SNAPSHOT.jar', '-port', '4444']);
selenium.stderr.setEncoding('utf8');
selenium.stderr.on('data', function (data){
console.log(data);
});
webdriverjs-test.js (webdriverjs)
var webdriverjs = require('webdriverjs');
var options = {
desiredCapabilities: {
browserName: 'safari',
platform: 'OS X 10.9',
version: '7.1',
device: 'iphone'
}
};
webdriverjs
.remote(options)
.init()
.end();
Reproduce this error by creating the above files, running selenium-test.js in one window and webdriverjs-test.js in another window. You will first need to npm install webdriverjs and curl -O http://ios-driver-ci.ebaystratus.com/userContent/ios-server-standalone-0.6.6-SNAPSHOT.jar
Version info:
$ java version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
$ node -v
v0.10.26
Why does this error happen and how do I fix it?
I managed to solve this by making the spawned child ignore stdin:
var selenium = spawn('java', ['-jar', './ios-server-standalone-0.6.6-SNAPSHOT.jar', '-port', '4444'], {stdio: ['ignore', null, null]});
I'm not sure why this workaround works.
I don't have much idea about it, what so far I've found is that this can be binding issue with java. More details is on following link:(It is not the updated information, it may lead to answer)
http://diario.beerensalat.info/2008/10/12/java_and_ipv6_on_bsd.html
If that is not the case, as this post suggests to change it to higher port should work.
"Protocol family unavailable" error while using VisualVM

Karma/Jasmine Tests and dropbox authentication in javascript

I'm attempting to create some tests using Karma and Jasmine for a javascript application that uses the Dropbox Datastore api.
Here is a simplified test using the introductory Dropbox code from https://www.dropbox.com/developers/datastore/tutorial/js
I've manually authorized the application with Dropbox in the browser before running the test, but when I run the test, it says the client is not authenticated and no error occurs. Is there something extra that needs to be done for it to authenticate when running the tests?
'use strict';
describe('dropbox', function () {
var client = null;
beforeEach(function() {
client = new Dropbox.Client({key: '46tjf8x15q98xic'});
// Try to finish OAuth authorization.
client.authenticate({interactive: false}, function (error) {
if (error) {
alert('Authentication error: ' + error);
}
});
});
it('client is not null', function() {
expect( client ).not.toBeNull();
});
it('authenticated is true', function() {
expect( client.isAuthenticated() ).toEqual( true );
});
});
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.9 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 33.0.1750 (Mac OS X 10.9.2)]: Connected on socket BKoS8rqqeeL7fg3cHEQl
Chrome 33.0.1750 (Mac OS X 10.9.2) dropbox authenticated is true FAILED
Expected false to equal true.
Error: Expected false to equal true.
at null.<anonymous> (/Users/davidsmith/Sites/myapp/test/spec/dropbox.js:23:38)
Chrome 33.0.1750 (Mac OS X 10.9.2): Executed 2 of 2 (1 FAILED) (0.301 secs / 0.009 secs)
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
So, to be able to run the tests, I looked at the local storage for my browser and copied my app's dropbox key/value pair.
In my test script, I added that key/value pair with
var value = '{"key":"46tjf8x15q98xic","token":"srMz5w4ReBsAAAAAAAAAAWfQfibrbJfeI7LVKsbMvxRfX1pdpS6SOKqvN6DcgK1B","uid":"1407454"}';
localStorage.setItem('dropbox-auth:default:cHKvNCKVzU7Jmnyaj1InU8TBCOc', value );
Another related problem (not shown above) is that openDefaultDatastore is asyncronous so in my test script I added some code to wait until openDefaultDatastore finishes before running my tests.

Categories

Resources