Protractor: Invalid locator error with isElementPresent - angularjs

I have the following simple line of code in my e2e test...
var promise = ptor.isElementPresent(element(by.binding('firstName')));
I get an error that says TypeError: Invalid locator. I don't see many other people getting this error after googling it. Where did I make an error?

I believe the syntax is(remove element(...)...
var promise = ptor.isElementPresent(by.binding('firstName'));

Related

Console Error : Unhandled Promise rejection: Reflect.getOwnPropertyDescriptor called on non-object

Running Angular + storybookjs and getting this error.
I just ran into this myself. For me a circular Module import caused the issue.
I found the issue by setting a breakpoint in NgModulesAnalyzer to break when typeof target !== 'function'
A few stackframes up I found the Module that caused the issue and replaced the import

How to fix the below test case when i am migrating from angularjs 1.6.9 to 1.7.8

i am trying to migrate my angularjs application from v1.6.9 to v1.7.8. my test case are failing with
angular-mock.js($rootScope)
ERROR: No response Defined! in angularjs/angular-mocks.js(1607)
ERROR:$rootScope:INPROG
since i am new to jasmine karma testing i have tried with $rootscope.flush(). but i am not able to resolve it .
this is my first unit testing with Angularjs and jasmine karma, not able to find the exact reason and i have gone through the release notes of the other releases as well.
with $rootScope i found that they have modified its scope to the function not generic.
Below is my spec.js:
I am getting error with $rootscope,flush(). could some please help me out to resolve this issue as it is required.
$httpBackend.when('GET','/application/api/prefernce-definition')
.respond(successResponsePrefernces);
$httpBackend.when('POST','/application/api/setprefernce-definition')
.respond(201);
$httpBackend.when('POST','/application/api/v1/set-prefernces');
$httpBackend.when('POST','/application/api/v2/balances')
.respond(accountApiResponse);
//assertion for expecting proper get request for preferences-definition
$httpBackend.expectGET(,'/application/api/v1/prefernce-prefernces');
//fetch and set prefernces
$scope.onclickSetting();
$rootScope.flush();
$timeout.flush();
//now save the settings
$scope.saveViewSettings();
// getting error in this line after the flush
$rootScope.flush();
$timeout.flush();
var viewMode = $scope.model.viewSettings.viewMode,
viewModeExpected = successResponsePreferences.preferenceDefinitionList[0];
expect(viewMode.default).toBe(viewModeExpected.defaultPreferenceValue);
expect(viewMode.selected).toBe(viewModeExpected.currentUserPreferenceValue);
expect($scope.$broadcast).toHaveBeenCalledWith("ShowFilter");
//should update the prefernces in cache
expect(viewMode.selected).toBe(cacheService.getPreferences().viewMode);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[]
);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[Constant.EXTD_MODE, Constant.NO_GROUPING]
);
});
Below are the errors:
Error: No response defined! In
../bower_components/angular-mocks/angular-mocks.js(line 1607) $httpBackend#/../bower_components/angular-mocks/angular-mocks.js:1607:63.

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'defaultView' of undefined [duplicate]

I am trying to use Selenium for Python eith the Chrome webdriver to automate the download of a file.
My program works perfectly up to the last step (clicking on the 'download' button) at which point a dialog box is triggered with the text:
"An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined41"
What does this error mean and what are the most probable causes?
For reference, here are the last few commands of my program:
try:
elem = wait.until(EC.presence_of_element_located((By.ID,'element_1_id')))
finally:
elem1 = driver.find_element_by_id('element_1_id')
elem2 = driver.find_element_by_id('element_2_id')
action = ActionChains(driver).move_to_element(elem1).move_to_element(elem2)
action.perform()
elem2.click()
This error message...
An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined
...implies that your program was unable to read the property getColomnSet while trying to download the desired file.
Possibly, the main problem is the js involved to download the document is invoked before the client renders the HTML DOM completely.
The relevant HTML, a bit more of your previous lines of code and the error stack trace would have given us some more idea about what's going wrong.
Solution
You can induce some measures to wait till the complete DOM Tree is rendered following the discussion:
Generic funtion to check if page has completely loaded in Selenium
A couple of facts:
In your code trials I don't see you interacting with the element (By.ID,'element_1_id') so possibly you can remove the step of presence_of_element_located() for the element (By.ID,'element_1_id').
If you still require presence_of_element_located((By.ID,'element_1_id')) catch the exception and initiate required steps.
As you invoke move_to_element() over elem1 and elem2 and moving ahead invoke perform() you need to induce WebDriverWait with expected_conditions as element_to_be_clickable(locator)
tl;dr (references)
Cannot read property 'getContext' of null, using canvas
Uncaught TypeError: Cannot read property 'getContext' of undefined
Uncaught Error remote.js
Try the following - it works on Salesforce Lightning UI screens:
WebElement element = driver.findElement(By.id("your ID"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

find the element in the source html code for invalid login case in protractor

I'm trying to write a simple "failed login" test in protractor. The thing is, i can't point (don't know how), to the specific string in the source code.
I tried all kinds of things like: cssContainingText, to equal, get text and etc. (maybe it's ok, but i did that wrong).
The test:
describe('login to POC', function() {
it('should login to POC', function() {
browser.get('http://emeaherz-swaqal:8080/web-client/login.html#/login');
element(by.model('echos_username')).sendKeys('super1');
element(by.model('echos_password')).sendKeys('super');
element(by.id('loginButton')).click();
expect(by.id('action-messages')).getText('The following error(s) occurred:').isPresent()).toBe(true);
});
});
Please look on the source code.
I'm really need the suggestion here!
html source
the error i'm getting is:
#alecxe
1) login to POC should login to POC
Message:
NoSuchElementError: No element found using locator: By.cssSelector(".action-messages")
Stacktrace:
NoSuchElementError: No element found using locator: By.cssSelector(".action-messages")
==== async task ====
Asynchronous test function: it()
Error
at [object Object]. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:16:18)
Error
at [object Object]. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:6:3)
at Object. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:1:63)
Finished in 4.942 seconds
1 test, 1 assertion, 1 failure
You miss the element call and I think you can just expect the text of the error message. Replace:
expect(by.id('action-messages')).getText('The following error(s) occurred:').isPresent()).toBe(true);
with:
expect($('#action-messages ul li').getText()).toEqual("Sorry, your username ...");

