Selenium Two Tutorial using IronPython and InternetExplorerDriver - The Automated Tester

Selenium Two Tutorial using IronPython and InternetExplorerDriver - The Automated Tester

Selenium Two Tutorial using IronPython and InternetExplorerDriver

Mon 11 Jan 2010

This tutorial is to show how to use the .NET Selenium 2 with dynamic languages that run on the .NET Common Language Runtime. This tutorial uses IronPython.

To complete this tutorial you will need to have IronPython installed and you will also need to download the .NET Bindings from Google Code

This tutorial will not be using the Remote Driver and it will be using the InternetExplorerDriver as this is the only complete browser at the moment that doesn't need to be built from the Repository.

 

  1. Lets start by creating a directory that will hold the IronPython script. Lets call it SeleniumTwoExamplePython
  2. Copy the WebDriver.Common.dll, WebDriver.IE.dll and InternetExplorerDriver.dll files into the newly created directory in the step above. Make sure the version of InternetExplorerDriver.dll matches the architecture of your operating system.
  3. We are now ready to have our write our first test!Copy the code below into a Python IDE or Notepad. Save the file as testgoogle.py
    import sys
    import unittest
     
    try:
      import clr
      clr.AddReference("WebDriver.Common.dll")
      clr.AddReference("WebDriver.IE.dll")
      from OpenQA.Selenium import *
      from OpenQA.Selenium.IE import *
    except ImportError:
      sys.exit("This needs to be run in IronPython")
      
    class TestGoogle(unittest.TestCase):
      def setUp(self):
        '''
    	   Start the driver
    	'''
        self.driver = InternetExplorerDriver()
     
      def testGoogleSearchForTheAutomatedTester(self):
        '''
           Test to have a load Google and the search for The Automated Tester
        '''
        #Navigate to the site
        self.driver.Navigate().GoToUrl("http://www.google.com/")
        #Create an object for an element on the page
        queryBox = self.driver.FindElement(By.Name("q"))
        queryBox.SendKeys("The Automated Tester")
        #Submit the form
        queryBox.Submit()
        #Check the title of the new page has The Automated Tester in the Title
        self.assertTrue("The Automated Tester" in self.driver.Title)
     
      def tearDown(self):
        '''
    	   Clean up the driver
    	'''
        self.driver.Quit()
     
    if __name__ == '__main__':
        unittest.main()
            
  4. Now you have a test that launch a browser and do a search on Google for you. In a command prompt run ipy testgoogle.py

 

Now you have created your first test that uses WebDriver.

posted on 2012-12-13 17:52  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/12/13/2816778.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值