element-get-attribute.test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. jest.setTimeout(30000);
  2. describe('test element-get-attribute', () => {
  3. let page;
  4. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  5. const isAndroid = platformInfo.startsWith('android')
  6. const isIos = platformInfo.startsWith('ios')
  7. const isApp = isAndroid || isIos
  8. const isWeb = platformInfo.startsWith('web')
  9. const isMP = platformInfo.startsWith('mp')
  10. beforeAll(async () => {
  11. page = await program.reLaunch('/pages/API/element-get-attribute/element-get-attribute')
  12. await page.waitFor(3000);
  13. });
  14. it('check getAttributeId', async () => {
  15. await page.callMethod('getAttributeId')
  16. expect(await page.data('attrId')).toEqual('box');
  17. });
  18. it('check setStyle getAttributeStyle', async () => {
  19. await page.callMethod('setStyle')
  20. if(isWeb||isMP){
  21. await page.callMethod('getAttributeStyle')
  22. console.log('attrStyle:',await page.data('attrStyle'))
  23. const attrStyle = isMP?'background-color:#FFF000;':'background-color: rgb(255, 240, 0);'
  24. expect(await page.data('attrStyle')).toEqual(attrStyle);
  25. }
  26. });
  27. it('check getPropertyValue', async () => {
  28. await page.callMethod('getPropertyValue')
  29. await page.waitFor(1000)
  30. const propertyValue = isWeb?'rgb(255, 240, 0)':'#FFF000'
  31. console.log('propertyValue: ',propertyValue,await page.data('propertyValue'));
  32. expect(await page.data('propertyValue')).toEqual(propertyValue);
  33. });
  34. it('getBoundingClientRectSync', async () => {
  35. await page.callMethod("getBoundingClientRectAsyncChild");
  36. await page.waitFor(100)
  37. const rectInfo = await page.data("rectInfo")
  38. const systemInfo = await program.systemInfo();
  39. const width = systemInfo.screenWidth
  40. console.log('width: ',width);
  41. console.log('rectInfo: ',rectInfo);
  42. expect(Math.round(rectInfo.x)).toBe(15)
  43. expect(Math.round(rectInfo.y) >= 242).toBe(true)
  44. expect(width - 15 * 2 - Math.round(rectInfo.width) >= 0).toBe(true)
  45. expect(Math.round(rectInfo.height)).toBe(100)
  46. expect(Math.round(rectInfo.left)).toBe(15)
  47. expect(Math.round(rectInfo.top) >= 242).toBe(true)
  48. expect(width - 15 - Math.round(rectInfo.right) >= 0).toBe(true)
  49. expect(Math.round(rectInfo.bottom) >= 342).toBe(true)
  50. })
  51. if(isApp||isMP){
  52. it('check scrollTo', async () => {
  53. await page.callMethod('scrollTo')
  54. await page.waitFor(100);
  55. const scrollView = await page.$('.scroll-view_H')
  56. expect(await scrollView.property('scrollLeft')).toBe(200);
  57. });
  58. }
  59. });