Gulp-uglify : throw er; // Unhandled 'error' event

i'm pretty new to gulp , and I follow tutorials in http://leveluptuts.com/tutorials/learning-gulp , I get this error:
events.js:141
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:196:18)
at js_error (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:204:11)
at croak (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:680:9)
at token_error (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:688:9)
at unexpected (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:694:9)
at expr_atom (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1201:9)
at maybe_unary (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1363:19)
at expr_ops (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1398:24)
at maybe_conditional (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1403:20)
at maybe_assign (/home/kid/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1427:20)
here is my code :
var gulp = require('gulp')
uglify = require('gulp-uglify');
gulp.task('default', function() {
// body...
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minjs'));
});
and the tree of directory, just simple
-gulp
-js/
-gulpfile.js
thanks a lot
Your uglify task is probably choking on one of the files it is trying to process. Handle the error and write the output to the console so you can see which file causing the task to fail.
gulp.task('scripts', ['clean'], function () {
return gulp.src('js/*.js')
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('minjs'));
});
When you run your gulp task again, you will still get an error, but this time, right towards the top of the output, you will see the file and line number that uglify is having trouble processing. Debug from there.
Maybe its a syntax error? Fix it and try again.
Maybe you've got a weird _reference.js file with unexpected characters like those you see in Visual Studio projects sometimes? Exclude it from the gulp.src and try again.
I had the same error. So I tried to output an error to the console (thanks to bingo). I realized that the problem is that gulp-uglify doesn't want to work with ES6. I changed my JS code to ES2015 and voila. You can also use gulp-babel.
In my case, it seems it doesn't accept "arrow-syntax" function
(e.g. data=>{ // do something; })
Also you can use gulp-util.
https://www.npmjs.com/package/gulp-util
var gutil = require('gulp-util');
gulp.task('scripts', ['clean'], function () {
return gulp.src('js/*.js')
.pipe(uglify().on('error',gutil.log))
.pipe(gulp.dest('minjs'));
});
I had the same issue and was getting the same error.
The problem was, one of my JS files had #charset "UTF-8"; in the first line. So the syntax was breaking due to # symbol. I removed it and it worked well.
{
SyntaxError: Unexpected character '#' at JS_Parse_Error.get
(eval at <anonymous> (C:\xampp\htdocs\catch\node_moles\uglify-js\tools\node.js:21:1),
<anonymous>:86:23) at formatError (util.js:649:15)
at formatValue (util.js:554:18)
at formatProperty (util.js:795:15)
at util.js:655:12
at Array.map (native)
at formatObject (util.js:654:15)
at formatValue (util.js:593:16)
at inspect (util.js:186:10)
at exports.format (util.js:72:24)
message: 'Unexpected character \'#\'',
filename: 'all.min.css', line: 1, col: 0, pos: 0 },
plugin: 'gulp-uglify',
....
....
}
I had the same issue and it came down to a js file that was giving out issues. The biggest issue was I had 10 js files but after a little digging my issue was not adding ;
since this will minify your code it does not matter you use ES6 you need to add ; at the end of your code or minifying won't work.
use gulp-uglify-es instead gulp-uglify. It works with es6

Resources