机械手文件错误:找不到名称为“ first_step”的关键字。我在这里同时提供.py和robot文件

时间:2019-07-19 07:07:24

标签: python robotframework android-uiautomator

因此,在这里,我提供了所有四个文件,它们是测试我的移动应用程序的代码,但是运行机器人文件时出现错误。 这是错误

我是python和移动测试的初学者,在类和函数中编写代码(call_from_contacts.py)的最佳方法是什么,这样我就可以轻松地将每个移动操作作为函数调用到机器人文件并生成成功的测试报告。因此,请帮助我完成此代码。

错误:未找到名称为“ first_step”的关键字。

#1。 call_from_contacts.py

from uiautomator import Device
from time import sleep
import sys
from Adb import Adb
import events

adb = Adb()
d = Device(adb.serial)  # '32001e9bf0a36571')


name = input("Input the name of the Contact Person:")
d.wakeup()
sleep(1)
d.swipe(500, 1200, 500, 300, steps=10)


def validate_activity(activity_info):
    cmd = 'adb shell dumpsys window windows'
    out = adb.run_cmd(cmd)
    out = out.split('\n')
    for line in out:
        if 'mCurrentFocus=' in line:
            if activity_info in line:
                print("Action  successfully performed")
                return True
    print('ERROR: Action not performed!')
    return False

def first_step():
    if d(descriptionContains='Contacts').exists:
        d(descriptionContains='Contacts').click.wait()
        sleep(2)

        """
        # Validation using UIautomator
        if not d(packageName='com.samsung.android.contacts').exists:
            print("Contact app did not open")
            sys.exit()
        """

        # Validation using dumpsys
        # validate_activity('com.samsung.android.contacts')
        out = validate_activity(events.event['contacts-open'])
        if out is True:
            return True
    else:
        print("Contacts app is not available on the current screen")
        return False


first_step()
if d(descriptionContains='Search').exists:
    d(descriptionContains='Search').click.wait()
    validate_activity(events.event['contact_search-open'])

    if not d(resourceId='com.samsung.android.contacts:id/search_plate').exists:
        print("Search box did not open")
        sys.exit()
else:
    print("Error : Search button is not available")
# OR
# d.press.search()

d(text="Search").set_text(name)
d.click(245, 315)
sleep(1)
validate_activity(events.event['contact_detail_page-open'])

if d(resourceId='com.samsung.android.contacts:id/display_name_card_fourth_icon').wait.exists():
    d(resourceId='com.samsung.android.contacts:id/display_name_card_fourth_icon').click.wait()
    sleep(3)
    validate_activity(events.event['calling_window-open'])

else:
    print("There is a problem, you can make a call from SIM2")

sleep(1)
d.click(140, 1000)
validate_activity(events.event['calling_window_ws'])

print("please attend your call")



adb.restart_server()

#2。 Adb.py

import subprocess
import os
import sys
import re


class Adb:

    def __init__(self):
        self.serial = self.get_serial_number()

    def run_cmd(self, command):
        proc = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=True
        )
        stdout, stderr = proc.communicate()
        stdout = stdout.decode('utf-8').strip()
        stderr = stderr.decode('utf-8').strip()

        if proc.returncode != 0:
            print("ERROR: Command: '{}' Failed! Reason: {}".format(command, stderr))
            return False

        return stdout

    def kill_server(self):
        cmd = 'adb kill-server'
        out = self.run_cmd(cmd)

        if out is False:
            return False

        print("Server killed successfully")
        return True

    def start_server(self):
        cmd = 'adb start-server'
        out = self.run_cmd(cmd)

        if out is False:
            return False

        print("Server started successfully")
        return True

    def restart_server(self):
        if self.kill_server():
            if self.start_server():
                return True
        return False

    def get_serial_number(self):
        cmd = 'adb devices'
        out = self.run_cmd(cmd)

        if out is False:
            return False

        # arr = out.split()
        # serial = arr[4]
        serial = out.split()[4]
        return serial


# adb = Adb()
# print('Serial - ', adb.serial)
# adb.kill_server()
# adb.start_server()
# adb.get_serial_number()

#3。 events.py

event = {

     'contacts-open': 'com.samsung.android.contacts.contactslist.PeopleActivity',
     'contact_search-open': 'com.samsung.android.contacts.search.activity.ContactSearchActivity',
     'contact_detail_page-open': 'com.samsung.android.contacts.detail.ContactDetailActivity',
     'calling_window-open': 'com.smsrobot.callrecorder/com.calldorado.android.ui.wic.WicDialogActivity',
     'calling_window_ws': 'com.samsung.android.incallui/com.android.incallui.call.InCallActivity'
}

#4。 call_contact.robot

*** Settings ***
Library             ../Library/call_from_contacts.py



*** Keywords ***
Open the Contacts window
    ${result}    first_step
    Should Be True      ${result}

*** Test Cases ***

TESTCASE1
    Open the Contacts window

0 个答案:

没有答案