Protractor - log type 'performance' not found error - protractor

webdriver-manager 12.1.5
protractor Version 5.4.2
Chrome version 75.0.3770.100
browser.manage().logs().get('performance');
This used to work fine before upgrading my webdriver-manager and protractor version.
(node:27715) UnhandledPromiseRejectionWarning: WebDriverError: invalid argument: log type 'performance' not found
(Session info: chrome=75.0.3770.100)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info:, os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.4', java.version: '1.8.0_191'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:546:15)
If I comment the browser.manage().logs().get('performance'); and other performance related code, then the test runs fine.
webdriver-manager logs show:
Starting ChromeDriver 75.0.3770.90 on port 12268

I came across a potential solution on this github issue thead. Apparently recently chromedriver has started to more strictly adhere to W3C standards and this has affected how webdriver activates logs.
We can get around this issue by setting the w3c: false flag in chromeoptions like so.
capabilities: {
browserName: 'chrome',
loggingPrefs: {
browser: 'ALL',
driver: 'ALL',
performance: 'ALL',
},
'goog:chromeOptions': {
perfLoggingPrefs: {
enableNetwork: true,
},
w3c: false,
},
},

New version might not support performance log type. You can always use getAvailableLogTypes function to check supported log types. I tried following code
var supportedLogTypes = await browser.manage().logs().getAvailableLogTypes();
received ouptput :
It means you can only use either of two supported log types.

I tried out the same thing with chrome 75.* and protractor 5.4.2 version. Following are my findings.
loggingPrefs object is one of the recognized capabilities like chromeOptions. This object allow us to decide preferences on logging part. Refer link for more details about capabilities.
In protractor context we have to pass loggingPrefs object to capabilities to enable it.
Once we pass it then we can use browser.manage().logs().get('performance'); to get all performance logs.
If you want to change perfLoggingPrefs then it is part of chromeOptions object and it has to be updated there. If we want to use default then no need to mention.

chrome use more strictly rule for w3c, when I test chrome driver 96, set w3c to false, I can get network log, but find_element failed and return dict value which is not WebElement

Related

ReferenceError: driver is not defined in Protractor

I'm a beginner. Can any one guide me?
Tests.js
describe("Test the calculator",()=>{
it("Addition functionality",function test(){
driver.browser.get("https://juliemr.github.io/protractor-demo/");
browser.manage().window().maximize();
//browser.manage().timeouts().implicitlyWait(3000)
})
})
Config.js
const driver= require("protractor")
exports.config= {
browserName: 'chrome',
framework: "mocha",
directconnect: true,
specs: ['./tests.js'],
mochaOpts: {
timeout: 0
}
}
At run time it display a message as "driver is not defined"
Chrome version: 83.0.4103.61 (Official Build) (64-bit)
Visual Studio code: 1.45.1
I see what's going on...
first of all, don't call protractor a driver. Don't confuse others and most importantly yourself. Protractor is protractor, period.
second, when you do const driver= require("protractor") your driver variable is available in conf.js, but when you call it from the spec, it's not there, because it's a local variable, not global. As simple as that, this is why you get this error
Third, you don't need to define protractor because it is a global variable, and is available anywhere in your project anyways. The same with browser, element, $, $$ they all are available globally in your project.
Fourth, lets assume for whatever GOOD reason you still want to define something that will be globally available just do global.driver = require('protractor') as described here https://stackoverflow.com/a/31208642/9150146, and then you can call by typing the variable name driver

An element could not be located on the page using the given search parameters (Appium 1.13.0)

