How to use a.getTagName method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

demo.js

Source: demo.js Github

copy
1function cl(some){
2	return console.log(some);
3}
4/*window.onload = function(){
5
6	$().getTagName('body').css('backgroundColor','lightgray');
7	cl($().getId('box').css('backgroundColor','lime').css('margin-top','59px'));
8	cl($().getTagName('p').html('haha').elements.length); //3
9	$().getTagName('p').html('eee').click(function(){cl('hh');}).css('backgroundColor','cornsilk');
10}*/
11
12/*window.onload = function(){
13	var base = new Base();
14	//cl(base.getId('box').css('color','lime'));
15	cl(base.getTagName('p').css('color','orange'));
16	//cl(base.getId('box').css('color','lime').css('backgroundColor','lightgray'));
17	cl(base.getTagName('p').elements.length);//4??
18	cl(base.getTagName('p').css('margin-left','100px').elements.length);
19	//base.getTagName('p').css('margin-left','50px').html('caption');
20	base.getId('box').click(function(){
21		cl('hh');
22	}).css('backgroundColor','maroon');
23}*/
24
25cl(document.getElementById);
26window.onload = function(){
27
28	$().getTagName('body').css('backgroundColor','lightgray');
29	cl($().getId('box').css('backgroundColor','lime').css('margin-top','59px'));
30	cl($().getTagName('p').html('haha').elements.length); //3
31	$().getTagName('p').html('eee').click(function(){cl('hh');}).css('backgroundColor','cornsilk');
32}
33/*window.onload = function(){
34	cl($);
35	cl($);
36}*/
37/*//每次点击都是+2 ???
38window.onload = function(){
39	//cl($());
40	$.getTagName('body').css('backgroundColor','lightgray');
41	cl($.getId('box').css('backgroundColor','lime'));
42	cl($.getTagName('p').elements.length); //3
43	$.getTagName('p').click(function(){
44		cl('hh');
45	}).css('color','fushcia'); //can't change the color
46}*/
47
48
49
50
51/*
52	//css,html,click等方法返回的均是Base对象,
53		//而不是一个元素节点对象;
54window.onload = function(){
55	// cl(Base.getTagName('p')[0].innerHTML);
56	
57	Base.getId('box').css('color', 'red').css('backgroundColor','black').html('pox')
58	.click(function(){alert('NB');
59	});
60
61cl(Base.getId('box'));  //Base is not defined??
62}
63*/
Full Screen

getTagName.js

Source: getTagName.js Github

copy
1/**
2 * Internal dependencies
3 */
4import { getTagName } from '../maybeSetTagName';
5
6const mockGetBlocksByClientId = jest.fn( () => [] );
7const mockGetBlockOrder = jest.fn( () => [] );
8const mockGetBlock = jest.fn();
9const mockUpdateBlockAttributes = jest.fn();
10
11jest.mock( '@wordpress/data', () => {
12	return {
13		select: () => ( {
14			getBlocksByClientId: ( ...args ) => mockGetBlocksByClientId( ...args ),
15			getBlockOrder: ( ...args ) => mockGetBlockOrder( ...args ),
16			getBlock: ( ...args ) => mockGetBlock( ...args ),
17		} ),
18
19		dispatch: () => ( {
20			updateBlockAttributes: ( ...args ) => mockUpdateBlockAttributes( ...args ),
21		} ),
22	};
23} );
24
25describe( 'getTagName', () => {
26	it( 'should return type if explicitly set', () => {
27		expect( getTagName( { type: 'h2' } ) ).toBe( 'h2' );
28	} );
29
30	it( 'should return p if block offset is below threshold', () => {
31		expect( getTagName( { positionTop: 200 } ) ).toBe( 'p' );
32	} );
33
34	it( 'should return heading if text is large enough', () => {
35		expect( getTagName( { fontSize: 'huge' }, true ) ).toBe( 'h1' );
36		expect( getTagName( { fontSize: 'huge' }, false ) ).toBe( 'h2' );
37		expect( getTagName( { customFontSize: 50 }, true ) ).toBe( 'h1' );
38		expect( getTagName( { customFontSize: 50 }, false ) ).toBe( 'h2' );
39		expect( getTagName( { fontSize: 'large' }, true ) ).toBe( 'h2' );
40		expect( getTagName( { customFontSize: 30 }, true ) ).toBe( 'h2' );
41		expect( getTagName( { customFontSize: 30 }, false ) ).toBe( 'h2' );
42	} );
43
44	it( 'should return heading if text is short enough', () => {
45		expect( getTagName( { content: 'Hello World' }, true ) ).toBe( 'h1' );
46		expect( getTagName( { content: 'Hello World' }, false ) ).toBe( 'h2' );
47		expect( getTagName( { content: 'This heading is a bit longer' }, true ) ).toBe( 'h2' );
48		expect( getTagName( { content: 'This heading is a bit longer' }, false ) ).toBe( 'h2' );
49	} );
50
51	it( 'should return paragraph if text is long enough', () => {
52		expect( getTagName( { content: 'This content is way longer than what is normal for a heading' }, false ) ).toBe( 'p' );
53	} );
54} );
55
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)