"Error: no such session" Webdriver-IO, Appium - appium

I have setup Cucumber, Webdriver-IO, and Appium. Everything appears to be talking to each other, however I'm getting Error: no such session when trying to navigate to http://google.com.
On the Android device it opens up the Chrome browser, then closes it really fast.
webdriverio.js
//webdriverio.js
let client = WebDriverIO.remote({
desiredCapabilities: {
platformName: 'Android',
browserName: 'chrome',
deviceName: 'test',
},
host: 'localhost',
port: 4723,
waitForTimeout: 120 * 1000,
});
global.client = client;
module.exports = function() {
this.registerHandler('BeforeFeatures', function(event, done) {
client.init().call(done);
});
this.registerHandler('AfterFeatures', function(event, done) {
client.end().call(done);
});
};
env.js
// env.js
module.exports = function() {
// added because default 50000 ms was long enough
this.setDefaultTimeout(60 * 1000);
};
search_steps.js
// search_steps.js
module.exports = function() {
this.Given('I have visited Google', function (done) {
client
.url('http://google.com')
.call(done);
});
this.When('I search for {arg1:stringInDoubleQuotes}', function (arg1, done) {
// Write code here that turns the phrase above into concrete actions
client
.setValue('input[name="q"]', 'Kittens')
.call(done);
});
this.Then('I see {arg1:stringInDoubleQuotes}', function (arg1, done) {
// Write code here that turns the phrase above into concrete actions
client
.getValue('input[name="q"]').then(function(text){
expect('Kittens').to.eql(text);
})
.call(done);
});
};

The issue is chromedriver 2.21.371459 that is shipped with my version of Appium (1.3.5) for Mac. I downloaded the latest version of chromedriver and overwritten the existing one that is shipped with Appium. See the answer here Chrome opens for a second and the crashes for windows. For mac the location of the chromedriver exec shipped with Appium is. /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac

Related

Electron Deeplink is not working, it does not respond at all with "gotTheLock", unless I run it directly via CMD line calling electron.exe

I've been trying to get deeplinks to work to do oauth for like 4 weeks:
on different boilerplates
on raw quick start of electron
on electron-forge with webpack.
None of them work while in dev mode, and only does while packaged.
I do not understand why it only works if I target command line the electron.exe and pass my app. OR when the app is packaged. If it's in development mode, it simply does not work.
I think? that the gotTheLock runs app.quit(), because in instances where I put the createWindow() outside of the lock if/else function, a window briefly opens and then closes immediately. For some reason it's opening a new instance completely? When createWindow() is inside, I basically see nothing happen.
I'm on Windows, I see nothing about forge that would cause issues or need extra setup in the forge config/package.json since I am on Windows
There's something fundamental flying over my head. Currently, my latest attempt is with the new 6.0 electron-forge from here with the following npm command to generate:
npm init electron-app#latest my-app --template=webpack cd my-app npm start
Here is my "main" which is called index.js here.
index.js
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
app.quit();
}
let mainWindow;
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('electron-fiddle', process.execPath, [path.resolve(process.argv[1])])
}
} else {
app.setAsDefaultProtocolClient('electron-fiddle')
}
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
// and load the index.html of the app.
mainWindow.loadFile(path.join(__dirname, 'index.html'));
// Open the DevTools.
mainWindow.webContents.openDevTools();
};
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
})
app.on('ready', createWindow);
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
ipcMain.on('shell:open', () => {
const pageDirectory = __dirname.replace('app.asar', 'app.asar.unpacked')
const pagePath = path.join('file://', pageDirectory, 'index.html')
shell.openExternal(pagePath)
})
I've tried so many iterations i'm honestly just lost. What's wrong with this that the electron-forge dev mode doesn't like?
As far as any other code is concerned, it's "as-is" from that npm command with the latest 6.0 electron-forge with webpack template. Only the index.js was modified

how to take a screenshot by a locator and then compare with the other locator with the screenshot using appium with webdriverio

