当前位置:文档之家› selenium2.0_中文帮助文档

selenium2.0_中文帮助文档

selenium2.0_中文帮助文档
selenium2.0_中文帮助文档

Selenium2.0帮助文档

第1章Webdirver基础 (2)

1.1 下载selenium2.0的lib包 (2)

1.2 用webdriver打开一个浏览器 (2)

1.3 打开测试页面 (2)

1.4 GettingStarted (2)

第2章Webdirver对浏览器的支持 (4)

2.1 HtmlUnit Driver (4)

2.2 FireFox Driver (4)

2.3 InternetExplorer Driver (4)

第3章使用操作 (4)

3.1 如何找到页面元素 (4)

3.1.1 By ID (5)

3.1.2 By Name (5)

3.1.3 By XPATH (5)

3.1.4 By Class Name (5)

3.1.5 By Link Text (5)

3.2 如何对页面元素进行操作 (6)

3.2.1 输入框(text field or textarea) (6)

3.2.2 下拉选择框(Select) (6)

3.2.3 单选项(Radio Button) (6)

3.2.4 多选项(checkbox) (7)

3.2.5 按钮(button) (7)

3.2.6 左右选择框 (7)

3.2.7 弹出对话框(Popup dialogs) (7)

3.2.8 表单(Form) (8)

3.2.9 上传文件(Upload File) (8)

3.2.10 Windows 和Frames之间的切换 (8)

3.2.11 拖拉(Drag andDrop) (8)

3.2.12 导航(Navigationand History) (8)

3.3 高级使用 (9)

3.3.1 改变user agent (9)

3.3.2 读取Cookies (9)

3.3.3 调用Java Script (9)

3.3.4 Webdriver截图 (10)

3.3.5 页面等待 (10)

第4章RemoteWebDriver (10)

4.1 使用RemoteWebDriver (10)

4.2 SeleniumServer (11)

4.3 How to setFirefox profile using RemoteWebDriver (11)

第5章封装与重用 (12)

第6章在selenium2.0中使用selenium1.0的API (14)

第1章 Webdirver基础

1.1 下载selenium

2.0的lib包

https://www.doczj.com/doc/232317115.html,/p/selenium/downloads/list

官方UserGuide:https://www.doczj.com/doc/232317115.html,/docs/

1.2 用webdriver打开一个浏览器

我们常用的浏览器有firefox和IE两种,firefox是selenium支持得比较成熟的浏览器。但是做页面的测试,速度通常很慢,严重影响持续集成的速度,这个时候建议使用HtmlUnit,不过HtmlUnitDirver运行时是看不到界面的,对调试就不方便了。使用哪种浏览器,可以做成配置项,根据需要灵活配置。

打开firefox浏览器:

//Create a newinstance of the Firefox driver

WebDriver driver = newFirefoxDriver();

打开IE浏览器

//Create a newinstance of the Internet Explorer driver

WebDriver driver = newInternetExplorerDriver ();

打开HtmlUnit浏览器

//Createa new instance of the Internet Explorer driver

WebDriverdriver = new HtmlUnitDriver();

1.3 打开测试页面

