casperjs can't click on reddit.com - phantomjs

my casperjs click is working fine in most web site, but when i try to click something on reddit, it wont click.
casper.start();
casper.then(function (){
this.open("http://reddit.com");
});
casper.then(function(){
this.sendKeys("[name='user']", 'someusername');
this.sendKeys("[name='passwd']", 'somepassword');
this.click("[id='rem-login-main']");
this.click(x('//*[#id="login_login-main"]/div[3]/button'))
});
casper.run();
the sendkeys function is working well, but both click function is not workin, please help!

Find the below code and its working
casper.test.begin("Opening Reddit page", 1, function suite(test) {
var x = require('casper').selectXPath;//required if we detect an element using xpath
casper.start();
casper.viewport(1024, 768).then(function () {
this.open("http://reddit.com");
this.wait(5000)
});
casper.then(function () {
this.sendKeys("[name='user']", 'username');
this.sendKeys("[name='passwd']", 'password');
this.click("[id='rem-login-main']");
this.click(x(".//*[#id='login_login-main']/div[3]/button"));
});
casper.wait(5000)
casper.then(function () {
this.test.assertExists(x(".//*[#id='header-img']"), "Confirmed that page has successfully loaded");
});
casper.run(function () {
test.done();
});
});

Related

How to send data from one Electron window to another with ipcRenderer using vuejs?

