How to use getSelectionInformation method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

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

PlacementCell.js

Source: PlacementCell.js Github

copy
1import { useContext } from "react";
2import { StyledPlacementCell } from "./styles/components.js";
3import { GameDispatch } from "./Game";
4
5export const PlacementCell = ({
6  cell,
7  setPointer,
8  getSelectionInformation,
9  board,
10  playerID,
11  currentShip,
12  horizontalPlacement,
13}) => {
14  const { x, y, ship } = cell;
15  const dispatch = useContext(GameDispatch);
16
17  const handleHover = () => {
18    setPointer(y, x);
19  };
20  // return how the cell should appear when rendered
21  const checkIfValid = () => {
22    let currentSelection = getSelectionInformation();
23    if (!currentSelection.valid) return false;
24    //check if there is a ship in current selection
25    if (
26      currentSelection.cells.some((coords) => {
27        // return false if any cell has a ship
28        return board[coords[0]][coords[1]].ship !== false;
29      })
30    ) {
31      return false;
32    }
33    return true;
34  };
35  const testRenderStyle = () => {
36    if (ship) return "ship";
37    let currentSelection = getSelectionInformation();
38    // check if cell is in range. render appropriately
39    if (
40      currentSelection.cells.some(
41        (coords) => coords[0] === y && coords[1] === x
42      )
43    ) {
44      // check if selection has any out of bounds
45      //check if there is a ship in current selection
46      if (currentShip.placed) return;
47      return checkIfValid() ? "valid" : "invalid";
48    }
49    // if cell doesn't have ship and isnt in selection
50    return "empty";
51  };
52  const handlePlacement = () => {
53    if (!checkIfValid()) return;
54    if (currentShip.placed) return;
55
56    dispatch({
57      type: "PLACE-SHIP",
58      playerID: playerID,
59      payload: {
60        x: x,
61        y: y,
62        ship: currentShip,
63        horizontal: horizontalPlacement,
64      },
65    });
66  };
67
68  return (
69    <>
70      <StyledPlacementCell
71        bg_color={testRenderStyle()}
72        onMouseEnter={handleHover}
73        onClick={handlePlacement}
74      />
75    </>
76  );
77};
78
Full Screen

TD21Q3_06-2_sceneInformation.js

Source: TD21Q3_06-2_sceneInformation.js Github

copy
1/*
2input: speciffic scene
3output: text information in the message log describing elements of the scene
4
5*/
6
7function write(message){
8	MessageLog.trace(message)
9	System.println(message)
10}
11
12function getSelectionInformation(){
13	//MessageLog.trace("getSelectionInformation() has been clicked")
14	
15	var nodeTypesToShow = ["WRITE", "MultiLayerWrite"]
16	
17	var env_path 		= scene.currentEnvironmentPath() 
18	var proj_path 		= scene.currentProjectPath() 
19	var proj_temp_path 	= scene.tempProjectPathRemapped() 
20	var scene_name		= scene.currentScene()
21	var scene_start_f	= scene.getStartFrame() 
22	var scene_stop_f	= scene.getStopFrame() 
23	var scene_length 	= scene_stop_f - scene_start_f
24	
25	var outputMessage   = "Scene Information:"
26
27	// give me information on the current scene
28	//outputMessage += ("\nEnvironment  = " + env_path)
29	//outputMessage += ("\nProject          = " + proj_path)
30	//outputMessage += ("\nProject TEMP = " + proj_temp_path)
31	outputMessage += scene.currentScene()
32	outputMessage += ("\t" + scene_length +"f ["+ scene_start_f + " -> " + scene_stop_f + "]")
33	
34	write(outputMessage)
35	
36	// give me a list of all nodes selected
37	var myNodeSelection_total = selection.numberOfNodesSelected()
38	if (myNodeSelection_total <= 0){
39		// if none are selected then list all nodes in the scene
40		selection.selectAll()
41	}
42	
43	var myNodeSelection 	= selection.selectedNodes()
44	var writeCounter 		= 0
45	
46	
47	
48	for( n in myNodeSelection ){
49		
50		var thisNode		= myNodeSelection[n]
51		var thisNode_type 	= node.type(thisNode)
52		
53		for ( t in nodeTypesToShow){
54			var thisType = nodeTypesToShow[t]
55			
56			if( thisNode_type == thisType ){
57				writeCounter += 1
58				write( "Write Node ["+ writeCounter + "] " + myNodeSelection[n] + " [" + node.type(thisNode) +"]" )
59				
60				// we will now get the render path for this write node
61				var thisNode_drawingPath = node.getTextAttr("Top/Write", frame.current(),"drawingName") 
62				var thisNode_moviePath 	= node.getTextAttr("Top/Write", frame.current(),"moviePath") 
63
64				write( "Drawing Path = " + thisNode_drawingPath )
65				write( "Movie Path = " + thisNode_moviePath )
66
67			}
68		}
69	}
70
71	
72	write("\n\n")
73}
74
75//getSelectionInformation()
76
77
78// TODO output the Movie & image sequence export path for each write node.
79
80
Full Screen