对页面对测试,首先要打开被测试页面的地址(如:https://www.doczj.com/doc/232317115.html,),web driver 提供的get方法可以打开一个页面:

// And now use thedriver to visit Google

driver.get("https://www.doczj.com/doc/232317115.html,");

1.4 GettingStarted

package org.openqa.selenium.example;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

public class Selenium2Example {

public static voidmain(String[] args) {

// Create a newinstance of the Firefox driver

// Notice that theremainder of the code relies on the interface,

// not the implementation.

WebDriver driver = newFirefoxDriver();

// And now use this tovisit Google

driver.get("https://www.doczj.com/doc/232317115.html,");

// Alternatively thesame thing can be done like this

// driver.navigate().to("https://www.doczj.com/doc/232317115.html,");

// Find the text inputelement by its name

WebElement element =driver.findElement(https://www.doczj.com/doc/232317115.html,("q"));

// Enter something tosearch for

element.sendKeys("Cheese!");

// Now submit the form.WebDriver will find the form for us from the element element.submit();

// Check the title ofthe page

System.out.println("Page title is: " + driver.getTitle());

// Google's search isrendered dynamically with JavaScript.

// Wait for the pageto load, timeout after 10 seconds

(newWebDriverWait(driver, 10)).until(new ExpectedCondition() { public Booleanapply(WebDriver d) {

returnd.getTitle().toLowerCase().startsWith("cheese!");

}

});

// Should see:"cheese! - Google Search"

System.out.println("Page title is: " + driver.getTitle());

//Close the browser

driver.quit();

}

}

第2章 Webdirver对浏览器的支持

2.1 HtmlUnit Driver

优点:HtmlUnit Driver不会实际打开浏览器,运行速度很快。对于用FireFox等浏览器来做测试的自动化测试用例,运行速度通常很慢,HtmlUnit Driver无疑是可以很好地解决这个问题。

缺点:它对JavaScript的支持不够好,当页面上有复杂JavaScript时,经常会捕获不到页面元素。

使用:

WebDriver driver = new HtmlUnitDriver();

2.2 FireFox Driver

优点:FireFox Dirver对页面的自动化测试支持得比较好,很直观地模拟页面的操作,对JavaScript的支持也非常完善,基本上页面上做的所有操作FireFox Driver都可以模拟。

缺点:启动很慢,运行也比较慢,不过,启动之后Webdriver的操作速度虽然不快但还是可以接受的,建议不要频繁启停FireFox Driver。

使用:

WebDriver driver = new FirefoxDriver();

Firefox profile的属性值是可以改变的,比如我们平时使用得非常频繁的改变useragent的功能,可以这样修改:

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("https://www.doczj.com/doc/232317115.html,eragent.override", "some UAstring");

WebDriver driver = new FirefoxDriver(profile);

2.3 InternetExplorer Driver

优点:直观地模拟用户的实际操作,对JavaScript提供完善的支持。

缺点:是所有浏览器中运行速度最慢的,并且只能在Windows下运行,对CSS以及XPA TH 的支持也不够好。

使用:

WebDriver driver = new InternetExplorerDriver();

第3章使用操作

3.1 如何找到页面元素

Webdriver的findElement方法可以用来找到页面的某个元素,最常用的方法是用id和name 查找。下面介绍几种比较常用的方法。

3.1.1 By ID

假设页面写成这样:

那么可以这样找到页面的元素:

通过id查找:

WebElement element = driver.findElement(By.id("passwd-id"));

3.1.2 By Name

或通过name查找:

WebElement element = driver.findElement(https://www.doczj.com/doc/232317115.html,("passwd"));

3.1.3 By XPATH

或通过xpath查找:

WebElement element =driver.findElement(By.xpath("//input[@id='passwd-id']"));

3.1.4 By Class Name

假设页面写成这样:

class="cheese">Cheddar

Gouda
可以通过这样查找页面元素:

Listcheeses = driver.findElements(By.className("cheese"));

3.1.5 By Link Text

假设页面元素写成这样:

cheese>

那么可以通过这样查找:

WebElement cheese =driver.findElement(By.linkText("cheese"));

3.2 如何对页面元素进行操作

找到页面元素后,怎样对页面进行操作呢?我们可以根据不同的类型的元素来进行一一说明。

3.2.1 输入框(text field or textarea)

找到输入框元素:

WebElement element = driver.findElement(By.id("passwd-id"));

在输入框中输入内容:

element.sendKeys(“test”);

将输入框清空:

element.clear();

获取输入框的文本内容:

element.getText();

3.2.2 下拉选择框(Select)

找到下拉选择框的元素:

Select select = new Select(driver.findElement(By.id("select")));

选择对应的选择项:

select.selectByVisibleText(“mediaAgencyA”);

select.selectByValue(“MA_ID_001”);

不选择对应的选择项:

select.deselectAll();

select.d eselectByValue(“MA_ID_001”);

select.deselectByVisibleText(“mediaAgencyA”);

或者获取选择项的值:

select.getAllSelectedOptions();

select.getFirstSelectedOption();

3.2.3 单选项(Radio Button)

找到单选框元素:

WebElement bookMode =driver.findElement(By.id("BookMode"));

选择某个单选项:

bookMode.click();

清空某个单选项:

bookMode.clear();

判断某个单选项是否已经被选择:

bookMode.isSelected();

3.2.4 多选项(checkbox)

多选项的操作和单选的差不多:

WebElement checkbox =driver.findElement(By.id("myCheckbox.")); checkbox.click();

checkbox.clear();

checkbox.isSelected();

checkbox.isEnabled();

3.2.5 按钮(button)

找到按钮元素:

WebElement saveButton = driver.findElement(By.id("save"));

点击按钮:

saveButton.click();

判断按钮是否enable:

saveButton.isEnabled ();

3.2.6 左右选择框

也就是左边是可供选择项,选择后移动到右边的框中,反之亦然。例如:Select lang = new Select(driver.findElement(By.id("languages")));

lang.selectByVisibleText(“English”);

WebElement addLanguage =driver.findElement(By.id("addButton")); addLanguage.click();

3.2.7 弹出对话框(Popup dialogs)

Alert alert = driver.switchTo().alert();

alert.accept();

alert.dismiss();

alert.getText();

3.2.8 表单(Form)

Form中的元素的操作和其它的元素操作一样,对元素操作完成后对表单的提交可以:WebElement approve = driver.findElement(By.id("approve"));

approve.click();

approve.submit();//只适合于表单的提交

3.2.9 上传文件 (Upload File)

上传文件的元素操作:

WebElement adFileUpload = driver.findElement(By.id("WAP-upload"));

String filePath = "C:\test\\uploadfile\\media_ads\\test.jpg";

adFileUpload.sendKeys(filePath);

3.2.10 Windows 和 Frames之间的切换

一般来说,登录后建议是先:

driver.switchTo().defaultContent();

切换到某个frame:

driver.switchTo().frame("leftFrame");

从一个frame切换到另一个frame:

driver.switchTo().frame("mainFrame");

切换到某个window:

driver.switchTo().window("windowName");

3.2.11 拖拉(Drag andDrop)

WebElement element =driver.findElement(https://www.doczj.com/doc/232317115.html,("source"));

WebElement target = driver.findElement(https://www.doczj.com/doc/232317115.html,("target"));

(new Actions(driver)).dragAndDrop(element, target).perform();

3.2.12 导航 (Navigationand History)

打开一个新的页面:

driver.navigate().to("https://www.doczj.com/doc/232317115.html,");

通过历史导航返回原页面:

driver.navigate().forward();

driver.navigate().back();

3.3 高级使用

3.3.1 改变user agent

User Agent的设置是平时使用得比较多的操作:

FirefoxProfile profile = new FirefoxProfile();

profile.addAdditionalPreference("https://www.doczj.com/doc/232317115.html,eragent.override","some UA string");

WebDriver driver = new FirefoxDriver(profile);

3.3.2 读取Cookies

我们经常要对的值进行读取和设置。

增加cookie:

// Now set the cookie. This one's valid for the entire domain

Cookie cookie = new Cookie("key", "value");

driver.manage().addCookie(cookie);

获取cookie的值:

// And now output all the available cookies for the current URL

Set allCookies = driver.manage().getCookies();

for (Cookie loadedCookie : allCookies) {

System.out.println(String.format("%s -> %s",loadedCookie.getName(), loadedCookie.getValue()));

}

根据某个cookie的name获取cookie的值:

driver.manage().getCookieNamed("mmsid");

删除cookie:

// You can delete cookies in 3 ways

// By name

driver.manage().deleteCookieNamed("CookieName");

// By Cookie

driver.manage().deleteCookie(loadedCookie);

// Or all of them

driver.manage().deleteAllCookies();

3.3.3 调用Java Script

Web driver对Java Script的调用是通过JavascriptExecutor来实现的,例如:JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("(function(){inventoryGridMgr.setTableFieldValue('"+ inventoryId + "','" + fieldName + "','"

+ value + "');})()");

3.3.4 Webdriver截图

如果用webdriver截图是:

driver = webdriver.Firefox()

driver.save_screenshot("C:\error.jpg")

3.3.5 页面等待

因为Load页面需要一段时间,如果页面还没加载完就查找元素,必然是查找不到的。最好的方式,就是设置一个默认等待时间,在查找页面元素的时候如果找不到就等待一段时间再找,直到超时。

Webdriver提供两种方法,一种是显性等待,另一种是隐性等待。

显性等待:

WebDriver driver =new FirefoxDriver();

driver.get("http://somedomain/url_that_delays_loading");

WebElement myDynamicElement = (new WebDriverWait(driver, 10))

.until(new ExpectedCondition(){

@Override

public WebElement apply(WebDriver d) {

returnd.findElement(By.id("myDynamicElement"));

}});

隐性等待:

WebDriver driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("http://somedomain/url_that_delays_loading");

WebElement myDynamicElement =driver.findElement(By.id("myDynamicElement"));

第4章 RemoteWebDriver

当本机上没有浏览器,需要远程调用浏览器进行自动化测试时,需要用到RemoteWebDirver.

4.1 使用RemoteWebDriver

import java.io.File;

import https://www.doczj.com/doc/232317115.html,.URL;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.remote.Augmenter;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

public class Testing {

public void myTest()throws Exception {

WebDriver driver = newRemoteWebDriver(

new URL("http://localhost:4446/wd/hub"),

DesiredCapabilities.firefox());

driver.get("https://www.doczj.com/doc/232317115.html,");

// RemoteWebDriverdoes not implement the TakesScreenshot class

// if the driver doeshave the Capabilities to take a screenshot

// then Augmenter willadd the TakesScreenshot methods to the instance

WebDriveraugmentedDriver = new Augmenter().augment(driver);

File screenshot =((TakesScreenshot)augmentedDriver).

getScreenshotAs(OutputType.FILE);

}

}

4.2 SeleniumServer

在使用RemoteDriver时,必须在远程服务器启动一个SeleniumServer:

java -jar selenium-server-standalone-2.20.0.jar -port 4446

4.3 How to setFirefox profile using RemoteWebDriver

profile = new FirefoxProfile();

profile.setPreference("https://www.doczj.com/doc/232317115.html,eragent.override",testData.getUserAgent()); capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("firefox_profile", profile);

driver = new RemoteWebDriver(new U RL(“http://localhost:4446/wd/hub”),capabilities);

driverWait = new WebDriverWait(driver,TestConstant.W AIT_ELEMENT_TO_LOAD); driver.get("https://www.doczj.com/doc/232317115.html,");

第5章封装与重用

WebDriver对页面的操作,需要找到一个WebElement,然后再对其进行操作,比较繁琐: // Find the text inputelement by its name

WebElement element = driver.findElement(https://www.doczj.com/doc/232317115.html,("q"));

// Enter something to search for

element.sendKeys("Cheese!");

我们可以考虑对这些基本的操作进行一个封装,简化操作。比如,封装代码:protected void sendKeys(By by, String value){

driver.findElement(by).sendKeys(value);

}

那么,在测试用例可以这样简化调用:

sendKeys(https://www.doczj.com/doc/232317115.html,("q"),”Cheese!”);

看,这就简洁多了。

类似的封装还有:

package com.drutt.mm.end2end.actions;

import java.util.List;

import java.util.NoSuchElementException;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.support.ui.WebDriverWait;

import com.drutt.mm.end2end.data.TestConstant;

public class WebDriverAction {

//protected WebDriverdriver;

protected RemoteWebDriverdriver;

protected WebDriverWaitdriverWait;

protected boolean isWebElementExist(By selector) {

try {

driver.findElement(selector);

return true;

} catch(NoSuchElementException e) {

return false;

}

}

protected StringgetWebText(By by) {

try {

return driver.findElement(by).getText();

} catch (NoSuchElementException e) {

return "Textnot existed!";

}

}

protected voidclickElementContainingText(By by, String text){

ListelementList = driver.findElements(by);

for(WebElement e:elementList){

if(e.getText().contains(text)){

e.click();

break;

}

}

}

protected StringgetLinkUrlContainingText(By by, String text){

ListsubscribeButton = driver.findElements(by);

String url = null;

for(WebElement e:subscribeButton){

if(e.getText().contains(text)){

url =e.getAttribute("href");

break;

}

}

return url;

}

protected void click(Byby){

driver.findElement(by).click();

driver.manage().timeouts().implicitlyWait(TestConstant.WAIT_ELEMENT_TO_LOAD,Time Unit.SECONDS);

}

protected StringgetLinkUrl(By by){

return driver.findElement(by).getAttribute("href");

}

protected void sendKeys(Byby, String value){

driver.findElement(by).sendKeys(value);

}

第6章在selenium2.0中使用selenium1.0的API

Selenium2.0中使用WeDriver API对页面进行操作,它最大的优点是不需要安装一个selenium server就可以运行,但是对页面进行操作不如selenium1.0的Selenium RC API那么方便。Selenium2.0提供了使用Selenium RC API的方法:

// You may use any WebDriver implementation. Firefox is used here as an example

WebDriver driver = new FirefoxDriver();

// A "base url", used by selenium to resolve relativeURLs

String baseUrl ="https://www.doczj.com/doc/232317115.html,";

// Create the Selenium implementation

Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);

// Perform actions with selenium

selenium.open("https://www.doczj.com/doc/232317115.html,");

selenium.type("name=q", "cheese");

selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This willrefer to the

// same WebDriver instance as the "driver" variableabove.

WebDriver driverInstance = ((WebDriverBackedSelenium)selenium).getUnderlyingWebDriver();

//Finally, close thebrowser. Call stop on the WebDriverBackedSelenium instance

//instead of callingdriver.quit(). Otherwise, the JVM will continue running after

//the browser has beenclosed.

selenium.stop();

我分别使用WebDriver API和SeleniumRC API写了一个Login的脚本,很明显,后者的操作更加简单明了。

WebDriver API写的Login脚本:

public void login() {

driver.switchTo().defaultContent();

driver.switchTo().frame("mainFrame");

WebElement eUsername= waitFindElement(By.id("username"));

eUsername.sendKeys(manager@https://www.doczj.com/doc/232317115.html,);

WebElement ePassword= waitFindElement(By.id("password"));

ePassword.sendKeys(manager);

WebElementeLoginButton = waitFindElement(By.id("loginButton")); eLoginButton.click();

}

SeleniumRC API写的Login脚本:

public void login() {

selenium.selectFrame("relative=top");

selenium.selectFrame("mainFrame");

selenium.type("username","manager@https://www.doczj.com/doc/232317115.html,");

selenium.type("password","manager");

selenium.click("loginButton");

}

Revolve产品知识

产品名称BOSE SoundLink Revolve 产地墨西哥颜色灰/银 产品尺寸/重量 152×82×82mm/660g 续航时间 12小时 充电时间4小时 供电方式锂电池 音频接口 3.5mm/ USB接口(只限电脑音源)单元尺寸3英寸 NFC功能是 防水级别IPX4防水 通话功能是 语音提示是 APP 是 保修期一年(注册微信会员赠送延保6个月) 包装清单音箱本机x1 USB电源x1USB连接线 x1 交流电源适配器 x1 技术特点1360度全向发声:一个向下发声的全音域单元配合BOSE专利的声波导向技术,可以向四周发出均匀,无死角的声音 技术特点2独特优势:体积小巧 低音震撼 技术特点3优雅的设计:采用高品质阳极氧化铝金属材质配合全新的无缝连接一体成型工艺,是产品更为高雅,耐用 技术特点4蓝牙无线连接:方便,易用,可连接几乎是所有常规的智能手机,平板电脑的蓝牙设 备,可支持与蓝牙设备10米距离的无线连接。技术特点5内置锂电池:更好的便携性,4小时充满电可在正常音量下约12小时的使用时间。 技术特点6IPX4级防水:可以使您在室外环境中放心使用。技术特点7BOSE Connect APP :轻松实现“派对模式”与“立体声模式”的切换,可以满足您更多声音需求。技术特点8支持有线连接:3.5mm与USB接口可以满足你有线音源的连接,连接更多的设备。 技术特点9可选配充电底座:充电方便,同时为扬声器在家中使用时提供了一个放置的地方。 技术特点10 远程操作:可通过配对的蓝牙设备控制扬声器的各项功能(如音量等)不需要携带其他产品说明

音效表现 Feature令人惊艳的宏亮气势,超乎想象的小巧体积。Benefit体积小巧 低音震撼 Advantage 精巧的外壳下装载了众多技术,展现出扬声器超乎想象的的低音效能,让人深深的沉醉在饱满的动人音色中。 Evidence X先生经常会带着家中的小朋友到户外和同事们野餐,因为有小孩子每次外出都需要随身带很多东西。聚会时大家喜欢拿出手机播放孩子们喜欢的音乐增加气氛,偶尔路过门店体验到我们的产品,十分满意。不仅可以满足了他外出携带需要,还提供了完美的音质 360°音效 Feature 可以向四周发出均匀的,无死角的声音。实现零死角的环绕音效。 Benefit随意摆放,一样可以体验到全方位的声音。 Advantage 一个向下发声的全音域单元配合BOSE专利的声波导向器,营造出全方位,无死角的震撼 Evidence X女士三口之家,每天晚上喜欢在客厅给孩子放放音乐,孩子太小总是跑来跑去,之前的音响固定的放在一个位置声音太大影响邻居,声音太小孩子跑来跑去还听不见。选择了我们产品后放在家里中间的位置不管孩子 精致设计 Feature 一体成型的采用高品质阳极氧化铝金属材质配合全新的无缝连接一体成型工艺。 Benefit使产品更为高雅,耐用。 Advantage 精密的设计,一体成型的阳极氧化铝材质,可以提供全方位的音效,不留一丝缝隙,外 Evidence X小姐喜欢游泳,喜欢做SPA ,喜欢泡温泉,更喜欢听音乐。自从购买了产品,她可以随意带着音响到她喜欢的地方,再也没有任何的顾虑。无论什么环境,我们的产品都可以

python-ctypes模块中文帮助文档

内容: .加载动态链接库 .从已加载的dll中引用函数 .调用函数1 .基本的数据类型 .调用函数2 .用自己的数据类型调用函数 .确认需要的参数类型(函数原型) .返回值 .传递指针 .结构和联合 .结构或联合的对齐方式和字节的顺序 .结构和联合中的位 .数组 .指针 .类型转换 .未完成的类型 .回调函数 .访问dlls导出的值 .可变长度的数据类型 .bugs 将要做的和没有做的事情 注意:本文中的代码例子使用doctest确保他们能够实际工作。一些代码例子在linux和windows以及苹果机上执行有一定的差别 注意:一些代码引用了ctypes的c_int类型。它是c_long在32位机子上的别名,你不应该变得迷惑,如果你期望 的是c_int类型,实事上打印的是c_long,它们实事上是相同的类型。 加载动态链接库 ctypes加载动态链接库,导出cdll和在windows上同样也导出windll和oledll对象。 加载动态链接库后,你可以像使用对象的属性一样使用它们。cdll加载使用标准的cdecl调用约定的链接库, 而windll库使用stdcall调用约定,oledll也使用stdcall调用约定,同时确保函数返回一个windows HRESULT错误代码。这错误 代码自动的升为WindowsError Python exceptions,当这些函数调用失败时。 这有一些windows例子,msvcrt是微软的c标准库,包含大部分的标准c函数,同时使用cdecl调用约定。 注:cdecl和stdcall的区别请见https://www.doczj.com/doc/232317115.html,/log-20.html >>> from ctypes import * >>> print windll.kernel32 # doctest: +WINDOWS

CAD和TSSD快捷键(含探索者中文键名)

AutoCAD 简化命令 3A, *3DARRAY 3DO, *3DORBIT 3F, *3DFACE 3P, *3DPOLY A, *ARRAY ,阵列ADC, *ADCENTER AD, *ID AE, *AREA AL, *ALIGN AP, *APERTURE ATP, *ATTDISP AT, *DDATTE -AT, *ATTEDIT ATT, *DDATTDEF -ATT, *ATTDEF AV, *DSVIEWER B, *BREAK H, *BHATCH BL, *BMAKE -BL, *BLOCK BO, *BOUNDARY -BO, *-BOUNDARY CO, *COPY CC, *CHAMFER CH, *DDCHPROP -CH, *CHANGE DDC, *DDCOLOR C, *CIRCLE D, *DIM DD, *DDEDIT DDV, *DDVPOINT DI, *DIST DIV, *DIVIDE DO, *DONUT DST, *DIMSTYLE DT, *DTEXT DV, *DVIEW DX, *DDIM DXI, *DXFIN DXO, *DXFOUT E, *ERASE EL, *ELEV ELL, *ELLIPSE EN, *END EP, *EXPLODE EX, *EXTEND F, *FILLET FF, *FILL FI, *FILTER G, *GROUP GR, *DDGRIPS -GR, *GRID HI, *HIDE HE, *HATCHEDIT HT, *HATCH I, *DDINSERT -I, *INSERT IM, *IMAGE -IM, *-IMAGE L, *LINE LA, *LAYER -LA, *-LAYER LE, *LEADER LEN, *LENGTHEN LI, *LIST LS, *LTSCALE LT, *LINETYPE -LT, *-LINETYPE LTS, *LTSCALE M, *MOVE MA, *MATCHPROP ME, *MEASURE MI, *MIRROR ML, *MLINE MO, *DDMODIFY MN, *MENU MS, *MSPACE MT, *MTEXT -MT, *-MTEXT MV, *MVIEW N, *NEW O, *OFFSET OP, *OPEN OS, *OSNAP

python-os模块中文帮助文档

注此模块中关于unix中的函数大部分都被略过,翻译主要针对WINDOWS,翻译速度很快,其中很多不足之处请多多包涵。 这个模块提供了一个轻便的方法使用要依赖操作系统的功能。如何你只是想读或写文件,请使用open() ,如果你想操作文件路径,请使用os.path模块,如果你想在命令行中,读入所有文件的所有行,请使用 fileinput模块。使用tempfile模块创建临时文件和文件夹,更高级的文件和文件夹处理,请使用shutil模块。 os.error 内建OSError exception的别名。 https://www.doczj.com/doc/232317115.html, 导入依赖操作系统模块的名字。下面是目前被注册的名字:'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'. 下面的function和data项是和当前的进程和用户有关 os.environ 一个mapping对象表示环境。例如,environ['HOME'] ,表示的你自己home文件夹的路径(某些平台支持,windows不支持) ,它与C中的getenv("HOME")一致。 这个mapping对象在os模块第一次导入时被创建,一般在python启动时,作为site.py处理过程的一部分。在这一次之后改变environment不 影响os.environ,除非直接修改os.environ. 注:putenv()不会直接改变os.environ,所以最好是修改os.environ 注:在一些平台上,包括FreeBSD和Mac OS X,修改environ会导致内存泄露。参考putenv()的系统文档。 如果没有提供putenv(),mapping的修改版本传递给合适的创建过程函数,将导致子过程使用一个修改的environment。 如果这个平台支持unsetenv()函数,你可以删除mapping中的项目。当从os.environ使用pop()或clear()删除一个项目时,unsetenv()会自动被调用(版本2.6)。 os.chdir(path) os.fchdir(fd) os.getcwd() 这些函数在Files和Directories中。

【资料】Airpak中文帮助文档(1.7部分)

Airpak中文帮助文档(1.7部分) 此文翻译来自Airpak帮助文档1.7部分 通过1.7部分,你将使用Airpak 建立一个问题、解决一个问题以及输出结果。这是 对Airpak 特点的基础介绍。 如有疑问可参考Airpak帮助文档的相关部分

1.7 示例 在下面的示例中,你将使用Airpak建立一个问题、解决一个问题以及输出结果。这是对Airpak特点的基础介绍。使用指南中的例子将提供更完整的程序特点。 1.7.1 问题描述 图1.7.1显示的所要解决的问题。房间中包含了一个开放的进风口、一个排气口和一个恒定温度的墙。房间的长是4.57 m,宽是 2.74 m,高是2.74m。房间外测量值是0.92 m ×0.46 m,同时引入一个冷空气射入房间使得空气流动。排气口的尺寸是0.91 m×0.45 m。惯性的力量、浮力的力量以及湍流混合的相互作用对所提供的空气的渗透及路径有着重要的影响。 1.7.2 主要的过程 图1.7.1显示的问题是一个稳定通风的情形。边界温度以及速度是被定义的。示例中的步骤简要如下: z打开和定义一项工作 z调整默认房间大小 z对于一个房间生成一个进风口(opening)、排气口(vent)以及墙 z生成网格 z计算

z检查结果 1.7.3 开始一个新工作 启动Airpak(1.5节)。图1.7.2.显示的是【Open job】面板。 在【Select the job to open】文本显示框中路径的最后将/sample写上。点击【Accept】打开一个新工作。Airpak将生成一个10 m×3 m×10 m默认房间,同时在图形窗口显示房间。 你可以使用鼠标左键围绕一个中心点旋转房间,或者使用鼠标中间键你可以将房间转移到屏幕的任意一点上。使用右键放大或缩小房间。为了将房间回复的默认方位,点击【Options】菜单下【Orient】,在下拉菜单中选择【Home】。 1.7.4 定义工作 通过定义房间的种类和设置环境温度来开始工作。这些参数在【Problem setup】面板中具体指明了。在【File】菜单中选择【Problem】可以打开【Problem setup】面板(如图1.7.3)。

pyevolve中文帮助文档

Pyevolve的用户手册中文版 1.1.6基本概念 Raw score:表示由适应度函数返回的还未进行比例换算的适应值。 Fitness score :对Raw score进行比例换算后的适应值,如果你使用线性的比例换算(Scaling.LinearScaling()),fitness score将会使用线性方法进行换算,fitness score代表个体与种群的相关程度。 Sample genome : 是所有genome进行复制的基础 1.2.3对pyevolve进行扩展 对pyevolve进行扩展首先要查看GenomeBase.GenomeBase类的源码。 扩展的基本步骤 1)创建染色体类 2)创建染色体的初始化函数 3)创建遗传算子:选择算子,交叉算子,和变异算子等。 1.3模块 1.3.2基本模块 a) Consts :常量模块 Pyevolve 提供了所有的默认遗传算子,这是为了帮助用户方便的使用API,在常量模块中,你可以找到这些默认的设置,最好的情况是查看常量模块,但是不改变常量模块中的内容。 b)Util :公用模块 公用模块中提供了一些公用的函数,比如列表项的交换,随机功能等。 list2DSwapElement(lst, indexa, indexb):交换矩阵中的元素项。 listSwapElement(lst, indexa, indexb):交换列表中的元素项。 c)FunctionSlot :函数分片模块 Pyevolve中广泛使用函数分片的概念;这个想法是很简单的,每个遗传操作或者说是任何遗传操作能够被分配到一个片,按照这种想法,我们能够添加不止一种的遗传操作,比如说同时进行两种或者更多的变异操作,或者两种或更多的计算操作等,函数分片模块是以FunctionSlot.FunctionSlot类来实现的。 例子: Def fit_fun(genome): …. Def fit_fun2(genome): …. Genome.evaluator.set(fit_fun) Genome.evaluator.add(fit_fun2) Print Genome.evaluator #the result is “slot [evaluator] (count:2)” Print Genome.evaluator[0] # the result is “function fit_fun at <....>” Print Genome.evaluator[1] # the result is “function fit_fun2 at <...>”

相关主题
文本预览
相关文档 最新文档