Winium remote automation? - selenium

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();

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);
}

Integration testing with Selenium Webdrive on a project with Continous Integration

I have a question. When I run a selenium webdrive integration test on my webb app, the web app must be running, because selenium browses to a debug version of my app (which is launched in IIS Express from Visual Studios). The problem is that if I want to achive this using CI development practice, on a dedicated CI machine, that machine have to be running a version of my webb app that's based on the current mainline code from subversion directory.
The code base constantly changes, and so theoretically you could run and restart the web app on the CI machine with code from the subversion dir, so that the tests always cover the latests commit.
Each individual developer on the project doesn't have any problems running the integration tests on the pre-commit build/test. And the unit tests can be handled with Cruise Control, MsBuild, subversion and NUnit working together. But running the integration tests (selenium webdrive test) on the integration server automatically with dynamic codebase is what I'm wondering about. Does anyone have experience of this, perhaps examples?
EDIT:
Arran has suggested that you can utilize a dedicated test enviroment to solve this problem. I don't quite practically understand how dedicated test enviroments works, and how practically it would works to solve this problem. The answers received doesn't seems to be automatable to the point where it can be implemented with the concurrent integration flow of Continous Integration. Does anyone else have any experience or thoughts on the matter?
This is the Selenium Webdrive code for reference:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;
using System.Threading.Tasks;
using System.Threading;
namespace ChatProj.Tests
{
[TestFixture]
class WebDriverTestClass
{
private IWebDriver _driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetUp()
{
_driver = new FirefoxDriver();
baseURL = "http://localhost:59932/";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
_driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Repeat(2)]
[Test]
public void TestFirefox()
{
_driver.Navigate().GoToUrl(baseURL + "");
IWebElement userNameInput = _driver.FindElement(By.Name("UserName"));
userNameInput.SendKeys("Svenneglenne");
IWebElement passwordInput = _driver.FindElement(By.Name("Password"));
passwordInput.SendKeys("password");
_driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
IWebElement messageBox = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("message"));
});
IWebElement adminMessageWaiter = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.XPath("//ul[#id='discussion']/li[1]"));
});
System.Console.Out.WriteLine("STUFF");
//IWebElement query = driver.FindElement(By.Id("message"));
String textSnippet = "This is a selenium test";
adminMessageWaiter.SendKeys("");
messageBox.SendKeys("This is a selenium test");
IWebElement waitForJava = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.XPath("//ul[#id='discussion']/li[1]"));
});
//Thread.Sleep(2000);
WaitForPageLoad(10);
_driver.FindElement(By.Id("sendmessage")).Click();
//Thread.Sleep(2000);
_driver.FindElement(By.LinkText("Logg")).Click();
IWebElement loggWaiter = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.XPath("//div[#id='body']/section/table/tbody/tr/td[2]"));
});
Assert.AreEqual(textSnippet, loggWaiter.Text);
_driver.FindElement(By.LinkText("MPM Graph")).Click();
Thread.Sleep(2000);
}
public void WaitForPageLoad(int maxWaitTimeInSeconds)
{
string state = string.Empty;
try
{
WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(maxWaitTimeInSeconds));
//Checks every 500 ms whether predicate returns true if returns exit otherwise keep trying till it returns ture
wait.Until(d =>
{
try
{
state = ((IJavaScriptExecutor)_driver).ExecuteScript(#"return document.readyState").ToString();
}
catch (InvalidOperationException)
{
//Ignore
}
catch (NoSuchWindowException)
{
//when popup is closed, switch to last windows
_driver.SwitchTo().Window(_driver.WindowHandles.Last());
}
//In IE7 there are chances we may get state as loaded instead of complete
return (state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase));
});
}
catch (TimeoutException)
{
//sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
throw;
}
catch (NullReferenceException)
{
//sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
throw;
}
catch (WebDriverException)
{
if (_driver.WindowHandles.Count == 1)
{
_driver.SwitchTo().Window(_driver.WindowHandles[0]);
}
state = ((IJavaScriptExecutor)_driver).ExecuteScript(#"return document.readyState").ToString();
if (!(state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase)))
throw;
}
}
}
}
the basic answer for your test automation automation is to run it in your gitlab CI
i dont undrestand what do you mean by running on "to be running a version of my webb app"
is this version of your webb app has a spicific url or domaine ?
if not then the test automation project is continous integration every version of your app the test project gonna run on it , if it has upgrade , then you need to upgrade your test automation to follow the flow
i hope thats help

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

How to open a External browser in Eclipse Editor

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.