51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2379|回复: 3
打印 上一主题 下一主题

[求助] 调试的时候好好的,运行的时候就不行了

[复制链接]
  • TA的每日心情
    擦汗
    2016-6-29 09:56
  • 签到天数: 25 天

    连续签到: 1 天

    [LV.4]测试营长

    跳转到指定楼层
    1#
    发表于 2016-2-29 17:18:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    这是源码:
    # coding=utf-8
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import Select
    from selenium.common.exceptions import NoSuchElementException
    import unittest,time,re
    import HTMLTestRunner

    class Baidu(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(40)
            self.base_url = "http://www.baidu.com/"
            self.verificationErrors = []
            self.accept_next_alert = True

        #百度搜索用例
        def test_baidu_search(self):
            driver = self.driver
            driver.get(self.base_url + '/')
            driver.find_element_by_id("kw").send_keys("selenium")
            driver.find_element_by_id("su").click()
            time.sleep(2)
            driver.close()
        #白度设置用例
        def test_baidu_set(self):
            driver = self.driver
            driver.get(self.base_url + '/gaoji/preferences.html')
            m = driver.find_element_by_name("NR")
            m.click()
            #time.sleep(2)
            t = m.find_element_by_xpath("/html/body/form/table/tbody/tr[3]/td[2]/select/option[3]")
            #time.sleep(2)
            t.click()
            #time.sleep(2)
            driver.find_element_by_id("save").click()
            #time.sleep(2)
            driver.switch_to_alert().accept()

        def tearDown(self):
            self.driver.quit()
            self.assertEqual([],self.verificationErrors)

    if __name__ == "__main__":
        testunit = unittest.TestSuite()
        #testunit.addTest(Baidu("test_baidu_search"))
        testunit.addTest(Baidu("test_baidu_set"))
        filename = "result.html"
        fp = file(filename,'wb')
        runner = HTMLTestRunner.HTMLTestRunner(
            stream=fp,
            title = u"百度搜索测试报告",
            description = u'用例执行情况:'
         )
        runner.run(testunit)


    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2016-6-29 09:56
  • 签到天数: 25 天

    连续签到: 1 天

    [LV.4]测试营长

    2#
     楼主| 发表于 2016-2-29 17:23:40 | 只看该作者
    请大神们帮忙看看
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2017-9-21 15:25
  • 签到天数: 50 天

    连续签到: 1 天

    [LV.5]测试团长

    3#
    发表于 2016-2-29 19:32:53 | 只看该作者
    xpath用绝对路径不稳定,最好换成相对路径

    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 积极回复获得测试积点10

    查看全部评分

    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    擦汗
    2016-6-29 09:56
  • 签到天数: 25 天

    连续签到: 1 天

    [LV.4]测试营长

    4#
     楼主| 发表于 2016-3-2 09:19:54 | 只看该作者
    prettyfool 发表于 2016-2-29 19:32
    xpath用绝对路径不稳定,最好换成相对路径

    谢谢啦
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-22 01:00 , Processed in 0.080306 second(s), 24 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表