Showing posts with label Selenium/WebDriver. Show all posts
Showing posts with label Selenium/WebDriver. Show all posts

Sunday, December 20, 2015

Configure Jenkins email notifications

In this tutorial we will discuss about setting up the email notification in your Jenkins environment from the start :

Part I: Configure the email notifications from Jenkins Management section.

Part II : Configure the email notification for the individual Jenkins job  

Part I: Configure the email notifications from Jenkins Management section.

  1. First you should be logged in to Jenkins interface as Administrators, so you should see 'Manage Jenkins' link on the left side options.
  2. Click on the 'Manage Jenkins', to navigate to 'Manage Jenkins' page. 'Configure System' option should be available
  3. Click on the 'Configure System' link, scroll down on 'Configure System' page, you should see the 'Email notifications' section.
  4. Set the following settings in the 'Email notification' section [We are taking yahoo domain for example]
    • SMTP Server : smtp.mail.yahoo.com
    • Check 'Use SMTP Authentication'
    • Username : <email address to send emails> Example : test@yahoo.com
    • Password : <used email address password>
    • Check 'Use SSL'
    • SMTP Port : 465
    • Reply-To-Address :  <email address to reply emails, can be same email or different>
    • Charset : UTF-8
    • Scroll up on the page and now set following settings in 'Locations' section
      • System admin e-mail address :  <email address to send emails> Example : test@yahoo.com
    • Now to test your email configurations, Scroll down to 'Email Notification' section.
      • Check 'Test Configuration by sending test e-mail'
      • Test e-mail recipient : <recipient email address to test configuration> Example: youremail@yahoo.com
      • Click on "Test Configuration" button.
    • You should see message 'Email was successfully sent'. It yes, congrats you have successfully configured Jenkins email notifications :)
    • 'Apply' and 'Save' the changes.

    Part II : Configure the email notification for the individual Jenkins job  

    1. Navigate to configuration page of Jenkins job, for which you wants to send a email notification. For example we have a job 'test-email-notification'
    2. Under 'Post Build Actions', click on 'Add post build action' and select 'Email Notification' option.
    3. Now, when the 'Email notification' section visible. Provide the recipients email addresses and select other check box options per your requirement
    4. Click on Apply and Save the changes.
    Feel free to leave your comments in case of any issues in above steps... :)

    Saturday, January 3, 2015

    Running Selenium Webdriver tests on Internet Explorer browser

    So finally added support to execute tests on Internet Explorer browser also in my github project https://github.com/lalit-k/selenium-java-tests.

    3 Simple steps to add Internet Explorer support in Selenium Webdriver project:
    1. Download the IEDriverServer.exe , you can download the latest version from http://selenium-release.storage.googleapis.com/index.html for your target operating system.[download url may change, you can google latest if it changes]
    2. Extract the IEDriverServer.exe from the downloaded zip, and place in your project resources folder.
      IEDriverServer.exe
    3. Now, go to the Driver script where you are initializing the IEDriverServer and add the below code line to initialize the IEDriverServer.
    
    System.setProperty("webdriver.ie.driver", <full system path of the IEDriverServer.exe. Example: c:\tests\resources\IEDriverServer.exe>);
    WebDriver driver = new InternetExplorerDriver();
    

    Tip : you can use the "System.getProperty("user.dir");" to get the current working directory and then append the path to IEDriverServer.exe
    System.getProperty("user.dir")
    You can also view the complete code changes for your reference at https://github.com/lalit-k/selenium-java-tests/commit/d1dc4cd3f878d64a4119fc0d6297df026a07cf5a

    Running Selenium Webdriver tests on Google Chrome browser

    Few months back i had added the support to execute tests on Google Chrome browser in my github project https://github.com/lalit-k/selenium-java-tests , so i thought to write it down how you can do the same if needed in your project.

    3 Simple steps to add Google Chrome support in Selenium Webdriver project:
    1. Download the ChromeDriver.exe , you can download the latest version from http://chromedriver.storage.googleapis.com/index.html for your target operating system.[download url may change, you can google latest if it changes]
    2. Extract the chromedriver.exe from the downloaded zip, and place in your project resources folder.
      Add Chromedriver.exe
    3. Now, go to the Driver file where you are initializing the ChromeDriver and add the below code line to initialize the ChromeDriver.
    
    System.setProperty("webdriver.chrome.driver", <full system path of the chromedriver.exe. Example: c:\tests\resources\chromedriver.exe>);
    WebDriver driver = new ChromeDriver();
    

    Tip : you can use the "System.getProperty("user.dir");" to get the current working directory and then append the path to chromedriver.exe


    System.getProperty("user.dir")


    You can also view the complete code changes for your reference at https://github.com/lalit-k/selenium-java-tests/commit/01cda755f72918a417b7b0cded1b2db4c387eb70

    Monday, June 30, 2014

    How to Disable Selenium HtmlUnitDriver logging

    Recently, while working on a project using Selenium HtmlUnitDriver, i found that it generates too much log messages by default to output console which really fills the screen with non wanted messages.


    So, like me some of you may also get this and wanted to resolve the same. What i did is added the below code statements to suppress the logging messages.
    
    
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log","org.apache.commons.logging.impl.NoOpLog");
    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); 
    
    
    and it Worked :) :)

    Saturday, May 3, 2014

    Handle Sharepoint HTTP basic window authentication - using selenium webdriver java


    import org.openqa.selenium.Alert;
    import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent;
    // Switch to alert window. Alert authenticationWindow = driver.switchTo().alert();
    // Type the username/email. authenticationWindow.sendKeys("<username/email address>");
    // Shift cursor focus to password input text field. Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_TAB);
    // Type the password in password field. [ Selenium does not know at this point that the cursor focus is shifted, so calling Alert class instance sendKeys() will cause password to be typed in username field. So, we are copying the password first to windows clipboard and then pasting it directly into the password field using  Robot class instance ] StringSelection stringSelection = new StringSelection("<user password>"); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,null); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL);
    // Accept the authentication window. robot.keyPress(KeyEvent.VK_ENTER);

    Sunday, January 5, 2014

    Friday, October 26, 2012

    How to locate element in Html 'svg' tag in Selenium 2(Webdriver)


    Sample svg code enbeded into Html code
     <html>  
     <head>  
     <title>automatethebox.blogspot.com</title>  
     </head>  
     <body>  
     <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="939" height="360">  
     <defs>  
     <g zIndex="10">  
     <tspan x="5.5">You</tspan>  
     </g>  
     <g zIndex="20">  
     <tspan x="5.5">Me</tspan>  
     </g>  
     <g zIndex="30">  
     <tspan x="5.5">None</tspan>  
     </g>  
     </svg>  
     </body>  
     </html>  
    
    Selenium 2 (Webdriver) code to locate and intract with an svg element embeded into HTML 
    Suppose in above given svg code three buttons are embeded into the svg.
    Now we will be finding the button and be clicking on them using 'css locators'.Here we go....

    Method 1
     // First of all find the 'svg' tag in the page and save it into as WebElement instance.  
     WebElement svgElement = driver.findElement(By.cssSelector("svg"));  
       
     // Get the Buttons with which we want to interact in a list  
     List<WebElement> gElements = svgElement.findElements(By.cssSelector("g"));  
       
     // Click on 'Me' Button  
     WebElement button = gElements.get(0).findElement(By.cssSelector("tspan");  
     button.click();  
       
     // Click on 'You' Button  
     WebElement button = gElements.get(1).findElement(By.cssSelector("tspan");  
     button.click();  
       
     // Click on 'None' Button  
     WebElement button = gElements.get(2).findElement(By.cssSelector("tspan");  
     button.click();  
    
    Method 2
     // Locate buttons and save in the WebElement instances.  
     WebElement meButton = driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='Me']"));  
     WebElement youButton = driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='You']"));  
     WebElement noneButton = driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='None']"));  
       
     // Click on the buttons.  
     meButton.click();  
     youButton.click();  
     noneButton.click();  
    

    Wednesday, October 24, 2012

    How to switch between browser windows in Selenium 2 (WebDriver Java)

     // Store you current window handle in a String variable.  
     String parentWindow = driver.getWindowHandle();  
       
     // Click on the the page element which causes a new window to be opened,suppose a link.  
     driver.findElement(BY.linkText("myLink")).click();  
       
     // Get the window handle of the new browser window opened.  
     String childWindow = (String) driver.getWindowHandles().toArray()[1];  
       
     // Switch to newly opened window.  
     driver.switchTo().window(childWindow);  
       
     // Switch back to main window.  
     driver.switchTo().window(parentWindow);  
    


    © automatethebox. All Rights Reserved

    AWS Certified Solutions Architect Associate - AWS Introduction - Questions

    All the Best !!! Show Result !! Try Again !! ×