how to take a screenshot by a locator and then compare with the other locator with the screenshot(and compare those two images) using appium with webdriverio. I tried looking at a tutorial but not able to find anything that works
You can capture screenshot of an element with webdriver io as mentioned below
it('should save a screenshot of the browser view', function () {
const elem = $('#someElem');
elem.saveScreenshot('./some/path/elemScreenshot.png');
});
you can see more about in on official documentation of webdriver-io
Once you capture screenshot for both element then you can use Visual Regression service for WebdriverIO V5 called wdio-image-comparison-service.
Installation:
Install this module locally with the following command to be used as a (dev-)dependency:
npm install --save-dev wdio-image-comparison-service
Instructions on how to install WebdriverIO can be found here.
Usage:
wdio-image-comparison-service supports NodeJS 8 or higher
Configuration:
wdio-image-comparison-service is a service so it can be used as a normal service. You can set it up in your wdio.conf.js file with the following:
const { join } = require('path');
// wdio.conf.js
exports.config = {
// ...
// =====
// Setup
// =====
services: [
['image-comparison',
// The options
{
// Some options, see the docs for more
baselineFolder: join(process.cwd(), './tests/sauceLabsBaseline/'),
formatImageName: '{tag}-{logName}-{width}x{height}',
screenshotPath: join(process.cwd(), '.tmp/'),
savePerInstance: true,
autoSaveBaseline: true,
blockOutStatusBar: true,
blockOutToolBar: true,
// ... more options
}],
],
// ...
};
Writing tests to compare screenshot of 2 elements:
describe('Example', () => {
beforeEach(() => {
browser.url('https://webdriver.io');
});
it('should save some screenshots', () => {
// Save an element
browser.saveElement($('#element-id'), 'firstButtonElement', { /* some options*/ });
});
it('should compare successful with a baseline', () => {
// Check an element
expect(browser.checkElement($('#element-id'), 'firstButtonElement', { /* some options*/ })).toEqual(0);
});
});
Referenec: Please check all details about image comparison here

google cloud speech not working in electron package

When I run the application from command prompt using npm start command it works well. It returning the result from speech api.
I am using binaryServer and binaryclient to stream audio to google cloud API.
When I create package for electron application everything works but it not returning the result from speech api.
Here are my code snippe:
Package.json
{
"name": "test",
"version": "1.0.0",
"description": "test Web Server",
"main": "main.js",
"scripts": {
"start": "electron main.js"
},
"devDependencies": {
"electron": "^1.4.12"
},
"dependencies": {
"binaryjs": "^0.2.1",
"connect": "^3.3.4",
"biased-opener": "^0.2.8",
"serve-static": "^1.9.1",
"uaparser": "^0.0.2",
"#google-cloud/speech" : "^0.5.0"
}
}
Here is my main.js
app.on('ready', function () {
load_app();
});
var workerProcess = child_process.spawn('node', __dirname + '/binaryServer.js');
workerProcess.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
workerProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
workerProcess.on('close', function (code) {
console.log('child process exited with code ' + code);
});
processes.push(workerProcess);
function load_app () {
// Launches the browser window
mainWindow = new BrowserWindow({ width: 1080, height: 1920 });
// Load just launched server in browser window
mainWindow.loadURL("http://localhost:" + config.port);
if (config.devMode) {
mainWindow.webContents.openDevTools();
}
else {
mainWindow.setFullScreen(true);
}
}
here is my binary server
var binaryServer = require('binaryjs').BinaryServer,
https = require('http'),
connect = require('connect'),
serveStatic = require('serve-static');
var config = require('./config');
var server = connect()
.use(serveStatic(__dirname));
var speech = require('#google-cloud/speech')({
projectId: config.speech.projectId,
keyFilename: config.speech.keyFilename
});
httpServer = https.createServer(server);
httpServer.timeout = 0;
httpServer.listen(config.port);
var binarySer = binaryServer({ server: httpServer });
console.log("server pid" + process.pid);
binarySer.on('connection', function (client) {
console.log("new connection...");
client.on('stream', function (stream, meta) {
var options = {
config: {
encoding: 'LINEAR16',
sampleRate: meta.sampleRate,
languageCode: "en-IN"
},
singleUtterance: false,
interimResults: true,
verbose: true
};
// Create a recognize stream
const recognizeStream = speech.createRecognizeStream(options)
.on('error', console.error)
.on('data', function (data) { if (stream.writable && !stream.destroyed) stream.write(data) }); // send data to client
if (recognizeStream.writable && !recognizeStream.destroyed && stream.readable && !stream.destroyed)
stream.pipe(recognizeStream); // pipe audio to cloud speech
});
client.on('close', function () {
console.log("Connection Closed");
});
});
Thanks for your help
Taking a shot in the dark here (without much familiarity with binaryServer, which realistically could be the issue). I'm also a bit unclear about where the audio stream actually comes from:
Electron packages its own version of V8. When you run npm install it will install (or compile on the fly) the native binaries targeted for the version of V8 that are installed on your machine (local version). When you spawn the child process it uses that same local version.
However, when you package your electron app it will try to spawn the process with Electron's version of V8 and there will be binary incompatibilities.
Put simply
[Your version of V8] != [Electron's version of V8]
On to potential solutions
Sonus is compatible with
Electron provided that you
Re-compile dependencies with
electron-recompile

Appium can not test iOS Application "The URL '/' did not map to a valid resource"

Hi I am trying to test iOS application using Appium. I am getting following message in browser when I try to open this link http://127.0.0.1:4723/
"The URL '/' did not map to a valid resource"
Further information:
Appium Version 1.5.3
Appium acts like a server which hosts your iOS Application. You can write your tests in java or java script for writing tests I used intern Runner and configuration of intern.js is below
tunnel: 'NullTunnel',
tunnelOptions: {
hostname: 'localhost',
port: 4444
},
'capabilities': {
'selenium-version': '2.48.0',
'idle-timeout': 60,
'defaulTimeout':60,
'chromeOptions': {'args':['allow-ra-in-dev-mode']}
},
'environments': [
{browserName: 'chrome'},
],
Then you can write your own iOS test in iOSTest.js
'use strict';
define([
'intern!object',
'intern/chai!assert',
'intern/dojo/node!underscore'],
function(registerSuite,assert,_) {
//set server configurations
registerSuite({
'name': 'iOS CoApp Testing',
'setup': function() {
},
'teardown': function() {
// executes after suite ends;
// can also be called `after` instead of `teardown`
},
'beforeEach': function(test) {
},
'afterEach': function(test) {
// executes after each test
},
'simple test': function() {
// it finds text field and insert 124 in it
.findByXpath
("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]")
.click()
.pressKeys('124')
.end()
//it finds Button and clicks it
.findByXpath
("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")
.click()
.end()
}
});
});

Appium ios automation nodejs scripts

I am trying to automate an iOS native app on a real device using Appium(from terminal) and nodejs script. I am able to install and launch the app till the first screen of the app but after that no nodejs scripts other than sleep is getting executed. I need to type in some text in the the textfields present in the screen but the cursor is getting pointed and nothing happens after that. Please tell me whether I am using the correct nodejs commands here.
NB:The same nodejs script was working fine for android automation
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var capture = require("capture");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host, port, username, accessKey, desired;
console.log("Print 1");
var desired = {
'browserName': '',
'automationName': 'Appium',
'platformName': 'iOS',
'platformVersion': '6.1.4',
'deviceType':'iPhone',
'deviceName' :'xxx’s iPhone',
// 'nativeInstrumentsLib' : 'true',
'app': "/Users/Desktop/xxx_my_appname-358.ipa",
'bundleId': 'com.xxx.myapp',
'deviceOrientation': 'portrait'
};
host = "localhost";
port = 4723;
// Instantiate a new browser session
var browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser.init(desired)
// then(function () {
browser
// yield.elementByName("userNameTextField").click()
.sleep(30000) // **** WORKING FINE**
.elementByName('User Id').type('userID') // ** NOT WORKING **
.elementByName('Next').click() // ** NOT WORKING **
.elementByName('Password').type('password') // ** NOT WORKING *
.sleep(30000) // **** WORKING FINE**
.fin(function () {
return browser
.sleep(30000)
.quit()
console.log("inside click");
// });
})
.catch(function (err) {
console.log(err);
console.log("Entering into error Catch...")
throw err;
})
.done();
Try using the Appium app inspector to get the xpath of the elements:
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]").sendKeys("userID")
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]").sendKeys("password")

Resources