Friday, 15 April 2016
Logical Qn : Assume that you have 25 horses, and you want to pick the fastest 3 horses out of those 25. In each race, only 5 horses can run at the same time because there are only 5 tracks. What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?
After analyzing a bit, Here are the pointers.
- We need to put all the horses into a race ( 5 at a time ) to find out the best 3 performers.
- Maximum 5 Horses in a race, so 5 times we need to conduct.
- After 5 Races, below is the table we can draw "ORDER by best performer"
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Race1H2 - Race2H7 - Race3H12 - Race4H17 - Race5H22
Race1H3 - Race2H8 - Race3H13 - Race4H18 - Race5H23
Race1H4 - Race2H9 - Race3H14 - Race4H19 - Race5H24
Race1H5 - Race2H10 -Race3H15 - Race4H20 - Race5H25
Our Aim is to find the best three performers. so, we can eliminate last two rows.
Reason: We are least bothered about 4th and 5th best in each race.
They can not be one among top three performers.
Our Target table is
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Race1H2 - Race2H7 - Race3H12 - Race4H17 - Race5H22
Race1H3 - Race2H8 - Race3H13 - Race4H18 - Race5H23
Now Race # 6: all top players in each race:
i.e
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Assume results are, 1st place Race1H1 ; 2nd place Race2H6 ; 3rd place Race3H11
Now Race # 7: will gives the 2nd and 3rd place horse.
i.e we need to conduct a race with below set.
- Race2H6 - Race3H11
Race1H2 - Race2H7
Race1H3
why we eliminated other horses?
Elimination Set # 1
Race4H16 - Race5H21
Race4H17 - Race5H22
Race4H18 - Race5H23
Reason: As 3rd best horse is Race3H11. so, above set is definitely is not in 1,2,3 positions.
Elimination Set # 2
Race3H12
Race3H13
Reason: same as above.
Elimination Set # 3
Race2H8
Reason: as Race1H1 is 1st , there may be chance for 2nd is Race1H2 or Race2H6
chance for 3rd is Race1H3, Race2H6, Race2H7, Race3H11
but not Race2H8
so, Answer is 7
-
Thursday, 4 December 2014
Integrating AutoIt with Selenium
What is AutoIt:
AutoIt is freeware scripting language for
automating the windows GUI.
Why is AutoIt:
When
you start working with web-application so many time you will get window based
pop-up like- file upload, download pop up, window authentication etc. In
this case Selenium fails and will not be able to handle desktop elements to
avoid this we will use AutiIt script that will handle desktop or windows
elements and will combine AutoIt script with our Selenium code.
Setup / Configuration:
Download
and Install AutoIt software and Editor here
Install
the software.
IMAGE 2:
Search
for “sciTE Script Editor” or “SciTE.exe” in RUN dialog.
Problem statement:
Automate
file upload feature in http://www.dropzonejs.com/
We know
how to write selenium code until we click upload button and here is the code.
public static void main(String[] args) throws InterruptedException, IOException {
String baseUrl = "http://www.dropzonejs.com/";
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
driver.get(baseUrl);
driver.manage().window().maximize();
Thread.sleep(6000);
driver.findElement(By.id("demo-upload")).click();
Thread.sleep(3000);
}
Now, we
need to select a file from windows explorer and Selenium cannot do it for
obvious reasons.
But, we
can achieve this using AutoIt.
Here is the AutoIt script:
; Wait 10 seconds for the
Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit
control of Upload window using the handle returned by WinWait
ControlFocus("File
Upload","","Edit1")
Sleep(2000)
; Set the File name text on the
Edit field
ControlSetText("File
Upload","","Edit1","C:\Users\testUser\Downloads\A.jpg")
Sleep(2000)
; Click on the Open button
ControlClick("File
Upload", "","Button1");
Explanation:
WinWait pauses execution of the script until the
requested window existed
Now, we
need to understand how to locate the file upload windows explorer.
Open
Au3Info.exe (Window Info tool), select Finder
tool and point to file upload windows explorer to locate it.
We have
two parts in ‘Window Info tool’, one is ‘Basic window Info’ and other is ‘Basic
Control Info’.
As we
are dealing with windows explorer wait, lets concentrate on ‘Basic window
info’, notice about CLASS id to locate the window as ([CLASS:#32770])
Similarly
we can locate each and every windows explorer element.
Few
Methods to remember:
ControlFocus Sets
input focus to a given control on a window.
ControlSetText Sets
text of a control.
ControlClick Sends
mouse click command to a given control.
SAVE the file:
Save
AutoIt script file as with ‘.au3’ extension. Ex: one.au3
Compiling au3 script file:
Right
click on one.au3 file and select compile script option.
A new
file named one.exe will be generated.
Integrating
AutoIt
public static void main(String[] args) throws InterruptedException, IOException {
String baseUrl = "http://www.dropzonejs.com/";
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
driver.get(baseUrl);
driver.manage().window().maximize();
Thread.sleep(6000);
driver.findElement(By.id("demo-upload")).click();
Thread.sleep(3000);
Runtime.getRuntime().exec("E:/one.exe");
}
Just run
the script, that’s all.
NOTE: We
do not need to add any jars to the project for this to run.
Tuesday, 25 November 2014
What is abstract ? in OOP Language
You declare a class to be abstract by saying something like:
abstract class Base
{
}
Why would you do this?
To stop it being instantiated.
You cannot then say
Base b = new Base();
But, you can instantiate concrete sub-classes of Base.
Why would you want to stop it being instantiated?
Usually because it is too general.For example, you might define a class Animal and concrete subclasses of Bird, Cat and Dog.
In the real world you can have Cats and Dogs but not Animals which are not some type of Animal.
Using abstract lets you model this situation.
Subscribe to:
Posts (Atom)