Selenium Two Tutorial using IronPython and I

系统 1826 0

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.

Selenium Two Tutorial using IronPython and InternetExplorerDriver - The Automated Tester


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论