Browserstack - Not able to use browser.get on mobile devices - selenium

So I am trying to do something very simple yet so hard to understand for me the reason why its not working.
I am using browserstack combined with protractor and it is as simple as adding this to the config:
let SpecReporter = require('mochawesome').SpecReporter;
exports.config = {
baseUrl: 'http://testing.net/',
"browserstackUser": "test",
"browserstackKey": "1234",
multiCapabilities: [
{
os_version: "9.0",
device: "Samsung Galaxy S10 Plus",
real_mobile: false,
browserName: "Android",
project: "Selenium-Test",
build: "Build 1337",
name: "Mobile - Happy Flow"
}
],
mochaOpts: {
reporter: "mochawesome",
timeout: 60000,
},
suites: {
all: 'pages/*.js',
},
framework: 'mocha',
};
and whenever I run the code it starts by:
describe('FIRST TEST', function () {
var EC = protractor.ExpectedConditions;
browser.waitForAngularEnabled(false);
browser.manage().window().maximize();
brwoser.get('http://testing.net/');
}
and it seems to be stuck through here. I was watching the live demo of what is happening and it seems like it doesn't want to open the URL even thought I do have the link which is odd. and I am not sure if I am doing anything wrong for mobile version but yeah.
The problem is I can't open any URL for the phones but works well on desktop

Can you remove browser.manage().window().maximize(); for the mobile code

You can review a sample provided by BrowserStack in the link: https://github.com/browserstack/protractor-browserstack and execute the tests on similar lines

Related

How can I access localStorage of Cordova App via WebdriverIO and Appium?

I'm currently trying to write some automated tests for our cordova app written in Angular.
My current setup is the following:
Versions:
appium: 1.7.2
wdio-appium-service: 0.2.3
webdriverio: 4.11.0
wdio.conf.js
exports.config = {
port: 4723,
logLevel: 'error',
capabilities: [{
platformName: 'Android',
platformVersion: '8.1',
deviceName: 'any',
app: '../cordova_app/platforms/android/app/build/outputs/apk/debug/app-debug.apk',
autoWebview: true,
autoGrantPermissions: true
}],
// specs: ['./tests/spec/**/*.js'],
specs: ['./tests/spec/login.js'],
services: ['appium'],
reporters: ['spec'],
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 90000
}
}
tests/spec/login.js
describe('Language and market choosing process', () => {
beforeEach(() => {
browser.timeouts('implicit', 2000);
});
afterEach(() => {
browser.reload();
});
it('should go through login process', () => {
const selectCountryBtn = $('.fsr-login__market-chooser');
selectCountryBtn.click();
// everything works so far
browser.localStorage('POST', {key: 'test', value: 'test123'});
// Failed: unknown error: call function result missing 'value'
});
});
When I run this test on my Android 8.1 emulator, the test crashes as soon as it reaches the localstorage part with the error:
Failed: unknown error: call function result missing "value"
Error: An unknown server-side error occurred while processing the command.
at localStorage("POST", [object Object]) - index.js:316:3
The localStorage API of WebdriverIO is described here
What am I doing wrong?
I agree that localStorage manipulation is a tricky endeavour to tackle, especially cross-browser, cross-platform, etc. When dealing with application cookies, or local storage, I default to using plain JS commands to achieve my goal.
As such, I would recommend you try the browser.execute() command to manipulate the browser's local storage:
browser.execute("localStorage.setItem('socialMediaRuinsTheWorld', true)");
or
browser.execute((keyName, keyValue) => {
localStorage.setItem(keyName, keyValue);
}, "testing", "theLocalStorage");
Outcome:
Appium API doesn't offer function localStorage.
I think this is your problem. Also if you use 3.4 version, check Appium section, not only Protocol. Native apps don't have same localStorage as browser and you can't access to it easily.

How to skip a test-case file from executing for a particular browser in Protractor