tableAlignCol.js

Source: tableAlignCol.js Github

copy
1/**
2 * @fileoverview Implements table align column WysiwygCommand
3 * @author NHN FE Development Lab <dl_javascript@nhn.com>
4 */
5import $ from 'jquery';
6
7import CommandManager from '../commandManager';
8import domUtil from '../domUtils';
9
10/**
11 * AlignCol
12 * Align selected column's text content to given direction
13 * @extends Command
14 * @module wysiwygCommands/TableAlignCol
15 * @ignore
16 */
17const TableAlignCol = CommandManager.command('wysiwyg', /** @lends AlignCol */{
18  name: 'AlignCol',
19  /**
20   * command handler
21   * @param {WysiwygEditor} wwe wysiwygEditor instance
22   * @param {string} alignDirection Align direction
23   */
24  exec(wwe, alignDirection) {
25    const sq = wwe.getEditor();
26    const range = sq.getSelection().cloneRange();
27    const selectionMgr = wwe.componentManager.getManager('tableSelection');
28    const rangeInformation = getRangeInformation(range, selectionMgr);
29
30    wwe.focus();
31
32    if (sq.hasFormat('TR')) {
33      sq.saveUndoState(range);
34
35      const $table = $(range.startContainer).parents('table');
36
37      const selectionInformation = getSelectionInformation($table, rangeInformation);
38
39      setAlignAttributeToTableCells($table, alignDirection, selectionInformation);
40    }
41    selectionMgr.removeClassAttrbuteFromAllCellsIfNeed();
42  }
43});
44
45/**
46 * Set Column align
47 * @param {jQuery} $table jQuery wrapped TABLE
48 * @param {string} alignDirection 'left' or 'center' or 'right'
49 * @param {{
50 *     startColumnIndex: number,
51 *     endColumnIndex: number,
52 *     isDivided: boolean
53 *     }} selectionInformation start, end column index and boolean value for whether range divided or not
54 */
55function setAlignAttributeToTableCells($table, alignDirection, selectionInformation) {
56  const isDivided = selectionInformation.isDivided || false;
57  const start = selectionInformation.startColumnIndex;
58  const end = selectionInformation.endColumnIndex;
59  const columnLength = $table.find('tr').eq(0).find('td,th').length;
60
61  $table.find('tr').each((n, tr) => {
62    $(tr).children('td,th').each((index, cell) => {
63      if (isDivided &&
64                ((start <= index && index <= columnLength) || (index <= end))
65      ) {
66        $(cell).attr('align', alignDirection);
67      } else if ((start <= index && index <= end)) {
68        $(cell).attr('align', alignDirection);
69      }
70    });
71  });
72}
73
74/**
75 * Return start, end column index and boolean value for whether range divided or not
76 * @param {jQuery} $table jQuery wrapped TABLE
77 * @param {{startColumnIndex: number, endColumnIndex: number}} rangeInformation Range information
78 * @returns {{startColumnIndex: number, endColumnIndex: number, isDivided: boolean}}
79 */
80function getSelectionInformation($table, rangeInformation) {
81  const columnLength = $table.find('tr').eq(0).find('td,th').length;
82  const {
83    from,
84    to
85  } = rangeInformation;
86  let startColumnIndex, endColumnIndex, isDivided;
87
88  if (from.row === to.row) {
89    startColumnIndex = from.cell;
90    endColumnIndex = to.cell;
91  } else if (from.row < to.row) {
92    if (from.cell <= to.cell) {
93      startColumnIndex = 0;
94      endColumnIndex = columnLength - 1;
95    } else {
96      startColumnIndex = from.cell;
97      endColumnIndex = to.cell;
98      isDivided = true;
99    }
100  }
101
102  return {
103    startColumnIndex,
104    endColumnIndex,
105    isDivided
106  };
107}
108
109/**
110 * Get range information
111 * @param {Range} range Range object
112 * @param {object} selectionMgr Table selection manager
113 * @returns {object}
114 */
115function getRangeInformation(range, selectionMgr) {
116  const $selectedCells = selectionMgr.getSelectedCells();
117  let rangeInformation, startCell;
118
119  if ($selectedCells.length) {
120    rangeInformation = selectionMgr.getSelectionRangeFromTable($selectedCells.first().get(0),
121      $selectedCells.last().get(0));
122  } else {
123    const {startContainer} = range;
124    startCell = domUtil.isTextNode(startContainer) ? $(startContainer).parent('td,th')[0] : startContainer;
125    rangeInformation = selectionMgr.getSelectionRangeFromTable(startCell, startCell);
126  }
127
128  return rangeInformation;
129}
130
131export default TableAlignCol;
132
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 Playwright Internal 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)