Compare commits
	
		
			14 Commits 
		
	
	
		
			184656230f
			...
			1d23062c47
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
									
								
								 | 
						1d23062c47 | |
| 
							
							
								
									
								
								 | 
						df34770af0 | |
| 
							
							
								
									
								
								 | 
						b626df7c4b | |
| 
							
							
								
									
								
								 | 
						bd5f8f63f5 | |
| 
							
							
								
									
								
								 | 
						2500fa5fc8 | |
| 
							
							
								
									
								
								 | 
						6b3ad77c44 | |
| 
							
							
								 | 
						9aa718b236 | |
| 
							
							
								 | 
						230e8e92dc | |
| 
							
							
								
									
								
								 | 
						4ea6d9aeed | |
| 
							
							
								
									
								
								 | 
						768c81828d | |
| 
							
							
								
									
								
								 | 
						b7fe68c54d | |
| 
							
							
								
									
								
								 | 
						b8f2919959 | |
| 
							
							
								
									
								
								 | 
						f164465903 | |
| 
							
							
								
									
								
								 | 
						04c4064c68 | 
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
<html lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <title>Title</title>
 | 
			
		||||
    <title>单词词频</title>
 | 
			
		||||
 | 
			
		||||
    {{ yml['header'] | safe }}
 | 
			
		||||
    {% if yml['css']['item'] %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
from selenium import webdriver
 | 
			
		||||
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
 | 
			
		||||
from selenium.webdriver.support import expected_conditions as EC
 | 
			
		||||
from selenium import webdriver
 | 
			
		||||
from selenium.webdriver.support.wait import WebDriverWait
 | 
			
		||||
from selenium.webdriver.common.by import By
 | 
			
		||||
from selenium.webdriver.common.keys import Keys
 | 
			
		||||
import logging
 | 
			
		||||
import time
 | 
			
		||||
import pytest
 | 
			
		||||
 | 
			
		||||
@pytest.mark.parametrize("test_input,expected",
 | 
			
		||||
                         [("‘test1’", "test1"),
 | 
			
		||||
                          ("'test2'", "test2"),
 | 
			
		||||
                          ("“test3”", "test3"),
 | 
			
		||||
                          ("it's", "it's"),
 | 
			
		||||
                          ("hello,I'm linshan", ["hello","i'm","linshan"]),
 | 
			
		||||
                          ("Happy New Year!?", ["happy","new","year"]),
 | 
			
		||||
                          ("My favorite book is 《Harry Potter》。", ["potter","harry","my","favorite","book","is"])])
 | 
			
		||||
def test_bug553_LinShan(test_input,expected, driver, URL):
 | 
			
		||||
    try:
 | 
			
		||||
        # 打开对应地址的网页
 | 
			
		||||
        driver.get(URL)
 | 
			
		||||
 | 
			
		||||
        # 浏览器最大窗口化
 | 
			
		||||
        driver.maximize_window()
 | 
			
		||||
 | 
			
		||||
        # 判断网页源代码中是否有English Pal -文字
 | 
			
		||||
        assert 'English Pal -' in driver.page_source
 | 
			
		||||
 | 
			
		||||
        # 将测试的数据输入到主页的textarea里
 | 
			
		||||
        driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
 | 
			
		||||
        driver.find_element_by_xpath("//textarea[@name='content']").send_keys(test_input)
 | 
			
		||||
        time.sleep(1)
 | 
			
		||||
 | 
			
		||||
        # 点击按钮获取单词
 | 
			
		||||
        driver.find_element_by_xpath("//input[@value='get文章中的词频']").click()
 | 
			
		||||
        time.sleep(1)
 | 
			
		||||
 | 
			
		||||
        # 获取筛选后的单词
 | 
			
		||||
        words = driver.find_elements_by_xpath("//p/a")
 | 
			
		||||
 | 
			
		||||
        # 遍历获取到的单词,并判断单词与预期的相同
 | 
			
		||||
        for word in words:
 | 
			
		||||
            # 判断单词是否在预期结果中
 | 
			
		||||
            assert word.text in expected
 | 
			
		||||
            
 | 
			
		||||
        # 返回上一页网页
 | 
			
		||||
        driver.find_element_by_xpath("//input[@value='确定并返回']").click()
 | 
			
		||||
        time.sleep(0.1)
 | 
			
		||||
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        # 输出异常信息
 | 
			
		||||
        logging.error(e)
 | 
			
		||||
        # 关闭浏览器
 | 
			
		||||
        driver.quit()
 | 
			
		||||
    finally:
 | 
			
		||||
        driver.quit()
 | 
			
		||||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
###########################################################################
 | 
			
		||||
 | 
			
		||||
import collections
 | 
			
		||||
import html
 | 
			
		||||
import string
 | 
			
		||||
import operator
 | 
			
		||||
import os, sys # 引入模块sys,因为我要用里面的sys.argv列表中的信息来读取命令行参数。
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +40,8 @@ def file2str(fname):#文件转字符
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
 | 
			
		||||
    special_characters = '\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
 | 
			
		||||
    special_characters = '\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|,。?!¥……()、《》:;·' # 把里面的字符都去掉
 | 
			
		||||
    s = html.unescape(s) # 将HTML实体转换为对应的字符,比如<会被识别为小于号
 | 
			
		||||
    for c in special_characters:
 | 
			
		||||
        s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
 | 
			
		||||
    s = s.replace('--', ' ')
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +106,7 @@ if __name__ == '__main__':
 | 
			
		|||
        print('%s\t%d\t%s' % (x[0], x[1], youdao_link(x[0])))#函数导出
 | 
			
		||||
 | 
			
		||||
    # 把频率的结果放result.html中
 | 
			
		||||
    make_html_page(sort_in_descending_order(L), 'result.html') 
 | 
			
		||||
    make_html_page(sort_in_descending_order(L), 'result.html')
 | 
			
		||||
 | 
			
		||||
    print('\nHistory:\n')
 | 
			
		||||
    if os.path.exists('frequency.p'):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue