Ho to run multiple mobile tests on Sauce Labs via Jenkins? - jenkins

I have a problem with run Jenkins job with additional parameters
In my package.json I named a script name with some browser configs like:
"mobile": "npx wdio run ./config/wdio.mobile.conf.js"
I have got a config file with my mobile devices:
exports.config = {
...config,
...{
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
testobject_api_key: process.env.SAUCE_RDC_ACCESS_KEY,
region: 'eu',
specs: [
'./features/*'
],
maxInstances: 1,
capabilities: [{
deviceName: 'Samsung Galaxy S',
automationName: 'UiAutomator2',
platformName: 'Android',
idleTimeout: 180,
cacheId: new Date().getTime(),
noReset: true,
autoGrantPermissions: true,
orientation: 'PORTRAIT',
newCommandTimeout: 180,
build: 'test',
name: 'test',
maxInstances: 1,
}],
services: ['sauce'],
}
}
But instead of hardcoded strings with deviceName etc I want to use some parameters to set any device while running Jenkins job something like:
Additional problem:
How to manage running multiple devices? For example an array of devices at once. (30 devices).
I would appreciate your help

One way to do that is to manipulate env file
On Jenkins side:
creation of Jenkins input with devices
with every run with chosen device add dynamically new node variable to env file with deviceName, automationName and platformName:
echo DEVICE_NAME=${DEVICE_NAME} >> .env
On config side parametrize device capabilities like that:
deviceName: `${process.env.DEVICE_NAME}`
automationName: `${process.env.AUTOMATION_NAME}`
platformName: `${process.env.PLATFORM_NAME}`

Related

Appium capability baseUrl is not working when trying to connect to remote server

I am trying to run my tests with a remote Appium server. Until now, I have always used the server in the same machine where the tests are being run, so I was using url + port (localhost:4723).
The problem I am facing now is that the "baseUrl" capability does not make any change, it seems that it is being ignored. I am using Appium 1.22.3
This is my code:
const url = '88.123.123.23'
const path = '/ws/hub';
const timeout = 20000;
export function createAndroidConfig(port: number, deviceName: string, id: string): RemoteOptions {
const config: RemoteOptions = {
path: path,
port: port,
logLevel: 'trace',
baseUrl: url,
waitforTimeout: timeout,
capabilities: {
udid: id,
automationName: 'UiAutomator2',
platformName: 'Android',
deviceName: deviceName,
autoGrantPermissions: true,
unicodeKeyboard: true,
resetKeyboard: true,
'appium:app': apkPath,
newCommandTimeout: 100000,
unlockType: "pin",
unlockKey: "0000"
}
}
return config;
}
The error I get:
Unable to connect to "http://localhost:4723/ws/hub", make sure browser driver is running on that address.
I have searched for it, thinking it could be an Appium bug, but I did not find information.
If I change the port or path, the changes do take effect, but url does not.
const path = '/ws/hub';
/wd/hub
replace this with

WebdriverIO not using config.path to access Appium Server

I'm trying to get started with appium and successfully connected myself with my device using Appium Server and Appium Inspector (I had to change remote path to /wd/hub). Now, I'm trying to do the same using WebdriverIO using https://github.com/webdriverio/appium-boilerplate
At first I start the appium server:
Now I cloned Appium Boilerplate from https://github.com/webdriverio/appium-boilerplate and ran npm install. Then I changed the path in config/wdio.android.app.conf.ts to '/wd/hub':
import { join } from 'path';
import config from './wdio.shared.local.appium.conf';
// ============
// Specs
// ============
config.specs = [
'./tests/specs/**/app*.spec.ts',
];
// ============
// Capabilities
// ============
// For all capabilities please check
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities
config.capabilities = [
{
// The defaults you need to have in your config
platformName: 'Android',
maxInstances: 1,
// For W3C the appium capabilities need to have an extension prefix
// http://appium.io/docs/en/writing-running-appium/caps/
// This is `appium:` for all Appium Capabilities which can be found here
'appium:deviceName': 'Pixel_3_10.0',
'appium:platformVersion': '10.0',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'UiAutomator2',
// The path to the app
'appium:app': join(process.cwd(), './apps/Android-NativeDemoApp-0.4.0.apk'),
// #ts-ignore
'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
// Read the reset strategies very well, they differ per platform, see
// http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
'appium:noReset': true,
'appium:newCommandTimeout': 240,
},
];
config.path = '/wd/hub';
console.log(config);
exports.config = config;
Now I call npm run android.app, and the console.log command shows me:
{
runner: 'local',
specs: [ './tests/specs/**/app*.spec.ts' ],
capabilities: [
{
platformName: 'Android',
maxInstances: 1,
'appium:deviceName': 'Pixel_3_10.0',
'appium:platformVersion': '10.0',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'UiAutomator2',
'appium:app': '<<removed initially ;-)>>',
'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
'appium:noReset': true,
'appium:newCommandTimeout': 240
}
],
logLevel: 'silent',
bail: 0,
baseUrl: 'http://the-internet.herokuapp.com',
waitforTimeout: 45000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: [ [ 'appium', [Object] ] ],
framework: 'mocha',
reporters: [ 'spec' ],
mochaOpts: { ui: 'bdd', timeout: 180000 },
port: 4723,
path: '/wd/hub'
}
... which seems ok for me, but the Appium server shows:
[HTTP] Waiting until the server is closed
[HTTP] Received server close event
[Appium] Welcome to Appium v1.22.0
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] sessionOverride: true
[Appium] relaxedSecurityEnabled: true
[Appium] allowInsecure: {
[Appium] }
[Appium] denyInsecure: {
[Appium] }
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240}}
[HTTP] No route found for /session
[HTTP] <-- POST /session 404 8 ms - 211
[HTTP]
[HTTP] --> POST /session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240}}
It looks like WebdriverIO doesn't recognize the config.path-setting. I was already checking out Testing Mobile App with Appium & WebdriverIO: "No route found for /session" but the solution was changing the config.path value (which I did) but I've no idea why it's no recognized... Is anyone having any idea?
i just stepped over the same issue and it looks like it works when you set it under the capabilites:
capabilities: [{
"path": "/wd/hub",
...

Cypress setCookie not working with Firefox in a Docker container

I'm using Cypress 7.5.0 and I run my E2E tests in a Docker container based on cypress/browsers:node12.16.1-chrome80-ff73.
The tests have been running on Chrome for a while now.
When trying to execute them on Firefox, I've got the following error :
CypressError: `cy.setCookie()` had an unexpected error setting the requested cookie in Firefox.
When I run the tests locally (outside the Docker container) and use the version of Firefox installed on my computer (Ubuntu 18.04), the same code works fine.
In order to authenticate in my application, I retrieve the following cookies :
[
{
name: 'XSRF-TOKEN',
value: '7a8b8c79-796a-401a-a45e-1dec4b8bc3c3',
domain: 'frontend',
path: '/',
expires: -1,
size: 46,
httpOnly: false,
secure: false,
session: true
},
{
name: 'JSESSIONID',
value: 'B99C6DD2D423680393046B5775A60B1C',
domain: 'frontend',
path: '/',
expires: 1627566358.621716,
size: 42,
httpOnly: true,
secure: false,
session: false
}
]
and then I set them using :
cy.setCookie(cookie.name);
I've tried overriding the cookie details using different combination like :
cy.setCookie(cookie.name, cookie.value, {
domain: cookie.domain,
expiry: cookie.expires,
httpOnly: cookie.httpOnly,
path: cookie.path,
secure: true,
sameSite: 'Lax',
});
but nothing works.
I can't get my head around why it works when run locally and fails when run in a Docker container. Any ideas?
Thank you.

Webpack unable to load module for karma

Tyring to use webpack to bundle my depenedencies to be used in karma spec files. But getting:
Module 'fuse' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Fuse is the name of ng-app.
this same setup works when I run on standard tests, but when I try to: beforeEach(module('fuse')); the app breaks with the above error.
Here is my Karma.conf:
// Karma configuration
var webpackConfig = require('./webpack.dev.config.js');
webpackConfig.entry = {};
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
reporters: ['progress'],
port: 9876,
colors: false,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS', 'Chrome'],
singleRun: false,
autoWatchBatchDelay: 300,
// ... normal karma configuration
files: [
'node_modules/jquery/dist/jquery.js',
'./node_modules/angular/angular.js',
'./node_modules/angular-mocks/angular-mocks.js',
// 'public/app/pages/main/**/*.spec.js',
'../../app.js',
'public/app/services/auth/auth_service.spec.js'
],
preprocessors: {
// add webpack as preprocessor
'../../app.js': ['webpack'],
},
webpack: webpackConfig,
webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
noInfo: true
},
plugins: [
require("karma-webpack"),
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-phantomjs-launcher")
]
});
};
Any idea what is going on? I've tried so many things and am almost out of ideas, will keep trying to reorder the files being loaded.

Rails - Setting up karma with hamlc - getting parse error on hamlcoffee.js.coffee.erb

I'm trying to set up an angular testing environment using Karma, Jasmine, and Phantomjs. It's a rails app using hamlcoffee as template language.
My problem is that when i try to run the tests i get the following error:
PhantomJS 1.9.7 (Linux) ERROR
SyntaxError: Parse error at /home/me/.rvm/gems/ruby-2.1.2/bundler/gems/haml_coffee_assets-a3c2951eca00/vendor/assets/javascripts/hamlcoffee.js.coffee.erb:1
It looks like the file hamlcoffee.js.coffee.erb is the problem here, so i tried adding everything ending with .erb to the exclude list in the karma config file, but unfortunately with no luck.
This is my Karma config file:
// Karma configuration
module.exports = function(config) {
config.set({
// base path, based on tmp/ folder
basePath: '..',
// frameworks to use
frameworks: ['jasmine', 'ng-scenario'],
// list of files / patterns to load in the browser
files: [
APPLICATION_SPEC,
'app/assets/javascripts/*/*.{coffee,js}',
'spec/javascripts/**/*_spec.{coffee,js}',
'app/assets/*.haml'
],
// list of files to exclude
exclude: [
'**/*.erb'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
// Preprocessors
preprocessors: {
'**/*.coffee' : 'coffee',
'app/assets/javascripts/**/*.hamlc' : 'haml'
},
hamlPreprocessor: {
options: {
language: 'coffee'
}
}
});
};
I'm using the karma-haml-preprocessor for my .hamlc templates.

Resources