Anda di halaman 1dari 4

Step 3: Compile the .au3 script and convert it in to .

exe file
Now save the above script, if in case you have not saved the name earlier, pleas
e save it in .au3 format. The next step is to convert it in to .exe format. For
that you need to right click on the .au3 file and select Compile Script .
Step 4: Call the .exe file in to the Selenium test case
Once you done with the compiling, it will create the .exe
file with the same name unde
r the same folder and that .exe
file will be called in the Selenium Test Script by usi
ng the following script:
Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");
Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");
Need of third party tools in Selenium
Web applications do not always confine themselves to working entirely on the web
. Sometimes they need to interact with the desktop to do things like downloads &
uploads. Automating these sorts of workflow is tricky in Selenium. Selenium is
confined to automating browsers, so desktop windows are out of scope. If you are
looking to automate workflows that go from browser to desktop and back in Selen
ium, then a little AutoIt is in order.
What is AutoIt
AutoIt v3 is a freeware BASIC-like scripting language designed for automating th
e Windows GUI and general scripting. It uses a combination of simulated keystrok
es, mouse movement and window/control manipulation in order to automate tasks in
a way not possible or reliable with other languages (e.g. VBScript and SendKeys
). AutoIt is also very small, self-contained and will run on all versions of Win
required!
dows out-of-the-box with no annoying runtimes
In layman s term AutoIt is just another automation tool like Selenium but unlike Sel
enium it is used for Desktop Automation rather Web Automation. It is a powerful
tool and it just not automate desktop windows, button & form, it automates mous
e movements & keystrokes too. Just like Selenium IDE, it also gives you the reco
rding capability which generates the scripts for you to use the same script in y
ou test.

Could any one guide how to integrate an Auto IT script with in selenium web driv
er?
I am using a applet window embedded with in browser.
So, using Auto IT for keystroke & Mouse action.
I don't want to run the Auto It script as an .exe file in selenium.
I just want to covert the script in to selenium and run for future enhancement.
Answer:
1 down vote accepted
The solution: AutoITx.jar. import the jar in selenium and directly use the autoi
t script in selenium webdriver

ScreenShot:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in d drive with name "sc
reenshot.png"
FileUtils.copyFile(scrFile, new File("D:\\screenshot.png"));

WebDriver driver = new FirefoxDriver();


driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

ImplicitlyWait Command
Purpose: This means that we can tell Selenium that we would like it to wait for
a certain amount of time before throwing an exception that it cannot find the e
lement on the page. We should note that implicit waits will be in place for the
entire time the browser is open. This means that any search for elements on the
page could take the time the implicit wait is set for.
FluentWait Command
Implicit waits are basically your way of telling WebDriver the latency that you
want to see if specified web element is not present that WebDriver looking for.
So in this case, you are telling WebDriver that it should wait 10 seconds in cas
es of specified element not available on the UI (DOM).
Implicit wait time is applied to all elements in your script
Purpose: Each FluentWait instance defines the maximum amount of time to wait for
a condition, as well as the frequency with which to check the condition. Furthe
rmore, the user may configure the wait to ignore specific types of exceptions wh
ilst waiting, such as NoSuchElementExceptions when searching for an element on t
he page.
Explicit waits are intelligent waits that are confined to a particular web eleme
nt. Using explicit waits you are basically telling WebDriver at the max it is t
o wait for X units of time before it gives up.
Explicit wait time is applied only for particular specified element.
In Explicit you can configure, how frequently (instead of 2 seconds) you wa
nt to check condition
Explicit wait
public static WebElement explicitWait(WebDriver driver,By by)
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(by));

Synchronization in Selenium Webdriver


It is a mechanism which involves more than one components to work parallel with
Each other.

Generally in Test Automation, we have two components


1. Application Under Test
2. Test Automation Tool.
Both these components will have their own speed. We should write our scripts in
such a way that both the components should move with same and desired speed, so
that we will not encounter "Element Not Found" errors which will consume time ag
ain in debugging.
Synchronization can be classified into two categories:
1. Unconditional
2. Conditional Synchronization
Unconditional :
In this we just specify timeout value only. We will make the tool to wait until
certain amount of time and then proceed further.
Examples: Wait() and Thread.Sleep();
The main disadvantage for the above statements are, there is a chance of unneces
sary waiting time even though the application is ready.
The advantages are like in a situation where we interact for third party systems
like interfaces, it is not possible to write a condition or check for a conditi
on. Here in this situations, we have to make the application to wait for certain
amount of time by specifying the timeout value.
Conditional Synchronization:
We specify a condition along with timeout value, so that tool waits to check for
the condition and then come out if nothing happens.
It is very important to set the timeout value in conditional synchronization, be
cause the tool should proceed further instead of making the tool to wait for a p
articular condition to satisfy.
In Selenium we have implicit Wait and Explicit Wait conditional statements. Chec
k here for Examples on how to use Webdriver Waits
1. Implicit Wait.
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of ti
me when trying to find an element or elements if they are not immediately availa
ble.
The default setting is 0. Once when we define the implicit wait, it will set for
the life of the WebDriver object instance.
It is a mechanism which will be written once and applied for entire session auto
matically. It should be applied immediately once we initiate the Webdriver.
Implicit wait will not work all the commands/statements in the application. It w
ill work only for "FindElement" and "FindElements" statements.
If we set implicit wait, find element will not throw an exception if the element
is not found in first instance, instead it will poll for the element until the
timeout and then proceeds further. We should always remember to add the below sy
ntax immediately below the Webdriver statement.

Syntax: driver.manage.TimeOuts.implicitwait(6,Timeunit.SECONDS);
Example:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("www.google.com");
Explicit Wait:
We need to define a wait statement for certain condition to be satisfied until t
he specified timeout period. If the Webdriver finds the element within the timeo
ut period the code will get executed.
Explicit wait is mostly used when we need to Wait for a specific content/attribu
te change after performing any action, like when application gives AJAX call to
system and get dynamic data and render on UI.
Example: Like there are drop-downs Country and State, based on the country value
selected, the values in the state drop-down will change, which will take few se
conds of time to get the data based on user selection.
Example:
/*Explicit wait for state dropdown field*/
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("statedropdow
n")));
Fluent Wait:
Using FluentWait we can define the maximum amount of time to wait for a conditio
n, as well as the frequency with which to check for the condition.
And also the user can configure to ignore specific types of exceptions such as "
NoSuchElementExceptions" when searching for an element.
Syntax:
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
//Wait for the condition
.withTimeout(30, TimeUnit.SECONDS)
// which to check for the condition wit
h interval of 5 seconds.
.pollingEvery(5, TimeUnit.SECONDS)
//Which will ignore the NoSuchElementExcept
ion
.ignoring(NoSuchElementException.class);
}