I am working on Automation for Android App. While running the script, Appium unable to find the elements. I tried using Id, Xpath. Please help me with this...
Android version: 5.1.1 & 9
Appium Version: 1.13.0
Maven Project
#Test
public void login() {
driver.findElement(By.xpath("//com.vehito.vehitoplus[contains(#resource-id,'phone')]")).sendKeys("9632642105");
driver.findElement(By.id("com.vehito.vehitoplus:id/sign_in_button")).click();
}
Actual Result:
Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters
This error said that UIAutomator couldn't able to find that Element.
I found 2 problem with your Xpath code:
1- Replace , with = after resource-id.
2- You use packageName (com.vehito.vehitoplus) instead of the class name.
You can find the exact class name of the element with UIAutomator Viewer:
(Android SDK Dir)\tools\bin\uiautomatorviewer.bat
I mean you may use this: (If the element's class name be: android.widget.EditText )
driver.findElement(By.xpath("//android.widget.EditText[contains(#resource-id='phone')]")).sendKeys("9632642105");
In my experience, I found that By. library (XPath or ID) is not working well with #contains. So it's better if you use exact attributes.
e.g.
driver.findElement(By.id("com.vehito.vehitoplus:id/sign_in_button")).sendKeys("9632642105");
I hope this helps. If not, please provide a screenshot from the page and also UIAutomator viewer screenshot of this input element.
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: C:\Selenium\workspace\Ninja..., appPackage: com.ninjafocus.app, appactivity: com.ninjafocus.app.base.vie..., databaseEnabled: false, desired: {app: C:\Selenium\workspace\Ninja..., appPackage: com.ninjafocus.app, appactivity: com.ninjafocus.app.base.vie..., deviceName: Nokia 6, newCommandTimeout: 60, platformName: android, platformVersion: 9, udid: PLEGAR1780410318}, deviceApiLevel: 28,
Default suite
driver.findElementById("\r\n" + "com.ninjafocus.app:id/signinButton").click();
driver.findElementById("\r\n" + "com.ninjafocus.app:id/parentEmailText").sendKeys("pooja.yadav#gmail.com");
driver.findElementById("\r\n" + "com.ninjafocus.app:id/parentPasswordText").sendKeys("1234");
driver.findElementById("\r\n" +"com.ninjafocus.app:id/startedButton").click();

Informative stacktraces with karma+browserify, how?

I have a problem with assertion traces - they are not enough informative.
For an instance assertion fault:
should navigate inside of layout
PhantomJS 2.1.1 (Linux 0.0.0)
1) serialize#http://localhost:9876/base/node_modules/mocha/mocha.js?0491afff0b566ea45cd04c9164a355dba705689e:10776:34
processAssertionError#node_modules/karma-mocha/lib/adapter.js:59:50
node_modules/karma-mocha/lib/adapter.js:129:49
I've tried karma-sourcemap-loader, but it does not affect the output for me.
My config:
frameworks: ['mocha', 'chai', 'source-map-support', 'browserify'],
files: [
'tests/**/*.js'
],
browserify: {
debug: true
},
preprocessors: {
'tests/**/*.js': ['browserify']
},
reporters: ['progress', 'nyan'],
Any ideas ?
It seems like problem related to source-maps support by different browsers, this configuration works just fine with chromium browser, but does not provide readable stack-trace information when i'm testing with phantomjs browser.

howt o fix protractor that started failing on alerts all of a sudden

I have a project that has been running well for a long time now.
Recently (couple of weeks) the system tests are failing.
After a lot of investigation we concluded that protractor fails to identify and close an alert.
The code that used to work
exports.removeFaq = function( index ){
console.log('deleting item at',index);
exports.getContent(index).$( '[ng-click="removeFAQ($index)"]').click();
browser.sleep(2000);
browser.switchTo().alert().accept();
return browser.sleep(2000);
};
is now throwing errors:
WebDriverError: unknown error: cannot determine loading status
from unexpected alert open
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)
and (using element explorer):
> browser.switchTo().alert().accept();
UnexpectedAlertOpenError: unexpected alert open: {Alert text : are you sure you want to remove this helper content?}
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)
We've tried
- waiting instead of sleeping.
- sleeping for a long period
- ignoring angular.
nothing seems to make any difference whatsoever.
how can I fix this?
We had the same issue for a couple of days. Looks like we were on chromedriver 2.21. I updated to the latest version (2.23) and that seems to have fixed the issue.
The command webdriver-manager update --chrome did not work for me so I had to download the zip and extract it to my selenium directory. Under protractor.
Note there is a new protractor major version with updated versions. So updating protractor might fix the problem too.
for protractor version 3.x
You can also modify the file node_modules/protractor/config.json with the correct version and then run webdriver-manager update
for protractor version 4.x
You should modify the file ./node_modules/protractor/node_modules/webdriver-manager/config.json instead.
How can we say for sure that sleep of 2000ms is good enough? Exactly for this reason sleeps are not recommended in tests. Instead you can use proper waits and poll for alert. This way you would know that after a certain agreed timeout, alert never showed up and test rightfully failed
//wait maximum up to lets 5s before giving up
browser.wait(protractor.ExpectedConditions.alertIsPresent(), 5000);
browser.switchTo().alert().accept();

Appium - setting Desired Capabilities in both terminal and test code

I am trying to set some appium desired capabilities in the terminal window so that I can, for example, run my tests against different simulator devices:
Terminal: $ appium --device-name 'iPhone 6'
However, I am have to setup desired capabilities in my actual code, so I have a valid instance of IOSDriver. I use this code:
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "8.3");
capabilities.setCapability("app","../Build/Products/Debug-iphonesimulator/LightAlarm.app");
driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);
When I run my tests I get an error that deviceName is not being set:
The following desired capabilities are required, but were not provided: deviceName
However, my terminal appium server is all setup correctly:
info: Welcome to Appium v1.4.0 (REV dc30dae9e8fe8c85eeea707dbdbd60350fdff55b)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: [debug] Non-default server args: {"deviceName":"iPhone 6"}
info: Console LogLevel: debug
Any ideas what might be going wrong?