Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add execute commands for removing files #1095

Merged
merged 3 commits into from
Oct 24, 2019
Merged

Conversation

imurchie
Copy link
Contributor

Adds functions (mobile: deleteFile and mobile: deleteFolder) to remove files/folders from the device or simulator.

Locally this has been tested with an iPhone 7 Plus running iOS 13.1 with

describe('keynote', function () {
  const caps = {
    bundleId: 'com.apple.Keynote',
    platformName: 'iOS',
    platformVersion: '13.1',
    automationName: 'XCUITest',
    udid: 'auto',
    app: null,
    browserName: null,
  }
  let driver;
  before(async function () {
    driver = await initSession(caps);
  });
  after(async function () {
    await deleteSession();
  });

  it('should push a file', async function () {
    const stringData = `random string data ${Math.random()}`;
    const base64Data = Buffer.from(stringData).toString('base64');
    const remotePath = '@com.apple.Keynote:documents/higher.txt';

    await driver.pushFile(remotePath, base64Data);

    const remoteStringData = await pullFileAsString(driver, remotePath);
    remoteStringData.should.equal(stringData);

    await driver.execute('mobile: deleteFile', {remotePath});

    await pullFileAsString(driver, remotePath).should.eventually.be.rejectedWith(/does not exist on the device/);
  });
});

}
throw e;
} finally {
service.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

`Will get the data from '${dstPath}'`);
pathOnServer = dstPath;
} else {
const simRoot = device.getDir();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may potentially damage Simulator FS. Should we rather limit absolute paths, to only known subfolders?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it's much of a problem. If people mess things up, oh well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, only full reset will restore the Simulator in such case

Copy link
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree w/ @mykola-mokhnach but otherwise +1

async function deleteFromSimulator (device, remotePath) {
let pathOnServer;
if (CONTAINER_PATH_PATTERN.test(remotePath)) {
const { bundleId, pathInContainer: dstPath } = await parseContainerPath(remotePath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we usually don't have spaces around braces except in imports, i thought.

const {bundleId, pathInContainer: dstPath} = await parseContainerPath(remotePath,
async (appBundle, containerType) => await getAppContainer(device.udid, appBundle, null, containerType));
log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +
`Will get the data from '${dstPath}'`);
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this info message needs some update

@imurchie imurchie merged commit cf99c17 into master Oct 24, 2019
@imurchie imurchie deleted the isaac-delete-file branch October 24, 2019 14:26
khanayan123 pushed a commit to khanayan123/appium-xcuitest-driver that referenced this pull request May 10, 2021
* feat: add execute commands for removing files

* fix: address review

* fix: adjust logging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants