How can itegrated AutoIT in WebDriver (Selenium Grid) ? - selenium

I'm launched Selenium Grid (Node and Hub),and testing Web app. But I need provide some action on Windows Open dialog. Can I do that with and how using AutoIt on next way : capabilities.setCapability("browser", "AutoIt") ?

Refer this link for step by step guide on how to use AutoIT with Selenium. This involves using the tool to create a .au3 script which you will need to execute from your code. But from your question, if you want something like capabilities.setCapability("browser", "AutoIt"), you have to use AutoItDriverServer (See README for installation steps).
Its a Selenium like Interface wrapper for AutoIt, so you can basically operate your windows application by the very same selenium methods you are familiar with.
How to Use it:
In the 'autoitdriverserver_python' directory, run the "server.py" file. Now, whenever you want to perform actions on your windows application, just create a new remote driver with capability of 'browserName':'AutoIt'. Ex-
driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={'browserName':'AutoIt'})
driver.get("path to your application")
driver.switch_to_window("window name")
driver.find_element_by_id("your id").click()
Note as mentioned in docs:
AutoIt doesn't find or handle multiple elements specified by location
strategy, therefore, finding elements in WebDriver is not implemented
for AutoItDriverServer. You can only find singular elements.
See this link for all the available commands. To locate elements, for example through ID, you need AutoIT info tool which is available in the entire package.

Related

Appium unable to find UI-Elements using XPath

I need to find UI Elements within my Windows Desktop WPF application using xpath and Appiums xpath-selector.
It's working fine for "simple" applications but fails for my target application.
My environment is:
OS: Windows 10
Target Application: x86 WPF
Appium Windows Driver: 4.0.0.6 beta
Appium Desktop Application: 1.13.0
Selenium WebDriver: 3.141.0
This is what I am trying:
Once I have fired up my target application by the Appium desktop application, its session window tells me the xpath to UI-elements, such as (also see the screenshots):
xpath:
"/Windows/ToolBar/Tab/TabItem[1]"
Appium Session Window Screenshot:
Microsofts inspect.exe screenshot:
The wired thing now is:
If I am using the xpath-string that appium shows me, in order to find the corresponding UI-Element within this session manager itself (by using the search-feature and selecting the xpath-selector), it's unable to find any elements (see screenshots):
Also, if I am using a trivial xpath-string such as
"//*"
or
"/Window"
it fails as well by not finding any elements.
Here, as a contrast, are the same steps captured by screenshots for the baretail.exe notepad application, for which it works, i.e. where I am able to use the provided xpath-string to correctly find the corresponding UI-Element.
Appium Session Windows:
Microsofts inspect.exe:
Appium Session Window search for UI-Element - query:
Appium Session Window search for UI-Element - result:
Eventually, I need to use this from within a C#-project, for which I am using the following code, but i am getting the same result, which is, not finding any UI-Elements matching my xpath-string.
(I debugged the Appium source so far that I already know that the FindElement-request using the xpath-selecotr is submitted successfully, but the Appium server responds with an empty result set of found UI-Elements.)
AppiumOptions options = new AppiumOptions();
options.AddAdditionalCapability("app", "path/to/my/target/application");
options.AddAdditionalCapability("deviceName", "WindowsPC");
options.AddAdditionalCapability("platformName", "Windows");
options.AddAdditionalCapability("newCommandTimeout", "60000");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), options);
Assert.IsNotNull(session);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
string xpath = "/Window/MenuBar/MenuItem[2]"; // valid xpath to an UI-Element
var result = session.FindElementsByXPath(xpath); // successfully returns an empty collection
Anyone, any ideas? Please ...

How to run all scenario of same feature file in one browser? using selenium,java,cucumber

I am using hooks #Before (to initialize browser instance) and #After (to close browser instance) which means if there are three scenarios in feature file then the browser will open three times and close three times.
I want to run all three scenarios in the single browser instance.
Cucumber provides background which lets you set things ups before tests are executed.
The official docs are here. Scroll down to background (or CTRL+F background x3).
Feature File:
Background:
Given browser is initialized.
Scenerio: Test 1
Then browser is running.
And you can write the step definition as usual.

What is the difference between Selenium core extensions and Selenium IDE extensions?

I know that for using my js file I must use Selenium Core extension but I cannot understand what Selenium IDE Extension field is for?
Thanks in advance.
Selenium extensions provide a way to add more functionality/feature to Selenium as per your requirements. This is also known as Selenium User-Extensions and Selenium Custom-Extensions.
The concept is pretty simple, extend Selenium by adding your own actions, assertions and locator-strategies. Add JavaScript methods to the Selenium object prototype and the PageBot object prototype. On startup, Selenium will automatically look through methods on these prototypes, using name patterns to recognize which ones are actions, assertions and locators.
User-Extensions can be used with Selenium IDE (see this) and Selenium RC (see this).
Do not get confused with different names. Same concept is getting used at different places, differently.
"Selenium IDE Extensions" is mainly used to extend the recording behavior of Selenium IDE.
To use the extensions
Copy the extension code into a new .js file. You can place it
anywhere on your disk.
Open Options - Options... in the menu bar.
Choose the saved file in "Selenium IDE extensions" field and click OK.
Restart Selenium IDE by closing the window and opening it again.
Example
By default, Selenium IDE only records click events on certain types of elements (e.g. , , ...).
You can record any click events occured in a page by putting the following code as Selenium IDE extension.
Recorder.removeEventHandler('clickLocator');
Recorder.addEventHandler('clickLocator', 'click', function(event) {
if (event.button == 0) {
this.clickLocator = this.findLocator(event.target);
}
}, { capture: true });

