Why I got getText is not a function in a protractor test? - protractor

Im testing with protractor 7.0.0 and got the next error with the next code:
it('Translation', function () {
var transButtonText = element(by.xpath('//*[#id="menubar"]/status-bar/div/div[2]/button/div'));
expect(transButton.getText().toBe('ES'));
});
error: Failed: transButton.getText(...).toBe is not a function
I don't know why I got this error, I should get the text without problems, right?

Related

Failed: Cannot read property 'bind' of undefined with Expected Conditions

My script failed at the expected conditions at this line:
let condition = EC.presenceOf (title_css);
The error message:
Failed: Cannot read property 'bind' of undefined
I tried an equivalent script in selenium Java and it works. But I am wonder why this fails in Protractor. I am new to Protractor and wonder if ExpectedConditions do not work for non angular.
var title_css = "h1[ng-bind='::$ctrl.primaryText']"
describe ("Protractor test demo", function(){
it ("testing site", function (){
browser.get('https://www.eat24.com/')
let EC = ExpectedConditions;
var title_css = by.css (title_css);
let condition = EC.presenceOf (title_css);
browser.wait(condition, 30000)
})
})
ExpectedConditions in Protractor should accept css like in Selenium / Java?
change the EC to EC = protractor.ExpectedConditions;
then the presenceOf part browser.wait(EC.presenceOf(element));
Also this condition will return a promise that needs resolving
I suggest you to read protractor API documentation first. you'll see protractor has different syntax
A few problems I noticed in your code
let title_css = "h1[ng-bind='::$ctrl.primaryText']" // I assume you verified it works
describe("Protractor test demo", function() {
it("testing site", function () {
browser.get('https://www.eat24.com/')
let EC = protractor.ExpectedConditions; // ExpectedConditions may be available as a global variable, may not, so to be safe do it this way...
let title_element = element(by.css(title_css)); // syntax is element(by.strategy(locator))
let condition = EC.presenceOf(title_element);
browser.wait(condition, 30000)
})
})
If you solve your problem, your next problem will be Promises, I can guarantee you that. So read how to handle them

How to do error handling in protractor when errors like element not found, element not intractable,WebDriverError: unknown error occur

