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

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

Related

Nuxt Proxy Issue when deploying using Docker (Github Action)

I am trying to deploy my nuxt app using github actions. I tried to run my app built in docker container at my local environment, but it doesn't work. When I open application using browser,I could check nothing but the background image I set using css.
I believe it might be issue related to proxy or serverMiddleware that I set in nuxt.config.js.
Servermiddleware is for managing session, and proxy server is used to avoid CORS issues when getting data from external api server.
nuxt.config.js
proxy: {
'/api/v1/': {
target: 'http://192.168.219.101:8082',
pathRewrite: {'^/api/v1/cryptolive/': '/'},
changeOrigin: true,
},
}
serverMiddleware: [
// bodyParser.json(),
session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 60000,
},
}),
'~/apis',
],

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.

Ho to run multiple mobile tests on Sauce Labs via 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}`

How to force pull docker images in DC OS?

For docker orchestration, we are currently using mesos and chronos to schedule job runs.
Now, we dropped chronos and try to set it up via DCOs, using mesos and metronome.
In chronos, I could activate force pulling a docker image via its yml config:
container:
type: docker
image: registry.example.com:5001/the-app:production
forcePullImage: true
Now, in DC/OS using metronome and mesos, I also want it to force it to always pull the up-to-date image from the registry, instead of relying on its cached version.
Yet the json config for docker seems limited:
"docker": {
"image": "registry.example.com:5001/the-app:production"
},
If I push a new image to the production tag, the old image is used for the job run on mesos.
Just for the sake of it, I tried adding the flag:
"docker": {
"image": "registry.example.com:5001/my-app:staging",
"forcePullImage": true
},
yet on the put request, I get an error:
http PUT example.com/service/metronome/v1/jobs/the-app < app-config.json
HTTP/1.1 422 Unprocessable Entity
Connection: keep-alive
Content-Length: 147
Content-Type: application/json
Date: Fri, 12 May 2017 09:57:55 GMT
Server: openresty/1.9.15.1
{
"details": [
{
"errors": [
"Additional properties are not allowed but found 'forcePullImage'."
],
"path": "/run/docker"
}
],
"message": "Object is not valid"
}
How can I achieve that the DC OS always pulls the up-to-date image? Or do I have to always update the job definition via a unique image tag?
The Metronome API doesn't support this yet, see https://github.com/dcos/metronome/blob/master/api/src/main/resources/public/api/v1/schema/jobspec.schema.json
As this is currently not possible I created a feature request asking for this feature.
In the meantime, I created workaround to be able to update the image tag for all the registered jobs using typescript and request-promise library.
Basically I fetch all the jobs from the metronome api, filter them by id starting with my app name, and then change the docker image, and issue for each changed job a PUT request to the metronome api to update the config.
Here's my solution:
const targetTag = 'stage-build-1501'; // currently hardcoded, should be set via jenkins run
const app = 'my-app';
const dockerImage = `registry.example.com:5001/${app}:${targetTag}`;
interface JobConfig {
id: string;
description: string;
labels: object;
run: {
cpus: number,
mem: number,
disk: number,
cmd: string,
env: any,
placement: any,
artifacts: any[];
maxLaunchDelay: 3600;
docker: { image: string };
volumes: any[];
restart: any;
};
}
const rp = require('request-promise');
const BASE_URL = 'http://example.com';
const METRONOME_URL = '/service/metronome/v1/jobs';
const JOBS_URL = BASE_URL + METRONOME_URL;
const jobsOptions = {
uri: JOBS_URL,
headers: {
'User-Agent': 'Request-Promise',
},
json: true,
};
const createJobUpdateOptions = (jobConfig: JobConfig) => {
return {
method: 'PUT',
body: jobConfig,
uri: `${JOBS_URL}/${jobConfig.id}`,
headers: {
'User-Agent': 'Request-Promise',
},
json: true,
};
};
rp(jobsOptions).then((jobs: JobConfig[]) => {
const filteredJobs = jobs.filter((job: any) => {
return job.id.includes('job-prefix.'); // I don't want to change the image of all jobs, only for the same application
});
filteredJobs.map((job: JobConfig) => {
job.run.docker.image = dockerImage;
});
filteredJobs.map((updateJob: JobConfig) => {
console.log(`${updateJob.id} to be updated!`);
const requestOption = createJobUpdateOptions(updateJob);
rp(requestOption).then((response: any) => {
console.log(`Updated schedule for ${updateJob.id}`);
});
});
});
I had a similar problem where my image repo was authenticated and I could not provide the necessary auth info using the metronome syntax. I worked around this by specifying 2 commands instead of the directly referencing the image.
docker --config /etc/.docker pull
docker --config /etc/.docker run
I think the "forcePullImage": true should work with the docker dictionary.
Check:
https://mesosphere.github.io/marathon/docs/native-docker.html
Look at the "force pull option".

Resources