On click opens a new tab I need to interact with, however I just stay on the same window - angularjs

I am new to protractor and AngularJS just starting to get the hang of it. I have a login page that on click opens a new browser tab. The new browser tab is where I want to continue my test however I do not know how to do switch to the new browser tab.
I've tried the below code that was suggested here however it didn't do anything just stayed on the page.
element(by.css('span.icon.icon-add')).click();.then(function() {
browser.getAllWindowHandles().then(function(handles) {
newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function() {
element.all(by.css("input[type$='text']")).first().clear().sendKeys('anemailaddy#newmarketinc.com');
});
});
});
Any help would be fantastic! Thank you

changed code to look like this:
this.clicksAddUser = function() {
element(by.css('span.booking-icon.icon-gear')).click();
element.all(by.css('li:nth-of-type(4) > a')).click().then(function() {
browser.getAllWindowHandles().then(function(handles) {
newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function() {
element(by.css('span.icon.icon-add')).click()
element.all(by.css("input[type$='text']")).first().clear().sendKeys('anemailaddy#newmarketinc.com');
});
});
});
Because I was clicking a drop down menu in a separate this statement the drop down menu was closing before there was a chance to click on the login button. combined the code fixed the problem.

Related

How to focus on second tab and work on it using selenium webdriver

I have opened the link now i am clicking on login link on that page,
By clicking on login button its opening in a new tab automatically. I have to fill the form in that tab. For that i tried following code:
Actions act = new Actions(Initialsetupfirefox.driver);
new Actions(Initialsetupfirefox.driver) .keyDown(Keys.CONTROL).click(Initialsetupfirefox.driver.findElement(By.xpath("//a[contains(text(),'LOGIN')]")))
.keyUp(Keys.CONTROL)
.perform();
Thread.sleep(3000);
new Actions(Initialsetupfirefox.driver).sendKeys(Initialsetupfirefox.driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(Initialsetupfirefox.driver.findElement(By.tagName("html")),Keys.NUMPAD2).build().perform();
By this i am able to switch the focus but not able to do anything in this tab.
Please suggest
you can do like this:
Set<String> handles = driver.getWindowHandles();
String currentHandle = driver.getWindowHandle();
for (String handle : handles) {
if (!handle .equals(currentHandle))
{
driver.switchTo().window(handle);
}
}
//fill your form in the other tab
......
//go back to first tab if you want
driver.switchTo().window(currentHandle);
This it the code when using selenium with Node.js and Typescript
const mainHandle = await this.driver.getWindowHandle();
// load new tab here ..
const allHandles = await this.driver.getAllWindowHandles();
for (const handle of allHandles) {
if (handle !== mainHandle) {
await this.driver.switchTo().window(handle);
}
}
Get the browser-tabs and do as you like:
List<String> browserTabs = Lists.newArrayList(driver.getWindowHandles());
driver.switchTo().window(browserTabs.get(1)); // Switch to second tab
// Do something on second tab here...
driver.switchTo().window(browserTabs.get(0)); // Return to first tab
// Do something on first tab here...

get all dialogs in page in AEM

Is there any direct way to get dialog object of all components which are dragged on page.
For ex: when we load page and if there is any component like text, image are on page, I can get dialog. Please suggest?
Yes, it is possible. Attach a listener which listens to the editablesready event fired by WCM. Get all the editables on the page using the #getEditables() method of CQ.WCM and then get the dialog of each editable if it is present.
Sample code below.
CQ.WCM.on('editablesready', function() {
var editables = CQ.WCM.getEditables();
for(var path in editables) {
var editable = editables[path];
try {
console.log(editable.getEditDialog());
//Do stuff
} catch(e) { }
}
});

Using mmenu plugin -- how to remove for desktop?

I am trying out the mmenu plugin (http://mmenu.frebsite.nl/) and am super excited about it. I have it working for my responsive site... The only problem is that, when I go from a width with the mmenu working to a desktop view (like say 768px to 1024px or bigger), I need the mmenu to go away, remove itself, etc.
Because the mmenu plugin pulls my nav list out of its original spot in the HTML, I need it to get put back again and show itself... Not seeing anything about this in the docs. If I missed it or you have ideas, let me know!
Thanks.
Rather than clone the menu I think a better option would be to initiate the jQuery function when the screen is below a certain size.
$(window).resize(function() {
if ($(window).width() < 768) {
$(function() {
$(' nav#menu').mmenu();
});
}
else {
do some thing else
}
});
I have solved this by cloning the menu when the browser size is reduced (using Harvey: http://harvesthq.github.io/harvey/) and only activating it with mmenu at this point. When I resize back up, I delete the cloned mobile version of the menu, and then show the desktop menu again. One problem I faced was that if you resize back up to desktop with the mobile menu expanded, it didn't automatically close. I fixed this by adding a trigger event to close it before removing the mobile version.
Markup:
<ul id="menu">
<li class="menu-item">
Home
</li>
.....
</ul>
Jquery:
$( document ).ready(function() {
/* Add and remove the mobile version of the menu */
var toggleMenu = {
elem: $("#menu"),
mobile: function(){
//clone the existing top menu and append it to the mobile menu
var menu = this.elem.clone(true).addClass("mobile-added").appendTo("#mobile-menu");
//activate mmenu
$("#mobile-menu").mmenu({
position: "right",
zposition: "back",
});
//hide desktop top menu
this.elem.hide();
},
desktop: function(){
//close the menu
$("#mobile-menu").trigger("close.mm");
//remove cloned menu
$('.mobile-added').remove();
//reshow desktop menu
this.elem.show();
}
};
Harvey.attach('screen and (max-width:1024px)', {
setup: function(){ // called when the query becomes valid for the first time
},
on: function(){ // called each time the query is activated
toggleMenu.mobile();
},
off: function(){ // called each time the query is deactivated
}
});
Harvey.attach('screen and (min-width:1025px)', {
setup: function(){ // called when the query becomes valid for the first time
},
on: function(){ // called each time the query is activated
toggleMenu.desktop();
},
off: function(){// called each time the query is deactivated
}
});
});
You have to clone the menu and making a media query.
http://mmenu.frebsite.nl/support/tips-and-tricks.html
Here you can find the explanation.
Post that in your CSS
#media screen and (min-width:1000px) {
#menu {
display:none
}
}
Hi may be setting the options will help you.
The options page is here
and a working example is here and here

appcelerator titanium - edit button in tabgroup doesn't go away

Using Titanium mobile sdk 1.7.2, I created a tabgroup with 11 tabs. The problem is when I open any of the tabs inside the 'more' tab, if the child window has a right navbar button, some times the 'edit' button of the 'more' tab doesn't go away..
my code is:
app.js:
var tabGroup=Titanium.UI.createTabGroup({top:20});
............
/** list of windows and tabs **/
............
var win9 = Titanium.UI.createWindow({
url:'discover.js',
title:'Discover',
navBarHidden:true,
barColor: navBarColor
});
var tab9 = Titanium.UI.createTab({
icon:'images/icons/Discover.png',
title:'Discover',
window:win9
});
discover.js:
win=Titanium.UI.currentWindow;
var btn=Titanium.UI.createButton({title:'Discover'});
btn.addEventListener('click',function (){
//do some stuff
});
win.rightNavButton=btn;
the problem is, sometimes when I open the 'tab9' which opens 'win9' my button (btn) doesn't appear, the 'edit' button of the 'more' is shown instead.
N.B: the click event listener works just fine, It is the 'edit' title that persists. Any one knows how to solve this?
thank you,
You need to set allowUserCustomization:false in your Tabgroup.
var tabGroup=Titanium.UI.createTabGroup({top:20,allowUserCustomization:false});
try to set
win.rightNavButton = null;
win.rightNavButton = btn;

Add a title to a new window in Titanium

I'm trying to open a new window via a button to the configuration page but how do you add a title (at the top of the screen) to a newly created window?
On the starting page, I have a button created to open a new page as:
var btnConfig = Ti.UI.createButton({
backgroundImage:'img/settings.png',
height:33,
width:33
});
win1.rightNavButton = btnConfig;
btnConfig.addEventListener('click',function(){
Ti.include('win_config.js');
})
Then on win_config.js :
var win_config = Titanium.UI.createWindow({
title:"Configure",
backgroundColor:'#BBB',
});
win_config.open({
transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
});
I thought that by just setting "title" it'll appear but apparently it doesnt.
needed to add "modal:true" in the createWindow
var win_config = Titanium.UI.createWindow({
title:"Configure",
backgroundColor:'#BBB',
modal:true
});

Resources