首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我们使用appium重新启动应用程序时,无法限制ios 11.2中的应用程序重置数据

当我们使用appium重新启动应用程序时,无法限制ios 11.2中的应用程序重置数据
EN

Stack Overflow用户
提问于 2018-01-30 17:29:30
回答 1查看 125关注 0票数 0

我需要关闭应用程序,并在我关闭它的相同位置重新启动它,因为这是使用closeApp和launchApp方法。但当我启动应用程序时,它会从头开始启动应用程序。我尝试使用noReset和fullReset选项。我使用苹果1.2.7和iOS11.2与iPhone 7 simulator.In安卓能够做到这一点使用noReset,这是可能的ios。

有谁能提个建议吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-02-01 17:10:45

做你想做的事情的唯一方法是保存你的session_id,当你启动一个新的测试时,你在之前执行的测试的结束点开始...

你要做的就是覆盖Appium构造函数和start_session:

Python类代码

代码语言:javascript
复制
class MyWebDriverAppium(webdriver.Remote):    

def __init__(self, context, command_executor='http://127.0.0.1:4444/wd/hub',
             desired_capabilities=None, session_id=None):
    self.cCore = context
    try:
        self.preserved_session_id = session_id          
        self.error_handler = MobileErrorHandler()
        self._switch_to = MobileSwitchTo(self)

        # add new method to the `find_by_*` pantheon
        By.IOS_UIAUTOMATION = MobileBy.IOS_UIAUTOMATION
        By.IOS_PREDICATE = MobileBy.IOS_PREDICATE
        By.ANDROID_UIAUTOMATOR = MobileBy.ANDROID_UIAUTOMATOR
        By.ACCESSIBILITY_ID = MobileBy.ACCESSIBILITY_ID
        super(MyWebDriverAppium, self).__init__(command_executor, desired_capabilities)
    except Exception:
        print(traceback.format_exc())
        raise MyWebDriverAppiumInit("Error initializing Appium driver")

# If preserved_session is None we will start a new session as normal
# If preserved session is not None we will use that session to execute
def start_session(self, desired_capabilities, browser_profile=None):        
    try:            
        if self.preserved_session_id:            
            self.command_executor._commands['getSession'] = ('GET', '/session/$sessionId')
            self.session_id = self.preserved_session_id
            response = self.execute('getSession', {'sessionId ': self.session_id})            
            self.session_id = response['sessionId']
            self.capabilities = response['value']
            self.w3c = response['status']
        else:
            super(MyWebDriverAppium, self).start_session(desired_capabilities, browser_profile)
    except Exception:
        raise MyWebDriverAppiumStart("Error starting Appium driver after initialization")

Python实现代码

代码语言:javascript
复制
self.driver = MyWebDriverAppium(self, self.driver_context, self.desired_caps, session_id)

Java类代码

代码语言:javascript
复制
public class MyWebDriverAppium extends RemoteWebDriver {

    private String preserved_session_id = null;

    public MyWebDriverAppium(URL remoteAddress, Capabilities desiredCapabilities, String session_id) {
        super(remoteAddress, desiredCapabilities);
        this.preserved_session_id = session_id;
    }

    @Override
    protected void startSession(Capabilities desiredCapabilities) {
        if(this.preserved_session_id != null){
            setSessionId(this.preserved_session_id);
        }
        super.startSession(desiredCapabilities);
    }
}

Java实现代码

代码语言:javascript
复制
driver = new MyWebDriverAppium<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities, session_id);

我知道python代码运行得很好,因为我每次都会在测试中使用它。我不能百分之百确定Java代码是否能完美地工作,因为我没有使用IDE。

希望能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48518005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档