How to open a External browser in Eclipse Editor - eclipse-plugin

How to open an External browser like Safari from open option with in Eclipse plugin programmaticly?

try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL("http://stackoverflow.com"));
} catch (PartInitException | MalformedURLException e) {
e.printStackTrace();
}
This will open the external browser.

Related

How to perform automation in edge browser open using desktop application?

I have a Web application to automate using selenium and Java.
Application supports IE Browser on windows10 and for windows11 we have created an .lnk file to open same application in Edge browser because IE is no longer. And we have some videos to be streamed in application for which media player to be installed and more.
Scenario :
I have to open ABC.lnk application from desktop
Once clicked on ABC.lnk application, our application will open in Edge browser.
for step 1 : using below code to open ABC.lnk application
public static void openWindowApplication() {
String command = "C:\\Users\\Kasper\\Desktop\\ABC.lnk";
try {
Runtime.getRuntime().exec("cmd /c " + command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Step 2 :
Edge driver initialization Code :
System.setProperty("webdriver.edge.driver", FileReaderManager.getInstance().getConfigReader().getDriverPath() + "/msedgedriver.exe");
//Creating an object of EdgeDriver
driver = new EdgeDriver();
driver.manage().window().maximize();
//Deleting all the cookies
driver.manage().deleteAllCookies();
//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
I have used above code to achieve above scenarios. But 2 edge browsers are getting open and nothing is happening because of above code snippet and Step 1 is required to open ABC.lnk and application opens in edge browser on click on it.
And I have to perform automation on open browser through ABC.lnk click.
How can I perform automation in same edge browser open in step 1.
Thanks in advance.

selenium chrome driver select certificate popup confirmation in c#

I am automating tests using selenium chrome webdriver. Whenever I launch the site, I get a certificate selection popup like the one below:
The following code works in Java:
try {
driver.get(url);
} catch (Exception e) {
e.printStackTrace();
}
};
public void myfunction {
try {
Thread mthread = new Thread(mlauncher);
mthread.start
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (Exception e) {
e.printStackTrace();
}
I have not found code that works in c#.
I try with your solution, I use AutoIt.AutoItX library and use it to select a certificate but I have a problem.
when I click in the LogIn button, it show on the popup possibility to select ssl certificate.
The execution of the automatic test stops, and waits for the selection of the certificate.
When I manually select certificate, my automatic test continues with further execution, of that part that should select automaticly certificate in AutoIt.AutoItX.
It should contue automaticly without stopping, AutoIt.AutoItX part should not be on hold, but should be used to select a certificate.
{
welcomePage.LogIn.Click();
AutoIt.AutoItX.Send("{TAB}", 0);
AutoIt.AutoItX.Send(url, 10);
AutoIt.AutoItX.Send("{ENTER}", 0);
}

Winium remote automation?

I am using Winium to automate a desktop application. The process is I download a file from the web and execute it. which opens the remote application. Till here everything is working fine, but I am unable to access any control of that newly launched remote Citrix application. Any help would be appreciated.
public void SetupEnv() throws InterruptedException
{
DesktopOptions options = new DesktopOptions();
options.setApplicationPath("C:\\Users\\ajinkya\\Downloads\\launch.ica");
try
{
driver = new WiniumDriver(new URL("http://localhost:9999"), options);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Thread.sleep(5000);
driver.findElementByClassName("Transparent Windows Client").click();
Thread.sleep(5000);
}
Maybe you should try something like this:
WebElement window = driver.findElementByName("abcd.exe");
WebElement menuItem = window.findElement(By.name ("Find Item"));
menuItem.click();

Closing all open command prompt leads to error in forked process in testNG

I am using testNG for mobile automation and I want to close multiple command prompts(appium servers) which i launched. For this, I am using the below code
#AfterSuite
public void closeCommandPrompts() throws IOException, InterruptedException{
System.out.println("After suite");
Thread.sleep(8000);
Runtime.getRuntime().exec("taskkill /F /IM node.exe");
System.out.println("closed node.exe");
Runtime.getRuntime().exec("taskkill /F /IM cmd.exe");
The last line if I commnet it out works fine, however if they are not commented it gives an error in the forked process.
I guess testNG is internally using command prompt which i am trying to close when iam using taskkilll in #aftersuite.
Please help me in getting some work around.
You can use following code :
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("taskkill");
command.addArgument("/F");
command.addArgument("/IM");
command.addArgument("node.exe");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
System.out.println("Stopped appium node ! ");
} catch (IOException e) {
System.out.println("FAIL => Unable to stop appium server "+e.getMessage());
e.printStackTrace();
}

Handling Browser Authentication using Selenium

Does anyone know about handling Browser Authentication using Selenium or any other tool during automation?
EDIT in 2015:
This answer is outdated. WebDriver nowadays supports authentication! See How to handle authentication popup with Selenium WebDriver using Java
Original answer:
This is not handled very well by Selenium.
You can try using http://username:password#example.com/yourpage
instead of just http://example.com/yourpage
However, as far as I know, Firefox will still pop up a browser dialog requesting a confirmation.
You can try Robot if you're using Java (or any similar tool like AutoIt).
You could use driver.manage().addCookie() if you're using WebDriver.
Or a custom FirefoxProfile that has already passed the authentication once.
I spent days on this - literally.
Trying to get past browser level authentication within my company network to hit an application.
The solution was to use the 'unsername:password#' component within the URL, BUT to add a forward slash at the end of the login URL.
So total login URL looks like this (note the '/' after yourpage):
http://username:password#example.com/yourpage/
Works with Watir, Capybara and Selenium Webdriver.
Everything I have read on the Web didn't help me. So before making a request, like this:
driver.get(url);
you have to run a new thread like this:
RunScript runScript = new RunScript();
runScript.start();
In this case you are free to input login and password on another thread of follwing class
public class RunScript extends Thread {
#Override
public void run() {
try {
File file = new File("D:\\jacob-1.18-x86.dll");
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX autoIt = new AutoItX();
Thread.sleep(2000);
autoIt.winActivate("yourWindowName", "");
autoIt.winWaitActive("yourWindowName");
if (autoIt.winExists("yourWindowName")) {
autoIt.send("username{TAB}", false);
autoIt.send("password{Enter}", false);
}
}
} catch (InterruptedException ex) {
//
}
}
}
All the hacks via auto-it, sikuli, etc. just wasting your time when you'll run it in your CI solution, using several browser types / OS / Version / Resolutions etc.
The way to do it correctly is to identify the authentication actual method and perform a login using Rest protocol for instance.
I used it to get the JSESIONID cookie and insert it to the selenium driver.
hint on that: go to a non-exiting url of the domian first, then set the cookie, then go to the required url - you are logged-in.
use: rest client authentication to get the JSESSION ID
and With this information:
browser().navigate(foo.getUrl()+"non-exiting-url");
//the information got from the rest client login:
Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure, isHttpOnly);
try {
driver.manage().addCookie(cookie);
} catch (Exception e) {
System.out.println(e.toString());
}
browser().navigate(foo.getUrl());
you can use auto IT script to handle this problem
WinWaitActive("[CLASS:Chrome_WidgetWin_1]", "", time)
Send("user")
Send("{TAB}")
Send("pass")
Send("{ENTER}")
with Chrome 70 and other versions :
http://username:password#example.com/yourpage
You can use Java Robot class with Selenium 2 /Selenium WebDriver using Firefox
WebDriver driver = new FirefoxDriver();
driver.get("http://localhost:9990");
WebElement myDynamicElement = driver.findElement(By.id("app"));
Alert alert = driver.switchTo().alert();
try {
Robot robot = new Robot();
alert.sendKeys("username");
robot.keyPress(KeyEvent.VK_TAB);//go to password feild
robot.keyPress(KeyEvent.VK_P);
robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
}
Using Selenium with Robot
http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Robot.html