Showing posts with label selenium. Show all posts
Showing posts with label selenium. Show all posts

Saturday, July 22, 2017

Switch between Windows using switch to in Selenium


String MainWinHandle = driver.getWindowHandle();
for(String NewWinHandle : driver.getWindowHandles()){
// Ignore the parent window open and work with the new window frame
 if(!NewWinHandle.equals(MainWindowHandle))
  {
    driver.switchTo().window(NewWinHandle);
 //Perform the required tasks to be performed in the new window opened
 driver.close();
 }
}
//Perform action on the main window once the task is completed with the old window.
driver.switchTo().window(MainWinHandle);

Saturday, June 17, 2017

How to execute only failed TestNG tests in Eclipse

While running testNG suite, once we are done with one round of execution of tests in the test suite, It can be helpful to execute only the failed tests during the first round of execution to reduce test failures due to flakiness/synchronization issues.

Below steps shows how to achieve this in eclipse.

  • Run the required test suite through eclipse as shown below.
testng eclipse run
  • Once the execution is completed and there are failures in the execution, we may require to rerun the tests.
  • Refresh the project. folder test-output should be displayed in the project explorer.
  • File testng-failed.xml should be available in the folder.
  • Run the test suite in similar manner as shown above, i.e Run As TestNG suite.

Monday, May 15, 2017

Jenkins - Adding a conditional build step.

In Jenkins, at times we may require Jenkins to execute some build step on one condition and another in case of other condition. For e.g: It may be required to run a particular test/batch command on Weekdays and some other batch condition on weekends. We can create a job to perform different tasks based on the condition satisfied. 

To add a conditional build step, follow below steps in Jenkins.

  • Navigate to Jenkins>Manage Jenkins>Manage Plugins and go to available tab.
  • Search for Conditional buildstep as shown below and click on install without restart.
  • It will install the plugin and will show success once installation completes.
  • Now the plugin can be used in the Jenkins job as shown below.In the job, add build step as Conditional step (single)

  • Provide the conditional step from the list as shown below and execute the build command.







Saturday, May 6, 2017

Reload configuration from disk - Jenkins

In case of migration of existing jobs from one Jenkins setup to another setup or removing old build information from the disk, we can use the option to reload configuration from disk in Jenkins. Below are the steps to be be followed to reload configuration from disk:


  • When we set up jenkins in a machine, there is a folder with name .jenkins in location c:/users/<UserName> folder.

  • When we open the .jenkins>jobs folder, we see the folders for the jenkins jobs we have created in jenkins. 

  • We can copy folders from another jenkins instance and paste in this folder. Similarly we can make changes in the logs information or builds information.

  • Once we have made the required changes in the jenkins set up. Open Jenkins using localhost:8080 (assuming you are on the jenkins server itself and 8080 is the port used for jenkins and is installed as a window service on the server. Else if accessing from a remote client machine, use the address <machine name>:<port number>

  • The jenkins home Page will open as shown below.
  • Click on Manage Jenkins and in the Manage Jenkins Page, click on Reload configuration from disk as shown below. This will reload the changes made in jenkins set up.

Saturday, April 22, 2017

Switching between multiple frames in selenium


There can be multiple iframes in a webPage. To perform action on webelements in a frame, we need to first identify the frame and then perform action on the element.
We can switch to a particular frame based on the below identifiers:


By Index: The index depends on the order of frame in the Page. A numeric value is assigned to the frame based on the order in which it appears in the page.

driver.SwitchTo().Frame(0);

By Name: We can switch to a frame based on the name of the frame.

driver.SwitchTo().Frame("FrameName");

By Id: We can switch to a frame based on the id defined for the frame

driver.SwitchTo().Frame("FrameId");

Switch to a frame by locator for WebElement. In the below example frameElement is the locator for the frame

driver.switchTo().frame(frameElement);

e.g: 

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector(cssfortheelement)));


Frame inside frames: There can be scenario in which there are frame inside of the parent frame.Please note in case of frame inside frame, we need to first switch to the outer frame, and then switch to the inner frame to perform action on the webelement.


To acess the main webPage and come out of the frame, below code is used

driver.SwitchTo().DefaultContent()

Sunday, February 26, 2017

Importing jobs from one jenkins installation to another

Using Job import plugin, we can import Jenkins job from another machine to our machines. This is useful in migrating jobs from one setup to another or a new Jenkins setup. 

Below are the steps to copy jobs from one Jenkins set up to another.

  • We require Job Import plugin to be installed to import job from one machine to another. In case plugin is not installed, Go to Manage Jenkins > Manage Plugins. 
  • Click on Available tab and search for Job import plugin.

  • Select the checkbox and click on Install without restart.
  • Once Jenkins is installed, Job Import plugin will be displayed in the menu.
  • Next to import the jobs from another Jenkins URL, click on Job Import plugin
  • Provide the Remote Jenkins URL and credential to connect to Jenkins and click on Query!
  • Once we click on Query!, Jenkins job will be displayed from the remote Jenkins.
  • Select jobs to be imported and click on import.
  • Jobs will be imported once user clicks on Import.

Saturday, February 25, 2017

