Saturday, 27 June 2015

How to write xpath for SVG elements ?

Hi All

I have been working with charts, wherein I have to hover on the chart and get text from the tooltip.

In this scenario I came across SVG elements.The whole chart was present under the tag <svg> .

SVG is short for Scalable Vector Graphics. It is a graphic format in which the shapes are specified in XML. The XML is then rendered by an SVG viewer.

You can read more about SVG elements here.



 


 Sample HTML code


<svg width="400" height="110">

<g id="yui_3_6_0_1_1435305312018_1191" class="highcharts-series highcharts-tracker" visibility="visible" zIndex="0.1" transform="translate(64,37) scale(1 1)" style="cursor:pointer;" clip-path="url(#highcharts-13)">

<rect id="yui_3_6_0_1_1435305312018_1190" x="35.5" y="60.5" width="68" height="117" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">

<rect x="176.5" y="65.5" width="68" height="48" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">

<rect x="316.5" y="30.5" width="68" height="70" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">

</g>

</svg>
 
Scenario : Consider that we need to find the 2nd node of rect , present under the g tag, which is again present under the svg tag.

Our xpath would generally be something like, //svg/g/rect[2]-  but if we do that the element will not be found..


Xpath for svg elements should be like,

//*[name()='svg']/*[name()='g']/*[name()='rect' and @fill='#919EF9'][2]


That's it for now ..


Pay it forward..

DR











Monday, 18 May 2015

Real-time WebDriver/Java Interview Questions - Part 2

1.Tell me about yourself in terms of what you did in your career.
2.Explain the architecture of your project.
3.Explain your role in your project.
4..How did you handle exceptions in your project?
5.Is it possible to use multiple catch with one try block?
6.How do you handle dynamically changing objects?
7.What is WebDriver?
8.Scenario: There is an interface A and there are two classes Band C implementing it.Suppose we add a new method in interface A  what will happen to classes B and C?
9.Have you used any integration tool in your project ?
10.What are the different locator techniques?
11.How will you use CSS selector to identify elements?



Pay it forward..
DR

Tuesday, 7 April 2015

Real-time WebDriver/Java Interview Questions - Part 1

1.     What version of selenium did you use ?
2.     What is the current version of selenium
3.     Explain your project.
4.     Which module did you write in your project?
5.     Have you written any reusable methods in your project? What are they ?
6.     Write code for POI.
7.     Explain your framework.
8.     What are the TestNG annotations?
9.     What are the object identifiers in webdriver ? (Element Locators)
10.  When do we need automation?
11.  What is regression testing
12.  Have you done mobile testing? Tell  me something about mobile testing.
13.  Is it possible to use WebDriver  to automate a desktop application ?
14.  What is method overloading?
15.  What is method overriding?
16.  What is encapsulation?
17.  What are exceptions and what are its types?





Tuesday, 3 March 2015

File Upload - using AutoIT


In one of my previous posts , we had seen about file upload using Robot class. This post is about  uploading a file using the third party tool AutoIT.



Step1:

Launch http://www.toolsqa.com/automation-practice-form/

Step 2:

Under the section titled Profile Picture, click on the button named Choose File

Step3:

In the windows pop up for file upload, enter the path, where the file to be uploaded is present and hit enter.

Step1 and Step2 will be performed by the Webdriver script.


Step3 will be performed by the AutoIT script.



WebDriver script for this scenario:


public class ToolsQADemo {


public static void main(String[] args) throws InterruptedException,

IOException {

WebDriver driver = new FirefoxDriver();


driver.navigate()

.to("http://www.toolsqa.com/automation-practice-form/");

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);


driver.manage().window().maximize();


//We have to mention the path for the AutoIT script
Runtime.getRuntime().exec("D:/Selenium/AutoIt/Script/Script1.exe");

//Clicking on the element where the file is to be uploaded

driver.findElement(By.id("photo")).click();

}

}

AutoIT script for this scenario:


WinWaitActive("File Upload") 

Send("D:\Pictures\abc.jpg")
Send("{ENTER}")


Note:


We need to write the above mentioned script using the AutoIT tool and save it with .au3 extension.Then we need to compile it, which will be saved as a .exe file.  In the webdriver script, we have to mention the path of this .exe file.

In the AutoIT script we have to mention the path of the file to be uploaded.



In the first line of the script which is ,WinWaitActive("File Upload") ,


 "File Upload" is the name of the pop up that comes up. Make sure you give the same name as the windows pop up.




Pay It Forward...

 DR









Friday, 20 February 2015

Localization testing

If the website  that we test, deals with many languages say English,Magyar,French,Spanish, then we need to write our tests such that, it would work when the site is loaded in any of the languages.

Step 1:

To localize the tests , we first need to create properties files for each of the languages. 
  • Such files have key and value pairs. 
  • It should be a .txt file , saved with Encoding as UTF-8 format. 
  • It can be saved under the project which we are working on.


In the sample below I have assumed that we are going to load the website in Magyar language and the property file for Magyar is present in the path,

D:\\Automation\\Framework\\Properties.

The content of the file will be something like,

SIGN_OUT=Kilépés

MY_HOME_PAGE=Kezdőlapom

SETTINGS=Beállítások


Here "SIGN_OUT", "SETTINGS" are the Keys which have the corresponding Values "Kilépés","Beállítások".

We can copy and paste the values (the ones onto the right) from the website that is to be automated into the notepad.

Likewise we need to create Key - Value pair for all the required words which will be used in our test.

In our case we can save as hu.txt (encoding - UTF8)


Step 2:

Next step is to convert this into ASCII format.

To do this enter the command mentioned below in command prompt .

Syntax:

native2ascii -encoding utf8 source.txt destination.txt

Ex:

native2ascii -encoding utf8 hu.txt hu_ascii.txt


Note:


Open the directory where your source text file is, before entering the command .

The destination file, hu_ascii will be created under "D:\\Automation\\Framework\\Properties".
The values in it will be like ,

After conversion : 

SIGN_OUT=Kil\u00e9p\u00e9s

SETTINGS=Be\u00e1ll\u00edt\u00e1sok

Now we can use this encoded text in our webdriver tests.

Step 3:

For loading the respective property file, I use a method such as this


public Properties loadProp(String lang) throws FileNotFoundException,
IOException {

Properties prop = new Properties();

prop.load(new FileInputStream(
"D:\\Automation\\Framework\\Properties\\"
+lang+"_ascii.txt"));

        System.out.println(prop.get("SETTINGS"));

        return prop;

}


Step 4:

Now that the language's corresponding prop file is loaded, it can be used in any of the methods like ,

public static WebElement sel_Link(Properties prop,String menuitem){

we = driver.findElement(By.xpath("//li/a[text()='" + prop.getProperty(menuitem) + "']"));

return we;


}

That's all for now.

Hope this helps ..



Pay It Forward...

Lots of energy ..


DR