Let me explain the situation, I'm currently testing an AngularJS website with Protractor, I'm not developing it at all.
The problem is that, absolutely randomly the website is sometime not rendered. It's just blank with a different title :
If title is "VideoGame" -> then website is rendered
If title is "VideoGame-env-DEV" -> Then the website isn't rendered
No idea why and it's not my concern.
However, when testing with Protractor, it's obviously crashing.
So I wanted to bypass the problem with a temporary solution :
function specialRefreshFunction() {
cpt=0;
browser.get('https://blablabla');
browser.waitForAngular();
var title = browser.getTitle();
while (title != "VideoGame") {
cpt=cpt+1;
//sleep(1000);
//browser.sleep(1000);
browser.get('https://blablabla');
browser.waitForAngular();
//browser.navigate().refresh();
console.log("fail "+cpt);
}
console.log("Correct title " + title);}
My solution isn't working. I'm a total newbie with NodeJS & Protractor, so the code might be a nonsense.
W10 64bits
Latest Chromedriver
Protractor 5.4.2
NodeJS 10.15.0
Angular 6.1.10
Thank you !
You can go with browser.wait
let EC = protractor.ExpectedConditions;
browser.wait(
EC.presenceOf($('#some-element')),
10000,
'Element did not appear after route change'
).then(function() {}, function() {
browser.refresh();
});
In this particular example protractor will wait 10 sec for element #some-element to appear on the page. browser.wait returns a promise, so you can handle both cases - when element appear or element did not appear. Just put some specific selector instead of $('#some-element') that present on your page, by which you can consider page as loaded
Though, if you rely only on title value, you can use titleContains
var EC = protractor.ExpectedConditions;
// Waits for the title to contain 'foo'.
browser.wait(EC.titleContains('foo'), 5000);
Try to create a custom promise like that:
public vierifyPageTitle() {
return new Promise((resolve, reject) => {
const refreshUserData = setInterval(() => {
return browser.getTitle().then((title) => {
if (title === 'VideoGame') {
clearInterval(refreshUserData);
resolve(title);
}
}, (err) => {
browser.refresh();
reject(err);
});
}, 1000);
});
}
It's refreshing every 1000 ms if title is not equal to expected.
Related
I have a react native app which I input a value to TextInput, then onEndEditing I call axios.get inside a function GetSKUOPAttributes(). The onEndEditing is working. At debug mode everything is working fine, only doesn't work in release. I've put an alert to check if the onEndEditing was working and it is. Could someone help me to findout why it doesn't work at release? The var opNumber and selectedLine have value inside.
function GetSKUOPAttributes() {
alert('http://10.113.16.113:8082/api/skuattribute/find?OP=' + opNumber + '&line=' + selectedLine);
axios.get('http://10.113.16.113:8082/api/skuattribute/find?OP=' + opNumber + '&line=' + selectedLine, {
}).then(function (response) {
alert('Inside GetSKUOPAttributes');
var temp = [];
response.data.map(r => InsertSKUAttribute(r.id, r.attributE_DESCRIPTION, r.sku, r.value, r.status) ,console.log('INSIDE MAP'));
sleep(200);
GetLocalAttributes();
}).catch(error => {
console.log(error);
});
}
after a long week I've found out what was the problem. And it was this Starting with Android 9 (API level 28), cleartext support is disabled by default.
So after many searches, many updates. The fix was very very simple.
All I needed was to add the tag bellow to AndroidManifest.
android:usesCleartextTraffic="true"
I will let a link to the complete post if others, have the same issue.
https://freakycoder.com/react-native-notes-21-android-http-network-security-problem-fix-eeac4e1ea58b
I created a new route from the react-starter-kit project and it does an async fetch of some data, then renders it, but a second later the page reloads with a message saying "Page not found - sorry but the page you're trying to view does not exist".
In the console I see - "Warning: Text content did not match. Server: "Balances" Client: "Page Not Found"
async function action() {
let bittrex = new ccxt.bittrex ({
'apiKey': '',
'secret': ''
})
try {
// fetch account balance from the exchange
let bittrexBalance = await bittrex.fetchBalance ()
/**** commenting above and uncommenting this block stops it from happening....
let bittrexBalance = {};
bittrexBalance.info= [];
let currency = {};
currency.Currency = "BTC";
currency.Value=999;
// output the result
bittrexBalance.info.push(currency);*/
console.log ('balance', bittrexBalance)
let balances = [];
balances.push(bittrexBalance)
return {
title: "Balances",
component: (
<Layout>
<Balances balances={balances} />
</Layout>
),
};
} catch (e) {
console.log('SOME sort of error', e);
}
Does anyone have any idea what this could be?
Edit to add, I realise now that if I disable Javascript everything works perfectly...
It seems to be running through the universal router twice. The first time
That's the only clue I've found so far... I don't understand why it's reloading the page once it has already loaded...
The Page not found error is coming from it going through :
catch (e) the second time... I suspect something is happening inside the ccxt library but that the problem is actually that it is called a second time because the page is somehow reloaded...
It seems you have to call await bittrex.loadProducts() before fetching your Balance.
Edit : Seems also that bittrex.loadProducts() has been renamed by bittrex.loadMarkets()
More info in this issue on github
Your server code reached exception, which turns into rejection of route, because action method returns undefined, so server will fall down through —
next routes will not fit and finally it reaches the not found route.
I am using cucumber-js to run tests with selenium-webdriver.
I want to add a screenshot capture of the browser when any step times out.
I am using global timeout for all the steps as:
this.setDefaultTimeout(3 * 60 * 1000);
in my hooks file.
How do I register to the global timeout event (if such even exists)?
Selenium Webdriver js do provide function to get screenshot, you just need to use it in After, which is similar to #AfterClass tag in TestNG
The After scenario will execute after every scenario in Feature and check the result of the Scenario, it it is FAILED it will take the screenshot.
The reason for failure can be anything, like a bug, or DEFAULT_TIMEOUT
You need to add this in your world.js
this.After(function (scenario) {
if (scenario.isFailed()) {
// take a screenshot
// driver.takeScreenshot() is defined in webDriver.js
return driver.takeScreenshot()
.then(function (screenShot) {
scenario.attach(new Buffer(screenShot, 'base64'), 'image/png');
return driver.close()
.then(function () {
return driver.quit();
});
});
}
else {
return driver.close()
.then(function () {
return driver.quit();
});
}
});
My E2E testing is to fill some details in a page, click a button to go to the next page and verify whether we reached the next page.Now I am able to move to the next page and scroll down but after that I couldn't select an element based on id, name or css it fails with the above error.
Why do we get "timeout Aysnc callback was not invoked" error ?
I have seen so many questions asking for same error but none of the answers is working in my case.PFB the code.
beforeEach(() => {
browser.manage().window().setSize(BROWSER_WIDTH, BROWSER_HEIGHT);
browser.get('index.html#/banking');
bankingDetails = require('./banking.page');
});
fit('should navigate to check panel for source type = saving and one ' +
'savings checkbox was selected', () => {
var checkPanelDetails = require('./check.page');
bankingDetails.fillBankingDetails(true, true);
bankingDetails.bankingWeiterButton.click();
browser.executeScript('window.scrollTo(0, 700);');
var isPresent = browser.wait(function () {
return checkPanelDetails.isVisible();
});
expect(isPresent).toBeTruthy();
});
check.page
var CheckPanel = function () {
this.checkPanel = element(by.name('check.confirm'));
this.isVisible = function () {
return this.checkPanel.isPresent();
};
};
module.exports = new CheckPanel();
Note:
I am using jasmine(2.4.1) and protractor(2.3.0)
Here is a link from jasmine Asynchronous_Support that help me understand time out problems. Hope that can help you,
describe("long asynchronous specs", function() {
beforeEach(function(done) {
done();
}, 10000);
});
I have a test that clicks a button and redirects to a user dashboard. When this happens Webdriver returns:
javascript error: document unloaded while waiting for result.
To fix this I insert browser.sleep(2000) at the point where redirection occurs and assuming my CPU usage is low, this solves the issue. However, 2000 ms is arbitrary and slow. Is there something like browser.waitForAngular() that will wait for the angular to load on the redirected page before the expect(..)?
it('should create a new user', () => {
$signUp.click();
$email.sendKeys((new Date().getTime()) + '#.com');
$password.sendKeys('12345');
$submit.click();
browser.sleep(2000); // Need alternative to sleep...
// This doesn't do it...
// browser.sleep(1);
// browser.waitForAngular();
$body.evaluate('user')
.then((user) => {
expect(user).toBe(true);
});
});
do you think something like this could work for you? This will wait up to 10 seconds for the url to include the text 'pageTwo', or whatever you put in.
var nextPageButton = $('#nextPage');
nextPageButton.click().then(function(){
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /pageTwo/.test(url);
});
}, 10000);
};
Just stick in the regex of the url you are expecting.
Alternatively, you could wait for an element from the next page to appear as well:
var nextPageButton = $('#nextPage');
nextPageButton.click();
var elementFromSecondPage = $('#coolElement');
browser.wait(protractor.until.elementIsVisible(elementFromSecondPage), 5000, 'Error: Element did not display within 5 seconds');
When using .click, protractor will naturally wait for angular to finish the action attached to the click, such as changing the page. But, while the page change, you may still be needing something specific to be loaded, so the test fails before that part is available. Using this, it should wait for the click part to finish, then wait for the element to appear.
To expand on user2020347's answer:
Thanks that solved my issue. I wonder why this isn't a built in function. I'll be using this in many places to wait for browser navigation.
To make it more concise, I made a little helper:
Object.assign(global, {
waitUntilURLContains: string => {
let fn = () => {
return browser.driver.wait(() => {
return browser.driver.getCurrentUrl().then((url) => {
return url.includes(string);
});
}, waitDelay);
}
return fn.bind(null, string);
}
});
In my test:
$button.click().then(waitUntilURLContains('dashboard'));
keeping it very simple. I was also running into the same problem but was able to solve it using the following code :
page.setUsername(objectrepository.userdetails.useremail);
page.setPassword(objectrepository.userdetails.userpassword);
page.login().click();
**browser.wait(EC.visibilityOf(page.greetingMessageElement()), 5000);**
page.greetingMessageElement().getText()
.then(function (value){
expect(browser.getCurrentUrl()).toContain("#/mytickets");
});