I have executing some protractor script in a function and that function is calling in a for loop.So if any of the error occurring like element not found, element not intractable,WebDriverError: unknown error occur: Element is not clickable, then i need to skip for that loop count and need to execute next loop count.I have tried with isPresent(),isDisplayed() for catching the error but its not working then i tried below code for that.
for(i=0; i<count; i++){
post(post_details[i].MediaUrl,post_details[i].CallToActionType,post_details[i].LPAID,post_details[i].CallToActionUrl);
}
post((MediaUrl,CallToActionType,LPAID,CallToActionUrl){
element(by.css(locators.locator_post_description)).sendKeys(Summary).then (function(){
if(MediaUrl!=null){
var path = require('path');
var type=MediaUrl.split("/");
var fileToUpload = '../files/' + (type[type.length-1]) ;
var absolutePath = path.resolve(__dirname, fileToUpload);
browser.sleep(3000);
element(by.css(locators.locator_post_img)).sendKeys(absolutePath);
browser.sleep(6000);
}
if(CallToActionType!=null){
browser.sleep(1000);
element(by.css(locators.locator_post_eventPostButton)).click();
browser.sleep(2000);
element(by.cssContainingText(locators.locator_post_buttonType,CallToActionType)).click();
browser.sleep(1000);
element(by.css(locators.locator_post_eventPostButtonLInk)).sendKeys(CallToActionUrl);
}
element(by.xpath(locators.locator_post_publishBtn)).click().then (function(){
browser.sleep(3000);
updatedb(LPAID);
});
},function(err) {
console.log("no summary...."+err);
return true;
});
}
Here i am getting values(MediaUrl,CallToActionType,LPAID) form DB and i am checking its value is not null.By using the above code, i am able to catch the error associated with description element and then exiting from that loop count and executing next loop count.But i am not able to use this error catching method for image element,button type element,button link element.So how can i catch error(if any) associated with each of the locator elements and if error occurred, then to skip that loop count.Thanks in advance.
Protractor has inbuilt Expected Conditions using which with browser.wait() you can handle the your issues. Refer to below code and link:
var EC = protractor.ExpectedConditions;
var button = $('#xyz');
var isClickable = EC.elementToBeClickable(button);
browser.get(URL);
browser.wait(isClickable, 5000); //wait for an element to become clickable
button.click();
Documentation - https://www.protractortest.org/#/api?view=ProtractorExpectedConditions

Back4app issue in registering device with ionic 3

I m trying to use back4app for push notification. For this I have installed back4app's ionic sdk (https://www.back4app.com/docs/ionic/parse-ionic-sdk) like this
npm install parse
then in my app.component.ts I imported parse
import Parse from 'parse';
and in platform ready
Parse.serverURL = "https://parseapi.back4app.com/";
Parse.initialize("APP_ID_HERE", "JAVASCRIPT_KEY"); //I have used real keys from back4app dashboard.
let install = new Parse.Installation();
install.save(null, {
success: (install) => {
// Execute any logic that should take place after the object is saved.
// console.clear();
console.error('New object created with objectId: ' + install.id);
},
error: (install, error) => {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
//console.clear();
console.error('Failed to create new object, with error code:' + error.message.toString());
}
});
When I do Ionic serve or test it in device, it should register device/installation id to their backend but it gives 400 Bad Request error on https://parseapi.back4app.com/classes/_Installation the error was -
{"code":135,"error":"deviceType must be specified in this operation"}
I m not sure where to mention deviceType as their documentation doesn't seem that good.
Can anybody help me on this??
This is not mentioned in their documentation but I have found it in one of their example.
Replacing -
let install = new Parse.Installation();
with
let install = new Parse.Installation();
install.set("deviceType", platform.platforms().toString());
Solved the issue.
Here is the link to their repository
Parse SDK now supports Promises.
I'd recommend using it instead of passing in callbacks.
You can accomplish that by:
install.save().then(() => {
// success
}, err => {
// error
})

using Axe-core inside Intern 4

I am trying to set up my accessibility testing using axe-core or axe-webdriverjs inside of Intern 4. I finally got something to compile but I get this socket hung up error. Let me walk you through my process.
Loading axe-core as a plugin. In my intern.json
I have my included a plugin axe-core. node_modules/axe-core/axe.min.js specified here https://axe-core.org/. This did not work. When running the test it did not find the module.
I then tried using the loader to import this module. In my intern.json I had the following:
"plugins": [
"node_modules/babel-register/lib/node.js"
],
installed the necessary plugins and then I imported axe in my test.js using:
`import axe from '/node_modules/axe-core/axe.min'`
still I get axe is undefined errors.
I tried to use axe-webdriverjs used the example code
const { suite, test, before } = intern.getInterface('tdd');
const { assert } = intern.getPlugin('chai');
var AxeBuilder = require('axe-webdriverjs');
var time = 1000;
var session;
suite('Accessibility', () => {
test('Accessibility Test 1', ({remote}) => {
remote.get('https://dequeuniversity.com/demo/mars/')
.then(function () {
AxeBuilder(driver)
.analyze(function (results) {
console.log(results);
});
});
});
});
still could not get it to work.
then I tried changing the
var AxeBuilder = require('axe-webdriverjs');
to
import AxeBuilder from 'node_modules/axe-webdriverjs/lib/index';
It is now running but I get a socket hang up error.
All I am trying to do is run axe-core or even axe-webdriver a thrid party library into tests suite within intern 4. Any sort of help will be appreciated.
Thanks
There is an Intern accessibility plugin that includes support for aXe. You can use that directly, or simply use it as an example of how to use aXe-core with Intern.
You wouldn't typically use axe-webdriverjs with Intern since Intern is using its own WebDriver library which isn't directly compatible with the Selenium JS library.

How to write ContinueWith methods using UnityScript in Unity3D

I am having trouble with asynchronous tasks when trying to update User Data in my Parse cloud. I am using UnityScript for my project and using this function to update my Object. Please help me to write this correctly in UnityScript. I am getting this error
error:
Unexpected token: t
expecting ), found '{'
';' expected
Insert a semicolon at the end expecting EOF, found ')'
gameScore.SaveAsync().ContinueWith(t =>
{
// Now let's update it with some new data. In this case, only cheatMode
// and score will get sent to the cloud. playerName hasn't changed.
gameScore["cheatMode"] = true;
gameScore["score"] = 1338;
gameScore.SaveAsync();
});