GithubHelp home page GithubHelp logo

Comments (8)

brianlaibaoqin avatar brianlaibaoqin commented on July 20, 2024

用HTML 运行 以下代码。出现以上bug 。

coding=utf-8

from selenium import webdriver
import unittest

class Test_ranzhi(unittest.TestCase):

url = 'http://laibaoqin.top/ranzhi/www'
user = 'admin'
password = 12345678


@classmethod
def setUpClass(cls):
    cls.driver = webdriver.Firefox()

@classmethod
def tearDownClass(cls):
    cls.driver.quit()

def test_case1(self):
    pass
    self.driver.maximize_window()
    self.driver.implicitly_wait(30)
    self.driver.get(url)
    text = self.driver.find_element_by_css_selector(".btn").text
    print(text)
    if text != "繁體":  # 选择系统语言
        self.driver.find_element_by_css_selector(".btn").click()
        self.driver.find_element_by_xpath("//*[text()='繁體']").click()

    self.driver.find_element_by_css_selector("#account").send_keys(user)
    self.driver.find_element_by_css_selector("#password").send_keys(password)
    self.driver.find_element_by_xpath("//*[@id='keepLoginon']").click()
    self.driver.find_element_by_css_selector('#submit').click()

    try:
        act_name = self.driver.find_elements_by_css_selector(".nav.navbar-nav>li>a")[0].text
        print(act_name)
        assert act_name == "admin"
    except Exception as e:
        print("验证出错了", e)

    print("11111113")
    self.assertEqual(1 ,2)

from htmltestrunner_cn.

brianlaibaoqin avatar brianlaibaoqin commented on July 20, 2024

python3

from htmltestrunner_cn.

brianlaibaoqin avatar brianlaibaoqin commented on July 20, 2024
self.driver.find_element_by_css_selector("#account").send_keys(user)
self.driver.find_element_by_css_selector("#password").send_keys(password)   有参数化的 报AttributeError: 'NoneType' object has no attribute 'find'  ,请看看 ! 

from htmltestrunner_cn.

GoverSky avatar GoverSky commented on July 20, 2024

没重现啊,兄弟!你的参数化作用域也不对,下面根本引用不到的,还不如放在class上面

from htmltestrunner_cn.

GoverSky avatar GoverSky commented on July 20, 2024
#-*- coding: utf-8 -*-
from selenium import webdriver
import unittest
import time
url = 'http://laibaoqin.top/ranzhi/www'
user = 'admin'
password = 12345678

class Test_ranzhi(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Firefox()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def test_case1(self):
        """一个测试用例"""
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)
        self.driver.get(url)
        text = self.driver.find_element_by_css_selector(".btn").text
        print(text)
        if text != "繁體":  # 选择系统语言
            self.driver.find_element_by_css_selector(".btn").click()
            self.driver.find_element_by_xpath("//*[text()='繁體']").click()

        self.driver.find_element_by_css_selector("#account").send_keys(user)
        self.driver.find_element_by_css_selector("#password").send_keys(password)
        self.driver.find_element_by_xpath("//*[@id='keepLoginon']").click()

        self.driver.find_element_by_css_selector('#submit').click()
        time.sleep(1)
        try:
            print(self.driver.find_element_by_class_name('bootbox-body').text)
            self.driver.find_element_by_xpath('//button[@data-bb-handler="ok"]').click()
        except:
            pass
        try:
            act_name = self.driver.find_elements_by_css_selector(".nav.navbar-nav>li>a")[0].text
            print(act_name)
            assert act_name == "admin"
        except Exception as e:
            print("验证出错了", e)

        print("233")
        self.assertEqual(1 ,2)

from htmltestrunner_cn.

brianlaibaoqin avatar brianlaibaoqin commented on July 20, 2024

image
1, 我发现我的原因在哪里了,就是你的bug!

from htmltestrunner_cn.

GoverSky avatar GoverSky commented on July 20, 2024

1、在teardownClass 中初始化driver 是不会重启浏览器的,一个测试类只执行一次,要每次测试都重启放在setUp和tearDown中初始化和关闭
2、我这不编写注释也没有问题的,不知道你的问什么返回了None,因为本身用的是TestCase的_testMethodDoc,这块再针对改一下~
image

from htmltestrunner_cn.

brianlaibaoqin avatar brianlaibaoqin commented on July 20, 2024

我的python 版本3.6 anaconda装的

from htmltestrunner_cn.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.