Q. What is Selenium?
A. Selenium is a suite of tools for browser automation (i.e. automated Web testing). It is composed of
Selenium IDE: A tool for recording and playing back. This is a Fire-fox plugin.
WebDriver and RC provide the APIs for a variety of languages like Java, .NET, PHP, etc. A Java example is shown below. The WebDriver and RC work with most browsers.
Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites.
Q. How would you go about using selenium for your web testing?
A. The example below shows the steps involved in testing a simple login page with selenium + Web Driver. The pages have HTML snippets as shown below
Login Page:
1
2
3
4
5
6
7
8
9
10
11
12
13
| ... <form method= "POST" action= "some/url" > <input type= "text" name= "username" /> <input type= "text" name= "password" /> </form> ... |
Login response page:
1
2
3
4
5
6
7
| ... <table> <tr> <td>John</td>< /tr> </table> ...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <properties> <junit.version>4.4</junit.version> <selenium.version>2.7.0</selenium.version> <slf4j.version>1.5.2</slf4j.version> </properties> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> </dependencies>
|
The selenium-java-x.x.x.jar will transitively bring in the other relevant driver jars for different browsers.
STEP 2: It is a best practice to have separate page objects as these page objects can be shared by multiple JUnit test cases. If a particular page element changes, you will have to change it only in one place, which is page object, and not in all JUnit test cases where a paricular element is used. The JUnit test cases will depend on the page objects and should not refer to the page elements directly.
1
2
3
4
5
6
7
8
9
10
11
12
| package fsg.wrap.systemtest; import org.openqa.selenium.WebDriver; public class SystemTestPage { protected WebDriver driver; protected SystemTestPage(WebDriver driver) { this .driver = driver; } }
|
You can have your page objects extend the above generic SystemTestPage class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| package com.systemtest.page; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import fsg.wrap.systemtest.SystemTestPage; public class LoginPage extends SystemTestPage { @FindBy(name = "username" ) @CacheLookup private WebElement userNameInput; @FindBy(name = "password" ) @CacheLookup private WebElement passwordInput; @FindBy(xpath = "//input[@type=\"submit\"]" ) @CacheLookup private WebElement submitButton; public LoginPage(WebDriver driver){ super(driver); } public void login(String userName, String password) { userNameInput.sendKeys(userName); userNameInput.sendKeys(password); submitButton.submit(); } public String getUserName(String userName) { WebElement element = driver.findElement(By.xpath( "//td[text()=" + userName + "]" )); return element.getText(); } }
|
STEP 3: Write the JUnit class using the page objects defined above and assert the results. These JUnit test cases can be run to test your web pages.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| package com.unittests; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.WebDriverWait; import com.systemtest.page.LoginPage; public class LoginTest { private static final String USER_NAME = "John" ; private static final String PASSWORD = "aa44" private WebDriver driver; private WebDriverWait wait; private LoginPage loginPage; // the page object @Before public void setUp() { driver = new FirefoxDriver(); wait = new WebDriverWait(driver, 5); driver. get (BASE_URL); loginPage = PageFactory.initElements(driver, LoginPage. class ); } @Test public void testLogin() throws Exception { loginPage.login(USER_NAME, PASSWORD); Assert.assertEquals(MAC, loginPage.getUserName(USER_NAME)); } @After public void tearDown() { driver.quit(); } } |
Q. What are selenium locators? What tools do you use to locate them?
A. Selenium Locators are the way of finding the HTML element on the page to perform a Selenium action on. The example above has a line asshown below to extract the username element from the Login response page. This uses an XPath expression to locate the element.
1
2
3
4
| public String getUserName(String userName) { WebElement element = driver.findElement(By.xpath( "//td[text()=" + userName + "]" )); return element.getText(); } |
The XPath expression will be something like //td[[text()=John] which looks for a td element with text value "John".
The annotation in the above example is also a locator by name as shown below
1
2
3
| @FindBy(name = "username" ) @CacheLookup private WebElement userNameInput; |
This will match the HTML snippet
1
| <input type= "text" name= "username" > |
You could also find by tagName, id, css, etc.
There are handy tools to identify the HTML elements or locators.
Selenium IDE, which is a Firefox plugin useful in identifying the locators, debugging, etc.
The Fire-bug plugin, which allows you to inspect the elements by right clicking on the page and then selecting "Inspect Element". Google chrome provides a similar functionality to inspect element out of the box.
Q. In your experience, what are some of the challenges with Selenium?
A. In general, badly written test cases whether junit tests or web tests, the biggest complaint is about writing test cases that are not maintainable. Unmaintainable automated test cases can take more time than manual tests. So, it is important to write quality test cases by clearly separting the page objects from the test cases as demonstrated in the Q&A above. The use of the locators need to be carefully thought through. For example, some frameworks like JSF dynamically generate HTML element IDs. So, if IDs are used in your tests, then the test cases may fail if the IDs have changed. The solution to this problem is to use XPath to find the relevant HTML elements. The ClickAndWait action will not work for AJAX calls, and use "waitForElement" instead.
Tks very much for post:
ReplyDeleteI like it and hope that you continue posting.
Let me show other source that may be good for community.
Source: Hr sample interview questions
Best rgs
David
I'm so glad to see code!
ReplyDeleteYou're a great teacher :)
Thanks for sharing interview questions on selenium automation software testing tool. Your post will be lot useful for students and software testing professionals.
ReplyDeleteThanks for your informative article on software testing. LoadRunner is popular automation software testing tool that used to validate a software application by generating actual load. Further, it gives precise information about a software application or environment.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteVery nicely compiled and presented...just adding on to that some more selenium interview questions -
ReplyDeleteArt of Testing | Selenium Interview Questions
lot of things learnt from your blog. got more ideas for us. wonderful tips makes from yours. Executing and testing our status very helpful one.
ReplyDeleteSAT Training Centre in Chennai
Very great blog,you given wonderful information,thank you for sharing this article,keep posting.
ReplyDeleteSoftware Testing Company in Hyderabad
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeleteHome Interiors in Chennai
I have really enjoyed reading your blog. Very interesting and special informative post. Keep on updates.
ReplyDeleteBigdata Training in Chennai
I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time? Thanks for the post..
ReplyDeleteLogistic ERP
Transport ERP
Manufacturing ERP
ERP software companies
Best ERP software
ERP for the manufacturing industry
Thanks for sharing, Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this.
ReplyDeleteBest Training Institute in chennai
ReplyDeleteThanks for sharing such a nice and interesting blog with us...
SAP ABAP Training in chennai
Fertility is the natural capability to produce offspring. As a measure, fertility rate is the number of offspring born per mating pair, individual or population.Human fertility depends on factors of nutrition, sexual behavior, consanguinity, culture, instinct, endocrinology, timing, economics, way of life, and emotions.Greate thinks of a fertility center for humans.
ReplyDeleteFertility Center in OMR
Nice...Excellent article and useful to others
ReplyDeleteVMware Training Class in chennai
Thanks for your great and helpful presentation I like your good service.I always appreciate your post.That is very interesting I love reading and I am always searching for informative information like this.Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chenai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery | project management courses in chennai
ReplyDeleteThank you for this brief explanation and very nice information. Well, got a good knowledge. Sometimes you just have to yell at people and give them a good shake to get your point across.
ReplyDeleteHRMS Software In India
Human Resource Management Software
HRMS Software Chennai
HR Software In Chennai
HR Management Software In India
HRMS Chennai
ReplyDeletehttps://tinyurl.com/yxns6qsm
https://tinyurl.com/y4ogqv9n
https://tinyurl.com/y6awyqpy
https://tinyurl.com/y4ms8sfs
https://tinyurl.com/y3mbajme
https://tinyurl.com/yxgmmlz2
https://tinyurl.com/yxlgrnth
https://tinyurl.com/y5flxtfg
https://tinyurl.com/yxre83a7
https://tinyurl.com/yxarykte
I think that thanks for the valuabe information and insights you have so provided here. useless website generator
ReplyDeleteThis really is my first time i visit here. I discovered so many entertaining stuff in your blog, especially its discussion. From a great deal of comments in your articles, I guess I am not alone having all of the leisure here! Maintain the superb work. It is very useful who is looking for top software testing companies
ReplyDeleteThis is really a worthy and wonderful blog about Software Testing Services in Chennai to read and further more tips on the Software Testing Services in India have been learnt. thanks for sharing your views among us and its great time spending on this. I am waiting for new post here about Software Testing Companies in Bangalore and Please keep it up in future..
ReplyDeleteConsult today to - Software Testing Services in Mumbai
You made some decent factors there about Mobile App Testing Services. I looked on the internet for the difficulty and found most individuals will associate with along with your website. Keep update more excellent posts on Mobile Testing Services
ReplyDeletekralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
41MZ
slot siteleri
ReplyDeletekralbet
betpark
tipobet
mobil ödeme bahis
betmatik
kibris bahis siteleri
poker siteleri
bonus veren siteler
XX4H
Antalya
ReplyDeleteKonya
Adana
Ankara
Van
VPXF3A
F2572
ReplyDeleteTunceli Şehir İçi Nakliyat
Afyon Lojistik
Yozgat Parça Eşya Taşıma
Eryaman Parke Ustası
Bingöl Parça Eşya Taşıma
Çerkezköy Kurtarıcı
Pursaklar Parke Ustası
Zonguldak Parça Eşya Taşıma
Edirne Şehir İçi Nakliyat
F58B2
ReplyDeleteen iyi ücretsiz sohbet siteleri
kadınlarla sohbet et
burdur görüntülü sohbet canlı
bayburt parasız sohbet
bartın bedava görüntülü sohbet sitesi
gümüşhane görüntülü sohbet kadınlarla
rastgele sohbet
ankara parasız sohbet siteleri
elazığ en iyi rastgele görüntülü sohbet
2A61B
ReplyDeletemaraş canlı sohbet siteleri
izmir muhabbet sohbet
karabük rastgele görüntülü sohbet ücretsiz
afyon sesli sohbet
trabzon sohbet uygulamaları
bedava görüntülü sohbet
adana parasız görüntülü sohbet
muş sohbet
bitlis rastgele sohbet uygulaması
88397
ReplyDeleteankara parasız sohbet siteleri
aydın sesli sohbet odası
canlı sohbet odası
Denizli Yabancı Görüntülü Sohbet Siteleri
trabzon bedava görüntülü sohbet sitesi
zonguldak sesli mobil sohbet
tunceli rastgele sohbet
canlı ücretsiz sohbet
telefonda görüntülü sohbet
D130C
ReplyDeleteBitcoin Kazma Siteleri
Raca Coin Hangi Borsada
Btcturk Borsası Güvenilir mi
Bitcoin Nedir
Twitter Beğeni Satın Al
Bitcoin Kazanma
Twitter Takipçi Hilesi
Facebook Sayfa Beğeni Hilesi
Görüntülü Sohbet Parasız
BF3BD3D872
ReplyDeletegörüntülü show
şov
steroid satın al
cialis
steroid satın al
www.ijuntaxmedikal.store