Launch Firefox in the same tab - java

Problem Description: On my user's machine the default browser is IE 7. Because of security reasons the default browser cannot be changed. On the click of another application on my user's machine, my application gets launched. My application gets launched in IE 7. In my application I provide users the ability to launch firefox on the click of a button. I am using java to launch a New Firefox Window.
String url = "www.google.com";
String[] cmdArray = new String[2];
cmdArray[0] = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
cmdArray[1] = url;
Runtime.getRuntime().exec(cmdArray);
The above piece of code works, however it opens a new Firefox tab every time.
Is there any way to check if Firefox is already running (with a specific url), then open the 'url' in the same tab?
If this is not possible to achieve in java, can this be achieved in javascript?

You can call with -new-tab option:
firefox.exe -new-tab www.google.com
Reference: https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options

Related

Unable to capture text inside new window in Java Selenium Headless browser

I'm running all my test suites on Jenkins which is deployed on AWS EC2 instance. There is a scenario where when I click on a button, new small window opens up and I'm doing assertion for the text visible inside the small newly opened window. But my tests are failing when I run using Headless mode. But, same scripts works fine when I run scripts locally without opting for headless browser.
The issue here is the scripts are failing because of headless browser since it's unable to capture text inside small window which has opened after click of button.
This class is extending InitiateDriver class which explained. Below class is trying to fetch text which is visible inside the new window which just opened after clicked on SignInWithGSuiteSSOClick() button.
Here is the code:
// click on a button
GSuiteobject.SignInWithGSuiteSSOClick().click();
String winHandleBefore = driver.getWindowHandle();
// Here trying to capture text inside new window opened up basically gmail window to enter email
String signInHeader = GSuiteobject.GsuiteSignInHeader().getText();
Assert.assertEquals(signInHeader, "Sign in");
GSuiteobject.GsuiteEmail().sendKeys("example#gmail.com");
InitiateDriver.java
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1920, 1080");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
The same code works in browser mode but not in headless. But the driver will be initialized but it fails only while capturing text. Please help me out I'm stuck here and unable to execute it on Jenkins as a headless browser.
Headless chrome browser's gmail UI will be different from actual gmail UI(latest). Hence it fails when we run headless chrome for automating gmail login since xpaths will differ. We can validate that by taking Screenshot by running on headless and normal browser.
I suggest to take screenshot using both headless and normal browser. To check on xpaths for headless we can try driver.getPageSource() method.

how to handle Mobile OTP using selenium

There is one case that, when i open the URL manually in chrome browser and give the credentials.
After clicking on sign in button one OTP will come to mobile. There is one checkbox after entering the OTP. Don't ask OTP for this browser. If we click on that check box and login into the portal. Then from next time if we open same browser and access the portal, it will not ask for OTP. So can we automatically open same browser every time after closing browser. Without calling new chrome instance.
You can use the default profile to use the local chrome profile once the OTP is completed manually.
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
ChromeDriver driver = new ChromeDriver(options);
You can get the default profile path as shown in the below screenshot.
Please open chrome://version in the browser to see what profile Chrome is using.

Running desktop application with different user credentials - Winium Automation

I came across a situation where i need to open the desktop application with different user rather than current windows user.
Now to launch the application am using below code ,
DesktopOptions dop = new DesktopOptions();
dop.setApplicationPath("Path to executable file");
WiniumDriver d = new WiniumDriver(new URL("http://localhost:9999"), dop);
but by default the application opens with current windows user , instead i want to open with different user.
FYI , this can be done manually by Shift+Right Click and click on Run with different user option.
Can any one suggest how can i do this with Winium please ?

In parallel execution, safari browser navigate to url with out login page automatically

I am using selenium web driver 2.48 and safari driver 2.48 and safari version 8.0.8
I am facing a problem on running my test execution in safari driver.The problem is
"In parallel execution, if in one safari window,login is successfull, than in other
safari windows, this login page is not shown,
that means safri navigate to url with
out login as one safari window already complete login."
and for this reason, i am facing below issue in parallel execution:
"CSRF verification failed.Request aborted"
I want like that for parallel execution:
if five safari browser window open, in each window, login page will be appeared.
In a sense, each safari driver instance will not share other safari driver
instances resources or any other thing
I have changed safari preferences settings but its not helping.
Is there any best way to declare safari driver or i need to add any desired capabilities or
any other things in safari preferences or any any good suggestion.
please and thanks.
i am using the following code:
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
DesiredCapabilities dc = DesiredCapabilities.safari();
dc.setCapability(SafariOptions.CAPABILITY, safariOptions);
currentDriver = new SafariDriver(dc);
Set<Cookie> cookies = currentDriver.manage().getCookies();
currentDriver.manage().deleteAllCookies();
if(!cookies.isEmpty())
{
Iterator<Cookie> iter= currentDriver.manage().getCookies().iterator();
while(iter.hasNext()){
Cookie C = iter.next();
}
cookies.clear();
}
I personally have not used safari before. And as you said that the behavior in all other browsers are as you expect it to be. I would like you to try the following.
There is a way by which you can specify the profile of the driver instance to be used. I would suggest you to create separate profiles for each instance and try out . How to do that is explained in this answer. This answer explains how to use same profile each time . You need to use a different profile each time. ( Which happens by default in chrome not sure why it wouldn't for safari )

Selenium WebDriver: How to set focus when running exe, file for windows authentication.

In My web driver (Selenium) script I am running exe file before getting windows popup.
java.lang.Runtime.getRuntime().exec("E:\\winauthen.exe"); // Windows Authentication popup
driver.findElement(By.xpath(".//div[#id='home']/div[2]")).click();
Its running fine if focus always on the window But if simultaneously I am working something other the user name and password get print/type on the active page not on the Authentication popup.
How to set focus? that it run weather I am looking in to it or not.
Thanks in advance.

Categories

Resources