def create_world(mp: MasParams): world = World(w=mp.G, h=mp.G, torus_enabled=True) n_ores = round(mp.G**2 * mp.D) for _ in range(n_ores): world.add_agent(Ore()) positions = [] for x in range(mp.G): for y in range(mp.G): positions.append(Vec2D(x, y)) base_positions = random.sample(positions, mp.N) if mp.M == 1: # cooperation company_ids = [0] * mp.N else: # competitive company_ids = list(range(mp.N)) for base_pos, comp_id in zip(base_positions, company_ids): base = Base(mp, comp_id) world.add_agent(base, base_pos) for _ in range(mp.X): world.add_agent(Explorer(base, mp, comp_id), pos=base_pos) for _ in range(mp.Y): world.add_agent(Transporter(base, mp, comp_id), pos=base_pos) return world
def group_setting_name(self, rename): base = Base(self.driver) # 点击群设置 base.click([By.ID, "com.cnmts.smart_message:id/btn_right"]) # 更改群名称 base.click([By.ID, "com.cnmts.smart_message:id/tv_change_group_name"]) base.sendKeys([By.ID, "com.cnmts.smart_message:id/et_content"], rename) base.click([By.ID, "com.cnmts.smart_message:id/tv_save"])
def create_group_status(self): title = Base(self.driver).isElementExist( [By.ID, "com.cnmts.smart_message:id/tv_title"]) if title: logging.info("========create group success========") return True else: logging.info("========create group fail========") return False
def group_setting_group3(self): base = Base(self.driver) # 点击群设置 base.click([By.ID, "com.cnmts.smart_message:id/btn_right"]) # 解散群聊 sleep(2) base.click([By.ID, "com.cnmts.smart_message:id/btn_exit_group"]) self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("确定")').click()
def send_word(self, word): base = Base(self.driver) for i in range(2): base.sendKeys([By.ID, "com.cnmts.smart_message:id/rc_edit_text"], word) base.click([By.ID, "com.cnmts.smart_message:id/rc_send_toggle"]) base.click([By.ID, "com.cnmts.smart_message:id/rc_emoticon_toggle"]) for i in range(3): base.click([By.ID, "com.cnmts.smart_message:id/rc_ext_emoji_item"]) base.click([By.ID, "com.cnmts.smart_message:id/rc_send_toggle"])
def login_status(self): base = Base(self.driver) ele = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/img_ming_lu"]) if ele: logging.info("========login success========") return True else: logging.info("========login fail========") base.screenShot("login_zx fail") return False
def initialize(self): logging.info("========initialize========") base = Base(self.driver) for i in range(10): myself = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/message"]) if myself: base.click([By.ID, "com.cnmts.smart_message:id/message"]) break else: self.driver.keyevent(4)
def send_location(self): # 发送位置 base = Base(self.driver) ele = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"]) if ele: pass else: base.click([By.ID, "com.cnmts.smart_message:id/rc_plugin_toggle"]) base.findElements( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"])[2].click() base.click([By.ID, "com.cnmts.smart_message:id/btn_location_send"])
def create_group1(self): base = Base(self.driver) base.click([By.ID, "com.cnmts.smart_message:id/img_show_more"]) self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("发起群聊")').click() base.click([By.ID, "com.cnmts.smart_message:id/tv_title"]) base.findElements([By.ID, "com.cnmts.smart_message:id/tv_full_name" ])[1].click() sleep(1) self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("智能平台研发部")').click() base.findElements([By.ID, "com.cnmts.smart_message:id/radio_select" ])[3].click() base.click([By.ID, "com.cnmts.smart_message:id/btn_ok"])
def send_document(self): # 发送文件 base = Base(self.driver) ele = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"]) if ele: pass else: base.click([By.ID, "com.cnmts.smart_message:id/rc_plugin_toggle"]) base.findElements( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"])[3].click() base.click([By.ID, "com.cnmts.smart_message:id/radio_select"]) base.click([By.ID, "com.cnmts.smart_message:id/layout_send"])
def login_zx2(self, username="******", password="******"): base = Base(self.driver) skip = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/tv_jump"]) if skip: base.click([By.ID, "com.cnmts.smart_message:id/tv_jump"]) else: pass logging.info("======login zhixin======") base.click([By.ID, "com.cnmts.smart_message:id/tv_change_user"]) base.sendKeys([By.ID, "com.cnmts.smart_message:id/et_username"], username) base.sendKeys([By.ID, "com.cnmts.smart_message:id/et_pwd"], password) base.click([By.ID, "com.cnmts.smart_message:id/btn_login"])
def send_picture(self): # 发送图片 base = Base(self.driver) # 需要加+的判断 ele = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"]) if ele: pass else: base.click([By.ID, "com.cnmts.smart_message:id/rc_plugin_toggle"]) base.findElements( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"])[0].click() base.click([By.ID, "com.cnmts.smart_message:id/tv_select"]) base.click([By.ID, "com.cnmts.smart_message:id/tv_confirm"])
def login_out_zx(self): base = Base(self.driver) logging.info("========login out========") for i in range(10): myself = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/people"]) if myself: base.click([By.ID, "com.cnmts.smart_message:id/people"]) break else: self.driver.keyevent(4) self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("退出登录")').click() sleep(1) self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("确定")').click()
def take_photo(self): # 拍摄图片 base = Base(self.driver) ele = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"]) if ele: pass else: base.click([By.ID, "com.cnmts.smart_message:id/rc_plugin_toggle"]) base.findElements( [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"])[1].click() sleep(2) base.findElements([By.CLASS_NAME, "android.view.View"])[1].click() sleep(2) base.findElements([By.CLASS_NAME, "android.view.View"])[1].click()
def group_setting_group1(self): base = Base(self.driver) # 点击群设置 base.click([By.ID, "com.cnmts.smart_message:id/btn_right"]) # 群减人 number = base.findElement( [By.ID, "com.cnmts.smart_message:id/tv_group_member_size"]).text a = re.findall(r"\d+\.?\d*", number) b = int(a[0]) if b < 4: c = b + 2 base.findElements([By.ID, "com.cnmts.smart_message:id/iv_avatar" ])[c].click() else: base.findElements([By.ID, "com.cnmts.smart_message:id/iv_avatar" ])[6].click() self.driver.find_element_by_android_uiautomator( 'new UiSelector().text("任少龙")').click() base.click([By.ID, "com.cnmts.smart_message:id/btn_sure"]) sleep(2)
def group_setting_group2(self): base = Base(self.driver) # 点击群设置 base.click([By.ID, "com.cnmts.smart_message:id/btn_right"]) number = base.findElement( [By.ID, "com.cnmts.smart_message:id/tv_group_member_size"]).text a = re.findall(r"\d+\.?\d*", number) b = int(a[0]) # 群加人 if b < 3: d = b + 1 base.findElements([By.ID, "com.cnmts.smart_message:id/iv_avatar" ])[d].click() else: sleep(2) base.findElements([By.ID, "com.cnmts.smart_message:id/iv_avatar" ])[5].click() base.click([By.ID, "com.cnmts.smart_message:id/query"]) base.sendKeys([By.ID, "com.cnmts.smart_message:id/query"], "王德晨") base.click([By.ID, "com.cnmts.smart_message:id/radio_select"]) base.click([By.ID, "com.cnmts.smart_message:id/btn_ok"])
def approval_company_project(self, name): sleep(1) base = Base(self.driver) # 点击正式项目管理 base.click([By.XPATH, "//*[@id='leftBox']/ul/li[2]/ul/li/ul/li[1]"]) # 选择要审批的项目 sleep(1) for num in range(1, 6): companyname = self.driver.find_element_by_xpath( '//*[@id="pane-first"]/div/div[3]/div/div[3]/table/tbody/tr[' + str(num) + ']/td[3]/div').text if name == str(companyname): # 点击查看 self.driver.find_element_by_xpath( '//*[@id="pane-first"]/div/div[3]/div/div[4]/div[2]/table/tbody/tr[' + str(num) + ']/td[9]/div/div/div[1]').click() break # 点击同意 base.click( [By.XPATH, '//*[@id="printContent"]/div[1]/div[2]/div/span[1]']) base.sendKeys([By.CLASS_NAME, "el-textarea__inner"], "同意同意同意") base.click([ By.XPATH, '//*[@id="approvalDetail"]/div[2]/div/div[3]/span/button[2]/span' ]) sleep(1) # 点击审批主题 base.click([ By.XPATH, '//*[@id="pane-first"]/div/div[1]/form/div[2]/div/div/div/input' ]) # 选择我已审批 sleep(1) base.click([By.XPATH, '/html/body/div[2]/div[1]/div[1]/ul/li[2]/span']) # 点击查询 base.click([ By.XPATH, '//*[@id="pane-first"]/div/div[1]/div/div[2]/button[1]/span' ])
def login_zx1(self, username, password): base = Base(self.driver) skip = base.isElementExist( [By.ID, "com.cnmts.smart_message:id/tv_jump"]) if skip: base.click([By.ID, "com.cnmts.smart_message:id/tv_jump"]) else: pass for i in range(5): logging.info("======quanxian_setting======") permission_allow = base.isElementExist([ By.ID, "com.android.packageinstaller:id/permission_allow_button" ]) if permission_allow: logging.info("======quanxian_cunzai======") base.click([ By.ID, "com.android.packageinstaller:id/permission_allow_button" ]) else: break logging.info("======login zhixin======") base.click([By.ID, "com.cnmts.smart_message:id/tv_change_user"]) base.sendKeys([By.ID, "com.cnmts.smart_message:id/et_username"], username) base.sendKeys([By.ID, "com.cnmts.smart_message:id/et_pwd"], password) base.click([By.ID, "com.cnmts.smart_message:id/btn_login"]) # 需要加一个新用户的判断 # 电池优化权限 self.driver.implicitly_wait(40) button = base.isElementExist([By.ID, "android:id/button1"]) if button: base.click([By.ID, "android:id/button1"]) else: pass
def search(self, keyword): logging.info("========start serch========") base = Base(self.driver) base.click([By.ID, "com.cnmts.smart_message:id/search"]) base.sendKeys([By.ID, "com.cnmts.smart_message:id/query"], keyword) base.click([By.ID, "com.cnmts.smart_message:id/layout_item"])
def longpress(self): base = Base(self.driver) el = base.findElements( [By.ID, "com.cnmts.smart_message:id/text_message"])[0] TouchAction(self.driver).long_press(el, 1000).perform()