I started working with Galen and I had this test that was working perfectly:
this.HomePage = $page('Welcome Page', {
aboutButton: 'nav.navbar .about'
});
this.AboutPage = $page('About page', {
modalContent: 'div.modal-content',
supportLink: '.support-link',
dismissButton: '.dismiss'
});
var homePage = new HomePage(driver);
homePage.waitForIt();
homePage.aboutButton.click();
var aboutPage = new AboutPage(driver);
aboutPage.waitForIt();
I understand that the waitForIt method waits for all the attributes defined by page so the framework knows when to execute the next statement.
Now, I want to run this as a grunt task and I've been using grunt-galenframework, and I configured it correctly, everything is working, but I can't make the previous test pass, the task code is as follows:
load('../gl.js');
forAll(config.getDevices(), function (device) {
test('simple test on ' + device.deviceName, function () {
gl.openPage(device, config.getProjectPage(), "Welcome Page", {
aboutButton: 'nav.navbar .about'
});
elements.aboutButton.click();
// MISSING WAIT FOR ABOUT_PAGE
gl.runSpecFile(device, './test/responsive/galen/about.gspec');
});
});
As you can see, I get into the Welcome Page and then I need to click a button, wait for a dialog to appear, and then check the about.gspec specs (they verify elements inside the dialog).
So how can I add a wait for new elements to appear on the same URL? it feels like grunt-galenframework only offers wait when entering a new url, with the openPage method.
you could try
elements.newElement.waitToBeShown()
The methods from here should be available.
PS: I'm the author of the grunt plugin for Galen and also involved in the development of the Galen Framework itself
Related
I'm new to JS and trying cucumber js for the first time
This is how my step defn looks like:
Pseudocodes
Given("I launch Google.com", async (){
await Launch.launchGoogle():
})
When("I enter search text cucumber js", async (){
await Launch.searchCucumber():
})
This is how my Launch.js looks like:
module.exports launchGoogle= async function() {
await driver.get("www.google.com"):
}
module.exports searchCucumber = async function(){
await driver.findElement(By.name("q")).sendKeys("cucumber");
}
In this case, when I run the feature with 2 steps, I get ELIFECYCLE ERR at the end of first step.
When I remove the await in the step definitions, it runs fine. But, the console displays as 2 steps passed even before the chrome browser is launched. That is, it fires the Given and When steps and shows the result even as the code in Launch.js is still executing.
Pls help how to solve this?
I just figured out that the default step timeout is 5000ms. Since, launching the browser and hitting the URL was taking more than that, it was failing. i just increased the step timeout to 30000ms and it works fine.
As we know, we can put a pop up asking if we are sure about refreshing the page when we click the refresh button on the browser. Usually it is done by adding an event listener on onbeforeunload.
However, in my Aurelia application, I try to do that but it's not working.
let's say this is my app.js ( root ModelView )
export class App {
this.refreshClicked = () =>{ return "Are you sure you want to exit?"; };
attached(){
window.addEventListener("onbeforeunload", this.refreshClicked);
}
But it is not working, however, if we replace the return statement to console.log("clicked") I can see that the listener works without any problem.
Any help?
First of all, if you are adding event handler through window.addEventListener, you don't use on prefix in that case. So it's either:
attached() {
window.addEventListener('beforeunload', this.refreshClicked);
}
or an older, not recommended, syntax:
attached() {
window.onbeforeunload(this.refreshClicked);
}
Second, you'll need to set the returnValue property on Event object and also return the same string value to support more browsers. To learn more about this event (and various browser quirks), check out its MDN page.
Your refreshClicked should look like this:
this.refreshClicked = e => {
const confirmation = 'Are you sure you want to exit?';
e.returnValue = confirmation;
return confirmation;
};
I have a simple script that performs a login using the selenium-webdriver npm module. The script works, but it is really slow and the wait timeout is giving very odd results (sometimes it seems to timeout immediately, and other times it waits far past the defined timeout).
Am I doing something wrong that would make the login very slow (running this through a selenium hub perhaps)? The site itself is very responsive.
Here is the script:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
usingServer('http://hubserver:4444/wd/hub').
withCapabilities(webdriver.Capabilities.firefox()).
build();
console.log('\n\nStarting login.');
console.log('\nConnecting to grid: http://hubserver:4444/wd/hub' );
// Load the login page and wait for the form to display
driver.get('https://testsite.com');
driver.wait(function() {
return driver.isElementPresent(webdriver.By.name('user'));
}, 3000, '\nFailed to load login page.');
// Enter the user name
driver.findElement(webdriver.By.name('user')).sendKeys('testuser').then(function() {
console.log("\nEntering user name");
});
// Enter the password
driver.findElement(webdriver.By.name('pass')).sendKeys('testpwd').then(function() {
console.log("\nEntering password");
});
// Click the login button
driver.findElement(webdriver.By.id('submit')).click().then(function() {
console.log("\nLogging in.");
});
// Wait for the home page to load
driver.wait(function() {
console.log("\nWaiting for page to load");
return driver.isElementPresent(webdriver.By.id('main'));
}, 3000, '\nFailed to load home page.');
driver.getCurrentUrl().then(function(url) {
console.log("\nPage loaded: " + url);
});
driver.quit();
Maybe you have it specified elsewhere, but in the code shown your driver.wait() has no amount of time specified.
Also, maybe I'm misunderstanding your code because I do this mainly in Python, but driver.wait(function(){}); looks weird to me. Is this really proper use of the JS bindings? Generally, you wait for the element to be found and then subsequently call a function that does something with the element. I can't write it in JS, but in pseudocode:
driver.wait(#element you're looking for)
# Handle exception if there is one
# Otherwise do something with element you're looking for
Also, I would think
driver.isElementPresent(webdriver.By.name('user'));
Should be
driver.isElementPresent(By.name('user'));
I was working through the selenium web-driver example and it didn't work. Several months ago it worked just fine so I am wondering if I am doing something wrong or if the testing methods have changed.
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');
var By = webdriver.By;
test.describe('Google Search', function() {
test.it('should work', function(done) {
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("webdriver");
driver.findElement(By.name("btnG")).click();
driver.getTitle().then(function(title) {
assert.equal("webdriver - Google Search", title);
done();
});
driver.quit();
});
});
The output is:
AssertionError: "webdriver - Google Search" == "Google"
Expected :"Google"
Actual :"webdriver - Google Search"
This tells me that the page has not updated yet but I am not sure why. The example appears here: https://code.google.com/p/selenium/wiki/WebDriverJs#Getting_Started
Selenium version from package.json: 2.39.0
Update
I should have also stated that the test is being run through Mocha. Is Mocha the culprit? When I tried this last time it was using Jasmine.
Straight from the example in the documentation, use wait:
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
Why do you need to use wait? Because the Google page works asynchronously. After you enter the keys, it may take a bit of time before the server sends a response and the page is updated.
You should also remove done. While in general you need it for asynchronous tests, it seems the sequencer that comes with this incarnation of Selenium's webdriver will block on quit until all actions are performed. This example in the documentation does not use it.
Also, if you wonder why there is no assertion: you'll know your test has failed if you get a timeout exception when the timeout has expired.
With the promised web driver I would like to check if an element exists on the page, then login if it does, otherwise continue with the promise chain.
Is this not possible at the moment due to https://github.com/theintern/intern/issues/14?
In Intern 2, simply use the normal find command:
var remote = this.remote;
remote.get(url)
.findById('foo')
.then(function (element) {
// exists
}, function () {
// does not exist
});
In Intern 1, if you need to conditionally branch, you’ll need to stop and add new instructions based on the result of your check.
var remote = this.remote;
remote.get(url)
.elementByIdIfExists('foo')
.then(function (element) {
if (element) {
remote.clickElement()
.type('foo');
// ...etc.
}
});
This should work in Intern 1.1 only if you are adding new commands to the remote promise chain when there are no other already-existing commands pending. Intern 1.2 will contain improvements that eliminate this restriction. This is issue #14.