I am using Protractor for writing e2e test cases in Angular using Jasmin.
I am using Saucelab for executing my test cases on Chrome, Firefox, Edge and IE11.
I came across a issue that hover functionality using mouseMove doesen't work in case of IE11 so i want to skip those test-cases for IE11 but thost test must execute for rest 3 browsers.
My protractor.config.js file as below
...
...
multiCapabilities: ([
{
name: "ds-e2e-firefox",
browserName: "firefox",
version: "63"
},
{
name: "ds-e2e-chrome",
browserName: "googlechrome",
version: "70"
},
{
name: "ds-e2e-edge",
browserName: "MicrosoftEdge",
version: "16",
avoidProxy: true
},
{
name: "ds-e2e-ie11",
browserName: "internet explorer",
version: "11",
iedriverVersion: "3.12.0"
}
]).map(cap => Object.assign(cap, {
platform: "Windows 10",
seleniumVersion: SELENIUM_VERSION,
screenResolution: "1920x1080"
}))
};
...
I am open with some other workaround as i am unable to think how to achieve this.
multicapabilities is collection which takes array of capability so you Can try with exclude keyword reserved for ignoring spec files.
{
name: "ds-e2e-ie11",
browserName: "internet explorer",
version: "11",
iedriverVersion: "3.12.0",
exclude: [specfile.js, specfile2.js]
}
One of the ways to approach it is this way
it("Search by name", async () => {
// open home page
await browser.get(params.baseUrl);
let capabilities = await browser.getCapabilities();
let browserName = capabilities.map_.get('browserName');
if (browserName === "chrome") {
// your test goes here
}
});

How to change browser language of webdriverio

I would like to change browser language. but it is not working. default browser language is displayed..
capabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ['--lang=ja']
}
}],
If anyone is still interested in making this work, the WebdriverIO implementation would be:
capabilities: [{
browserName: 'chrome',
'goog:chromeOptions': {
args: [ '--your-args-go-here',
'--like-so',
'--and-so-and-so'
// e.g: '--headless', '--disable-gpu', '--start-fullscreen'
],
prefs: {
'intl.accept_languages': 'ru,RU'
}
}
}]
For the full list of Chromium switches (args array values), click here.
For the full list of Chromium preferences (prefs object properties), click here.
Note: another useful resource (which is always up to date) for Chromium switches is Peter Beverloo's Chromium CLI Switches portal.
Using the above Chrome config in the wdio.conf.js & running an Instagram login test will successfully convert the locale of the page to Russian, as seen below:
could you try this instead?
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
driver = webdriver.Chrome(chrome_options=options)
check on webdriver io how to use add_experimental_option

Error when running Selenium Server via Nightwatch

I'm attempting to run a simple test script. But I receive the following error:
I have my nightwatch config file setup as so:
nightwatch.conf.js
module.exports = {
"src_folders": [
"tests"// Where you are storing your Nightwatch e2e/UAT tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/selenium-standalone/.selenium/selenium-server/2.53.1-server.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": { "webdriver.chrome.driver" : "./node_modules/selenium-standalone/.selenium/chromedriver/2.25-x64-chromedriver"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // set to false to test progressive enhancement
}
}
}
}
guinea-pig.js
module.exports = { // addapted from: https://git.io/vodU0
'Guinea Pig Assert Title': function(browser) {
browser
.url('https://saucelabs.com/test/guinea-pig')
.waitForElementVisible('body')
.assert.title('I am a page title - Sauce Labs')
.saveScreenshot('ginea-pig-test.png')
.end();
}
};
The server path and chromedriver path are accurate and the most recent copy. I also have the latest version of chrome installed. Can someone please help me understand what could be the problem? Thanks!
Edit: I've also restarted the whole computer, same issue.
Try using the latest version of the Selenium standalone server v.3.0.1
If that doesn't work, then you can upgrade your chromedriver to the latest version and test. You can find the different versions here:
https://chromedriver.storage.googleapis.com/index.html
Also make sure you are using the most recent version of Nightwatch v0.9.9 and update it in you package.json file.
It is written very clear , your chrome version is lower than what chromedriver needs, just update your chrome to the latest version

Timeout error when trying to test ionic app with selenium+protractor

Error: Angular could not be found on the page index.html : retries looking for angular exceeded
I'm getting this error after I followed the ionic tutorial for setting up protractor.
Here's my protractor-conf.js:
exports.config = {
capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE (-_-)
'browserName': 'chrome'
},
// chromeDriver: ['./node_modules/protractor/selenium/chromedriver'],
specs: [
// We are going to make this file in a minute
'e2e/specs.js'
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
},
allScriptsTimeout: 20000,
onPrepare: function(){
browser.driver.get('http://localhost:3000');
}
};
I noticed in another tutorial, it had me give it a pointer to the selenium server. Maybe that's the problem?
I added the chromeDriver line in there, but it broke it even more, so I commented it out
Also, I have ionic serve up and running like the tutorial says.
Solved by adding the ionic server address localhost:8100/app to the baseURL property in protractor configuration file