How to run Jenkins on port other than 8080

By default Jenkins start at port 8080, but at times port 8080 is already used by some other application. We can run Jenkins on port other than 8080 by following below steps:
  • In case jenkins is running through command prompt, we can start jenkins to run at port 9090 or any other port using below command:
java -jar jenkins.war --httpPort=9090
  • To change the port permanently, follow below steps:
    • Go to jenkins home folder. The jenkins home folder is usually at C:\Program Files (x86)\Jenkins in case jenkins is installed from microsoft installer (MSI) file or it can be c:\Users\<UserName>\.jenkins folder.
    • Open the jenkins.xml file.
    • Change the port number in the file to the required port number.
    • Save the file.
    • Restart the window service for jenkins.

Tuesday, December 6, 2016

Tutorials to understand TestNG for Selenium Webdriver

Installing TestNG in eclipse - This post explains how to install TestNG in eclipse.


MindMap for TestNG - Understanding the concept in TestNG using MindMap.


Annotations in TestNG - Different annotations used in TestNG 


Assertion and Soft Assertions in Selenium Webdriver using TestNG - What are different assertions and soft assertions in selenium webdriver. What is the difference between assertions and soft assertion. How to use assertion in the test.


Maven POM.xml: Dependencies for Selenium, TestNG and junit - How to add TestNG dependenies in maven project.


Using dependencies and priority in TestNG tests: Ordering tests execution - how to define dependencies between tests and priotising order of tests execution in TestNG.


Creating TestNG.xml to run Selenium test suites - How to create testNG xml file for executing testsuite in TestNG. This article explains, how to create xml file for execution in  different scenarios.


How to run multiple test suites in TestNG? - Suppose we have individual suite for different module. This article explains how to create testNG xml file to run multiple test suites.


Maven POM.xml: Dependencies for Selenium, TestNG and junit - How to add dependencies for TestNG in Maven POM.xml

Tuesday, November 22, 2016

Tutorials for Selenium IDE easy understanding


Selenium IDE :: Add-ons for Firefox - Download Selenium IDE from the link for
firefox. Remember Selenium IDE is add-on for firefox browser only.

Download Selenium IDE - Official site for Selenium. Can learn about selenium
IDE and release notes from this page.

Introduction to Selenium IDE - Guru99 - Excellent link to start understanding about Selenium IDE

Introduction to Selenium IDE (Installation and its Features) - Another interesting blog to understand the concept of Selenium IDE.

Useful tutorial Posts for Selenium IDE in this blog:


Mindmap for understanding Selenium IDE - Mindmap to understand what selenium IDE is all about. 

Installing Selenium IDE add-on in firefox - How to install Selenium IDE add-on in firefox.

Understanding and locating Locators in Selenium IDE - What are locators in Selenium IDE and how are locators used to identify an element in Selenium IDE

Log file for Selenium IDE execution using FileLogging addon for firefox - Log file are useful to identify failures in execution and validating the performance of application response.This article explains how to create log file for execution in Selenium IDE

Selenium Commands in Selenium IDE - This article explains what are the selenese commands most commonly used in Selenium IDE

Exporting selenium IDE tests to WebDriver - Test recorded using Selenium IDE can be imported into different languages support. This article explains how to export selenium IDE tests to Selenium WebDriver.

Selenium IDE Panes and Shortcut keys - This article explains the Interface of Selenium IDE with details of different panes and shortkeys for operations in Selenium IDE.

How to run test with random data in Selenium IDE: store and storeText Command - This article explains how to store information in application or using javascript, generating random data and storing in a variable.



Validating conditions using assert and verify in Selenium IDE -This post explains how to add assertions in Selenium IDE and what is the difference between assert and verify statement.

Friends, there may be many interesting blogs/post for Selenium IDE, which you have come across. Please feel free to ion share such links as can be useful for other readers.

Sunday, November 20, 2016

Installing Selenium IDE add-on in firefox

Selenium IDE is a record and play automation IDE/add-on with Firefox. It is very simple to install selenium IDE and creating automated script in selenium which can then be imported in different languages and formats. In this article, we will explain how to install Selenium IDE in firefox.
  • Pre-condition: Firefox browser is installed. 
  • Installation steps:
    • Search Selenium IDE and click on the link as shown below:
Selenium IDE link
    • Click on the link.In the add-ons Page, click on Add to Firefox
Selenium IDE add-on
developer selenium IDE
    • Once the add-on is installed, Selenium IDE can be accessed by navigating to developer>Selenium IDE or pressing Alt + Ctrl + S
    • This will open Selenium IDE on which we can record and play on the applications.

Thursday, November 17, 2016

Log file for Selenium IDE execution using FileLogging addon for firefox

We can create log files of selenium IDE test execution and store in an file using the below process:

1. Download the File Logging add-on to Firefox as shown below.








2. Firefox will restart once the add-on is installed.

3. Now Open Selenium IDE in Firefox.

4. Go to Options>Options. 

5. Selenium IDE options window will open.

6. Go to FileLogging tab.

7. Provide location of file where logs needs to be created.

8. Define the logging level.

9. Select the required checkbox for logging information.

Give it a try, it is quite useful.