Open new window when already logged with watir - ruby

Is there a way to open a new window or tab when already logged in a site, and open it as a logged user?
When I try to open it with a new browser window it opens it as a guest user.
My code structure simplified looks like this right now:
b.goto url
Login(b)
link = b."getlink"
new_b.goto link
I want new_b to open as logged.

Related

Typo3 Session lost in MS-Edge when opening a new window

I'm experiencing a strange problem with the Edge-Browser.
I'm using an ajax-call to login a user. As long as the user is in the same window, the session vars seem to be persistent.
But as soon as I open a new window (target="_blank") the session vars seem to be lost and the user isn't logged in anymore. The session vars are gone in the opening window as well.
I'm using this to set and get the session vars:
$sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', self::$prefixKey . $key);
$GLOBALS['TSFE']->fe_user->setKey('ses', self::$prefixKey . $key, $sessionData);
$GLOBALS['TSFE']->fe_user->storeSessionData();
It's happening in all versions of Edge - interestingly, for once it doesn't happen in IE.
Any ideas?
[Edit for clarification]: The new window is on the same domain as the opening one. No subdomains, no nothing.
Which version of Edge browser are you using? Please refer to the following steps to make sure you are not disabled cookies in Edge browser:
Open Edge browser, click on the More actions button in the top right
corner and select Settings.
Click View Advanced Settings. You’ll need to scroll down to the
bottom of the page.
Press the dropdown arrow under the Cookies field.
Select Don't block cookies.
If still not working, try to reset the Edge browser setting.

How to make "stay logged in" work in Selenium webdriver?

I am working in a website like https://jira.atlassian.com/ using firefox, after clicking the "log in" on the top right corner, i am taken to the next login page, where on the right of "log in" button, there is this "stay logged in" checkbox, already checked.
I tested it manually. It seems that after i log in successfully, if i do not exit the page by log out, but simply close the page, the next time i enter https://jira.atlassian.com/, i am already logged in. Ok, make sense.
However, if testing such using selenium webdriver, log in, close page, open page again, the above does not happen.
My question is what is the mechanism for this "stay logged in", is it the same as "remember me"? and how do i make it happen when using selenium webdriver?
Up till now my understanding is:
this happens because of cookie
cookie is stored in firefox profile
selenium start with a default profile that does not include cookie, and can not store cookie during the test
Is there a relatively standard solution for this problem, in java preferably?
Thanks,
As far as I am aware, each instance of loading a FF with Selenium opens a stripped browser with no history/cookies/extensions etc. It's as if you have just download FF for the first time and its a fresh copy. I am not sure how to solve this issue. Maybe if you keep the session open by not closing the browser down but log out manually and not closing down the browser. Or open a new tab and opening the same address.
you can try to store the cookies and apply them to your new firefox instance
get the cookies using:
Set<Cookie> cookies = driver.manage().getCookies();
and than apply them to your new webdriver instance:
for(Cookie cook : cookies) {
driver.manage().addCookie(cook);
}

Can't access new window in Capybara

I've been trying to access a new window (well tab) when using Capybara, but keep getting
Selenium::WebDriver::Error::NoSuchWindowError: no such window
My process and understanding so far is
#session_1 = Capybara::Session.new(:chrome)
#session_1.visit("www.google.com")
So at this stage i have google open. Now lets say i want to open google in a new tab/window
#session_1.open_new_window
This opens a new window, and to access those windows I can do
#session_1.windows
which returns an array of windows
[#<Window #handle="CDwindow-09B6E81E-7874-4686-86A9-8BFB917E0F4F">,
#<Window #handle="CDwindow-5DA14173-8D63-422A-BF98-39B7C2A5D2DB">]
So as a test I wanted to check that latest windows url matches about:blank
#new_tab = #session_1.windows.last
# #new_tab = #<Window #handle="CDwindow-5DA14173-8D63-422A-BF98-39B7C2A5D2DB">
page.within_window #new_tab do
expect(current_url).to eq('about:blank')
end
It's here I get the error.
What I would like to know is
1) How to select the new tab
2) how to open a new url within the new tab
So I found the answer, turns out it was a lot simpler than i was trying, credit goes to Keiran Betteley and this post
#session_1.open_new_window
#session_1.switch_to_window(#session_1.windows.last)
#session_1.visit("url")
Capybara has a number of methods for dealing with windows, and open_new_window returns the window it opened so there's no need to go looking through the list of all windows
#session1.within_window(#session_1.open_new_window) do
#sessuion1.visit("url")
... more actions performed in the new window
end

How I can access the data from a popup page with watir?

I want to access the data in a popup window containing a login form, this window opens when you click on a logo, this line contains the code to execute the javascript: <div id="loadDIV" class="containerLogo" onclick="ventanaSecundaria('/Security-war/autentia/Login.jsp?sion=c5ac379249711c18cf6e030c8400',800,600); "></div>
with this line run the script:
browser = browser.div(:class => "containerLogo").fire_event :click
watir open in a new popup form.
The problem is that I can not access the data from the popup window and need to fill the form containing, try the following:puts browser.text.include? 'Login'
and get false, then I thought that maybe I could not access the other popup and look for something to not open another window but only refresh the I'm using and so we can access its contents, looking I found that I can do this:
browser.goto("javascript:document.getElementByClass()'containerLogo').click()")
but I try to console returns 'true' and the browser does not update.
Update
You can switch windows simply with this:
browser.window(:index => 1).use
and to be sure we change verify the url window with this:
browser.window.url
When a new browser window is opened, you can then ‘use’ the new
window. [Browser Popups | Watir Webdriver]
browser.window(:title => "annoying popup").use do
browser.button(:id => "close").click
end

Wicket - Internet Explorer double submit

I have a big problem with Internet Explorer 7 and 8.
SITUATION:
I have a FORM that build a Medical Prescription. When I hit the save button, the script saves the DomainObject on DB and set a boolean property (of panel where the form is added) called "saved" to true and a byte[] property called PDF with bytestream.
On RenderHead of Panel, I read this boolean and, if is true, I force the trigger of a hidden button with this code:
String js = "$('#" + printPDF.getMarkupId() + "').click();";
response.renderOnDomReadyJavaScript(js);
The button executes this code:
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(new ByteArrayResourceStream(pdf, "application/pdf"));
handler.setFileName("foo.pdf");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
This code work perfecly on FF and Chrome. The Browser download windows appears and the user can save the PDF on HD.
Unfortunally, Internet Explorer has that damn security behavior that is triggered when a site require something to download. That warning require a user validation. A yellow Bar appear and the user is force to hit "Download".
screenshot http://imageshack.us/a/img198/1438/securityg.jpg
When I hit Download File, the form is submitted again with the exact state I had when I hit save the first time. So no previous INSERT on DB is already committed; The Session is resetted to the previous state etc...
The result is a double INSERT on DB of the Domain Ojbect.
Any clue to resolve this?
The problem is that you click download link programaticly instead to redirect browser to an URL or open an URL by JS window.open(url). Click a link looks like an unwanted operation that is sometimes restricted by browser.

Resources