Selenium: Testing interaction between users on different browsers - firefox

I am implementing a suite to test the behavior of a chat. Each user performs different actions to log in into the chat on different browsers.
I have implemented each test case separately and work fine. I also implemented one suite which includes both cases, one first and then the other and it runs but it looks like both browsers are not sharing the information, because it does not show the user logged in. Here is an example of that I am implementing in java:
public class connect_facebook extends SeleneseTestCase{
Selenium sele1 = null;
Selenium sele2 = null;
#Before
public void setUp() throws Exception {
//Establish the first browser
sele1 = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.es/");
//Establish the second browser
sele2 = new DefaultSelenium("localhost", 4444, "*googlechrome " , "http://www.facebook.com");
//Start the first test case
sele1.start();
//Start the second test case
sele2.start();
}
//Send the message to a friend in Facebook
#Test
public void testConnect_facebook_nocookies() throws Exception {
...
}
I don't stop sele1
//Open Facebook, check the message and open Zaraproxy to start Connect
#Test
public void testCheck_mail_facebook() throws Exception {
...
}
NOTE: What it does is at the very beginning opens FF and Chrome, then closes Chrome and runs sele1. After that does not close FF but opens another FF and Chome browser, closes FF and then runs sele2 with Chrome.
When sele2 opens the chat panel, the user of sele1 (FF) appears offline.
I am using selenium server as a HUB and started another server as a node (not using selenium grid). Want to resolve with selenium RC first before passing to selenium Grid because installation of the Grid have been given me some problems.
Any help is welcome! Thanks in advance!
B

Related

Second Instance of firefox browser is not opening in selenium

I am new to selenium. And I am trying to open multiple instances of firefox browser.
I am not using any Grid. And My selenium version is 2.47.1 and firefox version is 37.0.1.
Also, my browser is not closing automatically even I used quit()
Below is my code:
package TestAutomation;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestClassOpenBrowser {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
WebDriver d2 = new FirefoxDriver();
d2.get("http://yahoo.com");
d2.manage().window().maximize();
driver.quit();
d2.quit();
}
}
Keep in mind that version 2.42.0 was probably the last version of Selenium that really supported Firefox native events (for Firefox 31). Selenium 2.43 says it supports native events for Firefox32 but I don't think it really worked. In general, if you are running local Firefox instances, you want to be using Firefox 31 or Firefox31.0.6 , even if your on Selenium 2.47+ .
Also, if you are having trouble managing multiple driver instances, take a look at how I did it here (see the ShootoutSuiteTestBase.java
class) :
https://gist.github.com/djangofan/f5eda36f556fc55a5dcb
Tried with jar file version 2.45.0. it worked. Issue was in the latest jar files 2.47.1

Selenium Webdriver C# - Stop browser opening on program start up

I am writing a program for automation testing and it works fine. I do however have an issue with the amount of time it takes from the program to start up. This is down to the face that I initialize the IWebdriver = new firefoxDriver() in the public partial class so to allow for all functions to access the driver class with ease and no fuss.
So when i load the program the browser loads which takes maybe 15/20 seconds followed by the GUI I have built. Does anybody know a way of making the "driver" global but not initializing the browser until I call it in a function? i.e. I can load my program and fiddle with the variables etc and then when I am ready I click a button, then the browser loads and executes the function all without have the Iwebdriver = new firefox() in each function separately. Also the reason I have coded it this way (making it global) was due to different browser session issues. It would not see other browsers outside of the initial one on start up
Here is the basic code I am working with
public partial class Main : Form
{
IWebDriver driver = new FirefoxDriver();
public Main()
{
InitializeComponent();
}
}
Initialize it the same way but make it static:
Public static IWebDriver Driver;
And then set it to FirefoxDriver where you need it to open the browser:
Driver = new FirefoxDriver();

Update UI after download with FileDownloader

