关于前端与UI自动化之间

web自动化

--html页面的编写与介绍

--web元素的定位

--自动化脚本

一.一个简单的登录页面

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主机后台管理</title>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
<link href='http://fonts.googleapis.com/css?family=Belgrano' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="loginpanelwrap">
      
    <div class="loginheader">
    <div class="logintitle"><a href="#">欢迎登陆</a></div>
    </div>

    <form action="/host_app/login/" method="post">
        <div class="loginform">

            <div class="loginform_row">
            <label>账号:</label>
            <input type="text" class="loginform_input" name="username" />
            </div>
            <div class="loginform_row">
            <label>密码:</label>
            <input type="text" class="loginform_input" name="password" />
            </div>
            <div class="loginform_row">
                <span style="color: red " >{{ error }}</span>
            <input type="submit" class="loginform_submit" value="登录" />
            </div>
            <div class="clear"></div>
        </div>

    </form>
</div>

        
</body>
</html>

主要的页面操作都写<body>标签中,所以先关注body标签中的元素。(css/script)

二.自动化脚本知识点:

 1.关于chrome浏览器的解除限制:

options = webdriver.ChromeOptions()
options.add_argument('disable-infobars')

browser = webdriver.Chrome('/Users/bernie/Documents/chromedriver',chrome_options=options)


2.浏览器最大化;
(mac下chrome)

options.add_argument('--kiosk')

其他
For MAC or Linux:
 ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--kiosk");
driver = new ChromeDriver(chromeOptions);

For Windows:
 ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
driver = new ChromeDriver(chromeOptions);

 ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");

  3.关于alert弹窗的关闭

  import selenium.webdriver.common.alert
  webdriver.common.alert.Alert(browser).accept()

 4.关于excel处理
  import xlrd,xlwt

  workbook = xlwt.Workbook(encoding='ascii')
  
  worksheet = workbook.add_sheet('My Worksheet')
  testCaseFile = os.path.join(os.getcwd(), testCaseFile)
  if not os.path.exists(testCaseFile):
  logging.error('ceshiyongliwenjianbucunzai')
  sys.exit()

  testCase = xlrd.open_workbook(testCaseFile)
  table = testCase.sheet_by_index(0)

  for i in range(1, table.nrows):
  if table.cell(i, 7).value.replace(' ', '').replace(' ', '') == 'Yes':
  continue

   a1 = table.cell(i, 0).value.replace(' ', '').replace(' ', '') # 逐行获取手机号信息





推荐博客:https://www.cnblogs.com/fnng/p/4540731.html

 

  

  






A wise man thinks all that he says, a fool says all that he thinks.
原文地址:https://www.cnblogs.com/BernieChen/p/6760289.html