I have in one component this:
openNewWindow() {
let child = new BrowserWindow({
modal: true,
show: false,
});
child.loadURL('http://localhost:9080/#/call/' + this.chatEntityId + '?devices=' + JSON.stringify(data));
child.on('close', function () { child = null; });
child.once('ready-to-show', () => {
child.show();
});
child.webContents.on('did-finish-load', () => {
console.log("done loading");
ipcRenderer.send('chanel', "data");
});
}
And then in child window component:
mounted() {
ipc.on('chanel', (event, message) => {
console.log(message);
console.log(event);
});
}
I tried that .on in created() and beforeCreate() and with this.$nextTick(), withsetTimeout` but nothing works.
I don't want to send some string data but object but as you can see not event simple string "data" works. I am out of ideas.
I can see that this only works in parent component for component where that emit came from if i do this:
send
listen in main process
send back to event.sender
So, question is how to pass any form of data from one window to another?
Ok, after long night, morning after solution.
In some vuejs componenet some action on button click for example
ipcRenderer.send('chanel', someData);
In main process
ipcMain.on('chanel', (event, arg) => {
let child = new BrowserWindow()
// other stuff here
child.loadURL(arg.url)
child.on('show', () => {
console.log("done loading");
child.webContents.send('data', arg);
});
})
In vuejs component for other route arg.url
mounted() {
ipc.on('chanel', (event, message) => {
console.log(message);
console.log(event);
});
}

Protractor "restartBrowserBetweenTests: true" restart browser, but don't run test after this

I need to restart browser after each "it" (test), for this reason I write "restartBrowserBetweenTests: true" in protractor.config file. Now after first "it" (test) finished, browser closed and opened again (open website that I write in "beforeEach", but next "it" (test) is not run.
What I do wrong? I will be happy for any advice.
I use "protractor": "2.5.1".
Thanks!
Added:
beforeEach(function () {
browserUtil.navigateTo(browserUtil.url.main);
loginPage.loginAsSample();
});
afterEach(function(){
browserUtil.deleteCookies();
});
it("'Delete' button is inactive if there are no projects in the list", function() {
projectPage.clickOnProjectButton();
expect(projectPage.isProjectPageFormVisibility(true)).toBe(true);
expect(projectPage.isDeleteBtnDisable()).toBe(true);
});
it("Create new project with template 'A'", function() {
projectPage.clickOnNewProjectBtn();
projectPage.clickOnAProject();
projectPage.clickOnOkBtnProject();
expect(projectPage.isOpenedProjectVisibility(true)).toBe(true);
});
I've never utilized restartBrowserBetweenTests: true, but this works for me:
in protractor.conf, remove restartBrowserBetweenTests: true
in test.spec.js, modify beforeEach and afterEach
beforeEach(function () {
browser.get(browserUtil.url.main);
});
afterEach(function () {
browser.manage().deleteAllCookies();
});
Being that you're utilizing a page object structure for your tests, you could/would want to encapsulate browser.get(browser.browserUtil.url.main); into you're page object.
Where ProjectPage is defined, I'd add :
this.refreshPage = function () {
browser.get(browserUtil.url.main);
};
If you go with this approach, you'd change the call on beforeEach to :
beforeEach(function () {
projectPage.refresh();
});

Browser switch handle Phantomjs Issue

I use protractor with cucumber and whenever there is a need to switch between browser tabs with phantomjs it just hangs without any error message. However the same step works fine with Chrome browser. Why is that? My step is as follows
this.Then(/^the page url hash should be "([^"]*)"$/, function (arg1, callback) {
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[2];
browser.switchTo().window(newWindowHandle).then(function () {
expect(browser.driver.getCurrentUrl()).to.eventually.contain(arg1).and.notify(callback);
});
});
Ok so apparently the issue was with callback. When i modified the above code slightly it works like a charm even in phantomjs!
this.Then(/^the page url hash should be "([^"]*)"$/, function (arg1, callback) {
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[2];
browser.switchTo().window(newWindowHandle).then(function () {
expect(browser.getCurrentUrl()).to.eventually.contain(arg1);
});
});
callback();
});

How can I use Protractor with google.com?

google.com isn't an Angular app, but Protractor should still be able to test it, right? I've been trying to do a simple test of a search, but keep running to errors.
the spec:
browser.ignoreSynchronization = true;
describe('Google Demo', function() {
it('Should Search', function() {
browser.get('http://google.com/');
browser.wait(element(By.id('q')).isPresent);
element(By.id('q')).sendKeys('please work');
});
});
the error is:
Failures:
1) Google Demo Should Search
Message: TypeError: Cannot read property 'count' of undefined
What am I doing wrong? I'd appreciate any help!
Since it's a non-Angular app, you need to use browser.driver instead of just browser. GitHub Link for non-angular app
browser.ignoreSynchronization = true;
describe('Google Demo', function() {
it('Should Search', function() {
browser.driver.get('http://google.com/');
browser.driver.findElement(by.name('q')).sendKeys('please work');
});
});
This is working on my system!
this also works for non angular apps
browser.waitForAngularEnabled(false);
describe('Google search', function() {
it('should search a text as GURU99', function() {
browser.waitForAngularEnabled(false);
browser.get('https://www.google.com');
element(by.name("q")).sendKeys('test')
browser.sleep(5000);
});
});

SimpleModal Closing with Transition on overlay but not on X click

So I have a page that lives here:
http://testing.bistromd.com/new-media
If you scroll down the screen to the magazine section you will see one called "National Culinary Review". Click on the image of the cover and the modal will fire with all of the proper timings and transitions. It will also close correctly with the transitions and timings when you click anywhere outside of the modal on the overlay.
What DOES NOT work is when you click on the "X" button in the upper right of the modal box. Then the modal just vanishes instantly with NO transitions. Here is the relevant Code:
<script>
$(document).ready(function() {
$('#cr > a').click(function() {
$("#crModal").modal({onOpen: function (dialog) {
dialog.overlay.fadeIn(300, function () {
dialog.container.fadeIn(10, function () {
dialog.data.fadeIn(200);
});
});
dialog.overlay.one('click', function () {
dialog.data.fadeOut(200, function () {
dialog.container.slideUp(10, function () {
dialog.overlay.fadeOut(300, function () {
$.modal.close();
});
});
});
});
}});
});
</script>
Thanks so much in advance!
On SimpleModal's project page, Eric gives an example of using the onClose event to do some animation, similar to how you're using the onOpen event now. Here's the example he provides:
$("#element-id").modal({onClose: function (dialog) {
dialog.data.fadeOut('slow', function () {
dialog.container.slideUp('slow', function () {
dialog.overlay.fadeOut('slow', function () {
$.modal.close(); // must call this!
});
});
});
}});