Tuesday, March 14, 2017

How to select values in dropdown using select in Selenium


  •  How to define an element of type dropdown or tag as select: We can define a element of type dropdown using the statement as shown below:             



Select selectElement = new Select(driver.findElement(By.id("SelectApp")));

  • Example of Select tag in html page: Below example shows how the values are defined in a select dropdown.


<select id="SelectApp">
<option value="Facebook">FB</option>
<option value="TasteBook">TB</option>
<option value="ClassBook">CB</option>
<option value="HomeBook">HB</option>
<option value="TestBook">TTB</option>
</select>


  • SelectByValue would select the option from the dropdown for option: <option value="Facebook">FB</option> if provided. selectByValue: Selects value based on argument value for the tag.

 selectElement.selectByValue("Facebook");  

  • selectByVisibleText: Select value based on the text of the tag


selectElement.selectByVisibleText("FB");        

  • selectByIndex: select the fifth dropdown using selectByIndex



 selectByIndex.selectByIndex(4);              

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.