I have some code which extends a button to offer a download with FileDownloader:
private final InputStream stream;
private final Label label;
private final Button button;
//…
StreamResource.StreamSource source = new StreamResource.StreamSource() {
#Override
public InputStream getStream() {
label.setValue("downloaded");
return stream;
}
};
FileDownloader downloader = new FileDownloader(new StreamResource(source));
downloader.extend(button);
This code wants to update the UI as well (set the Label to "downloaded").
This works in some browsers (Konqueror and Chromium), but in Firefox (31) it doesn't.
The behaviour in FF is quiet strange: The first click on the button starts the download without any update of the UI. A second click on the button shows the update of the UI only (i.e. no download).
My suspicion is that FF doesn't like FileDownloader's iframe:
Please note that the download will be started in an iframe
Any idea how I can achieve an update of the UI from within StreamSource.getStream()? If not, any better ideas to offer a download which updates the UI as well?
It's vaadin-7.1.15.
maybe it will work when you update the label value in a clicklistener?
button.addClickListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
label.setValue("downloaded");
}
});
I would also try to set the label to immediate=true:
label.setImmediate(true);
You can either add the ClickListener to the button as suggested, or you need to let your UI poll the server (or even better use push).
That the second click on the button will update the UI is caused by the fact, that this click initiates a client request and the server will answer with the changes in the UI. Before that you have updated the UI correctly - on server side - but the browser does not know about this. Therefore you should use UI listeners like the ButtonClickListener.
By the way I don't think that this is only a firefox issue.

Webdriver not finding elements in remote IE

I'm having a strange issue with webdriver. I have a local environment and a remote environment to perform my tests; they work great in Firefox in both environment, but with Internet Explorer 8, they only work in local.
Whenever I run the tests against the remote server it doesn't even find the textbox elements to make the login. I'm using a wait when finding elements, and I tried to increase the time until minutes, but nothing. I can see the element in IE browsing through the source code. I even compared the html generated from both of them and is the same.
I'm using selenium through JBehave (JBehave-web-selenium-3.3.4 with selenium-ie-driver-2.0b3)
To retrieve the element I'm using:
public WebElement getElementById(String elementId){
return getMyWaiter()
.waitForMe(By.id(elementId), TEST_DELAY_IN_S);
}
public WebElement waitForMe(By locator, int timeout) {
WebDriverWait wait = new WebDriverWait(driver, timeout);
return wait.until(Waiter.presenceOfElementLocated(locator));
}
public static Function<WebDriver, WebElement> presenceOfElementLocated(
final By locator) {
return new Function<WebDriver, WebElement>() {
#Override
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
};
}
Any idea why the different behaviour?
I found the issue, it's a security issue with Internet Explorer and remote servers. To fix it just add the remote server to the Trusted Sites (Tools > Options > Security Tab > Trusted Site)
This works for. On IE goto Internet Option -> Security -> Uncheck Enable Protected mode for all the tabs. And rerun your project

Internet Explorer buggy when accessing a custom weblogic provider

I've created a custom Weblogic Security Authentication Provider on version 10.3 that includes a custom login module to validate users. As part of the provider, I've implemented the ServletAuthenticationFilter and added one filter. The filter acts as a common log on page for all the applications within the domain.
When we access any secured URLs by entering them in the address bar, this works fine in IE and Firefox. But when we bookmark the link in IE an odd thing happens. If I click the bookmark, you will see our log on page, then after you've successfully logged into the system the basic auth page will display, even though the user is already authenticated. This never happens in Firefox, only IE. It's also intermittent. 1 time out of 5 IE will correctly redirect and not show the basic auth window. Firefox and Opera will correctly redirect everytime. We've captured the response headers and compared the success and failures, they are identical.
final boolean isAuthenticated = authenticateUser(userName, password, req);
// Send user on to the original URL
if (isAuthenticated) {
res.sendRedirect(targetURL);
return;
}
As you can see, once the user is authenticated I do a redirect to the original URL. Is there a step I'm missing? The authenticateUser() method is taken verbatim from an example in Oracle's documents.
private boolean authenticateUser(final String userName, final String password, HttpServletRequest request) {
boolean results;
try {
ServletAuthentication.login(new CallbackHandler() {
#Override
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(userName);
}
if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(password.toCharArray());
}
}
}
}, request);
results = true;
} catch (LoginException e) {
results = false;
}
return results;
I am asking the question here because I don't know if the issue is with the Weblogic config or the code. If this question is more suited to ServerFault please let me know and I will post there.
It is odd that it works everytime in Firefox and Opera but not in Internet Explorer. I wish that not using Internet Explorer was an option but it is currently the company standard. Any help or direction would be appreciated. I have tested against IE 6 & 8 and deployed the custom provider on 3 different environments and I can still reproduce the bug.
We figured it out.
The fix was to disable auth cookies on the weblogic server. For some reason Internet Explorer would lose the cookie causing Weblogic to think the session was being hacked. That is what prompted the basic auth login.
We still don't know what was causing IE to lose the cookie but this provider is for an intranet so the fix won't harm our overall security.
I hope this helps someone else.

Resources