Automate a button click on chrome://extensions page using selenium webdriver

I'm trying to write an automated test that will automate the process of updating a google chrome extension. I'm not aware of another method of doing this automatically so here is what I'm currently trying to do:
Open the chrome extensions page (as far as I'm aware this is just an html page unless I'm missing something).
Click on the "Update extensions" button
Here is what I have tried having opened the chrome extensions page:
IwebElement UpdateButton = driver.findelement(By.Id("update-extensions-now"));
UpdateButton.Click();
For some reason the button click is not registering. I have tried some other locators such as CSS path and Xpath but they don't work either. Also, when I debug this test, it passes fine so I know it's not an issue with any of my locators. I have (as a test) tried to automate clicks on the other elements on this page and it's the same issue. I can't get a handle on any elements on the chrome://extensions page at all.
Has anyone encountered this or have any ideas as to what's going on?
You can use the Chrome extensions API to auto-update required extension.
Find the file "manifest.json" in the default Google Chrome
C:\Users\*UserName*\AppData\Local\Google\Chrome\User Data\Default\Extensions
There find the update URL of your extension:
{
"name": "My extension",
...
"update_url": "http://myhost.com/mytestextension/updates.xml",
...
}
The returned XML by the Google server looks like:
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='yourAppID'>
<updatecheck codebase='http://myhost.com/mytestextension/mte_v2.crx' version='2.0' />
</app>
</gupdate>
appid
The extension or app ID, generated based on a hash of the public key, as described in Packaging. You can find the ID of an extension or Chrome App by going to the Extensions page (chrome://extensions).
codebase
A URL to the .crx file.
version
Used by the client to determine whether it should download the .crx file specified by codebase. It should match the value of "version" in the .crx file's manifest.json file.
The update manifest XML file may contain information about multiple extensions by including multiple elements.
Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:
chrome.exe --extensions-update-frequency=45
Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.
The request to update each individual extension would be:
http://test.com/extension_updates.php?x=id%3DyourAppID%26v%3D1.1
You can find even more detailed information on exntesions developers site: https://developer.chrome.com/extensions
If you look at the HTML of the "chrome://extensions" page you will notice that the "Update extensions now" button is contained within an iframe. You need to switch to the iframe before trying to register a button click. i.e:
(This is in c#. Note that this code is written from memory so it may not be 100% accurate. Also, you will want to write more robust method. This code just quickly demonstrates that by switching to the iframe, it will work ok)
String ChromeExtensionsPage = "chrome://extensions";
driver.Navigate().GoToUrl(ChromeExtensionsPage);
driver.Switchto().Frame("DesiredFrame");
IwebElement UpdateButton = driver.findelement(By.Id("DesiredButtonID"));
UpdateButton.Click();

issues in running selenium in internet explorer

Hi I am trying to run my selenium webdriver on IE9.
WebDriver version : 2.32.0
IE:9
IEDriverServer_win32:2.32.3
windows7
Below is my code:
File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();
Above code logs in to my site but then when I try to click on Securities button I am not able to do it. Securities button starts flickering and then I am notified that unable to find the element.
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with xpath == .//span[text()='Issue Type']
(WARNING: The server did not provide any stacktrace information) –
Same code works fine in FireFox.
Please help as i am suppose to test my UI on InternetExplorer.
I think it is the version compatibility issue.
Can anyone suggest the compatible version set for IEDriverServer, Selenium WebDriver and IE which is in working condition.
As this SO answer points out, IE does not have native XPath support. Instead, Selenium WebDriver uses an old third party xpath library when IE is being used. Firefox has integrated support for XPath, which is why your selectors work fine in that browser.
I would highly recommend you update your selectors to instead use CSS selectors. They are supported across all browser, are easier to read, understand, and pick up, and they are pretty fast.
You can learn more about how to use CSS selectors from some different tuturials here, here, and here, and a CSS selectors cheatsheet.
Also, whenever possible, please try to not select an element by the text it contains. If you can select an element by its ID, class, other attribute, or even through the DOM chain (i.e. "div.1 > div.2 > span.a > a.b"), is better than trying to select an element by text.
Webdriver has difficulty with IE using locators. It seems like Murnal has difficulty using CSS locator. My advice would be you HAVE to use other locators if one doesnt work. This issue comes again and again while using non firefox browser. In the meantime an easier way to come up with alternate locator is use Firefox selenium IDE, there in the boxes where you type command you will see it gives alternate locator as well. Copy that and try plugging tha in your webdriver's findelement script.
Hi all i have found out that it was the issue of Selenium Webdriver 2.32 with IEDriver_Server2_32. After trying out permutation & Combination with latest available webdriver versions and IEDriver_Server, i have found out suitable stable configuration to work on IE9 below is the stable configuration : Webdriver : 2.33.0 IEDriver_Server : 2.33.0. There is still small issue but i am trying to look for workaround. Issue : In IE if some control's tooltip overlaps other control than IE is not able to find out that control. i guess this issue is with IEs working. IE uses nativeEvents to perform operation hence it is not able to locate that control. In FF it is able to find out that control and it is working fine. Thanks everyone.