idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
15,900 | protected void assertLegalRelativeAddition ( String relativePropertySourceName , PropertySource < ? > propertySource ) { String newPropertySourceName = propertySource . getName ( ) ; if ( relativePropertySourceName . equals ( newPropertySourceName ) ) { throw new IllegalArgumentException ( "PropertySource named '" + newPropertySourceName + "' cannot be added relative to itself" ) ; } } | Ensure that the given property source is not being added relative to itself . |
15,901 | private void addAtIndex ( int index , PropertySource < ? > propertySource ) { removeIfPresent ( propertySource ) ; this . propertySourceList . add ( index , propertySource ) ; } | Add the given property source at a particular index in the list . |
15,902 | private int assertPresentAndGetIndex ( String name ) { int index = this . propertySourceList . indexOf ( PropertySource . named ( name ) ) ; if ( index == - 1 ) { throw new IllegalArgumentException ( "PropertySource named '" + name + "' does not exist" ) ; } return index ; } | Assert that the named property source is present and return its index . |
15,903 | public void fail ( ) { hasFailure = true ; long count = latch . getCount ( ) ; for ( int i = 0 ; i < count ; i ++ ) { latch . countDown ( ) ; } } | Countdown and fail - fast if the sub message is failed . |
15,904 | protected final void putInt16 ( int i16 ) { ensureCapacity ( position + 2 ) ; byte [ ] buf = buffer ; buf [ position ++ ] = ( byte ) ( i16 & 0xff ) ; buf [ position ++ ] = ( byte ) ( i16 >>> 8 ) ; } | Put 16 - bit integer in the buffer . |
15,905 | protected final void putInt32 ( long i32 ) { ensureCapacity ( position + 4 ) ; byte [ ] buf = buffer ; buf [ position ++ ] = ( byte ) ( i32 & 0xff ) ; buf [ position ++ ] = ( byte ) ( i32 >>> 8 ) ; buf [ position ++ ] = ( byte ) ( i32 >>> 16 ) ; buf [ position ++ ] = ( byte ) ( i32 >>> 24 ) ; } | Put 32 - bit integer in the buffer . |
15,906 | protected final void putString ( String s ) { ensureCapacity ( position + ( s . length ( ) * 2 ) + 1 ) ; System . arraycopy ( s . getBytes ( ) , 0 , buffer , position , s . length ( ) ) ; position += s . length ( ) ; buffer [ position ++ ] = 0 ; } | Put a string in the buffer . |
15,907 | public static final String collateCharset ( String charset ) { String [ ] output = StringUtils . split ( charset , "COLLATE" ) ; return output [ 0 ] . replace ( '\'' , ' ' ) . trim ( ) ; } | utf8 COLLATE utf8_general_ci |
15,908 | public void updateByQuery ( ESSyncConfig config , Map < String , Object > paramsTmp , Map < String , Object > esFieldData ) { if ( paramsTmp . isEmpty ( ) ) { return ; } ESMapping mapping = config . getEsMapping ( ) ; BoolQueryBuilder queryBuilder = QueryBuilders . boolQuery ( ) ; paramsTmp . forEach ( ( fieldName , value ) -> queryBuilder . must ( QueryBuilders . termsQuery ( fieldName , value ) ) ) ; DataSource ds = DatasourceConfig . DATA_SOURCES . get ( config . getDataSourceKey ( ) ) ; StringBuilder sql = new StringBuilder ( "SELECT * FROM (" + mapping . getSql ( ) + ") _v WHERE " ) ; List < Object > values = new ArrayList < > ( ) ; paramsTmp . forEach ( ( fieldName , value ) -> { sql . append ( "_v." ) . append ( fieldName ) . append ( "=? AND " ) ; values . add ( value ) ; } ) ; int len = sql . length ( ) ; sql . delete ( len - 4 , len ) ; Integer syncCount = ( Integer ) Util . sqlRS ( ds , sql . toString ( ) , values , rs -> { int count = 0 ; try { while ( rs . next ( ) ) { Object idVal = getIdValFromRS ( mapping , rs ) ; append4Update ( mapping , idVal , esFieldData ) ; commitBulk ( ) ; count ++ ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return count ; } ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Update ES by query affected {} records" , syncCount ) ; } } | update by query |
15,909 | public static String getCharset ( final int id ) { Entry entry = getEntry ( id ) ; if ( entry != null ) { return entry . mysqlCharset ; } else { logger . warn ( "Unexpect mysql charset: " + id ) ; return null ; } } | Return defined charset name for mysql . |
15,910 | public static String getCollation ( final int id ) { Entry entry = getEntry ( id ) ; if ( entry != null ) { return entry . mysqlCollation ; } else { logger . warn ( "Unexpect mysql charset: " + id ) ; return null ; } } | Return defined collaction name for mysql . |
15,911 | public static String getJavaCharset ( final int id ) { Entry entry = getEntry ( id ) ; if ( entry != null ) { if ( entry . javaCharset != null ) { return entry . javaCharset ; } else { logger . warn ( "Unknown java charset for: id = " + id + ", name = " + entry . mysqlCharset + ", coll = " + entry . mysqlCollation ) ; return null ; } } else { logger . warn ( "Unexpect mysql charset: " + id ) ; return null ; } } | Return converted charset name for java . |
15,912 | public static HashMode getPartitionHashColumns ( String name , String pkHashConfigs ) { if ( StringUtils . isEmpty ( pkHashConfigs ) ) { return null ; } List < PartitionData > datas = partitionDatas . get ( pkHashConfigs ) ; for ( PartitionData data : datas ) { if ( data . simpleName != null ) { if ( data . simpleName . equalsIgnoreCase ( name ) ) { return data . hashMode ; } } else { if ( data . regexFilter . filter ( name ) ) { return data . hashMode ; } } } return null ; } | match return List not match return null |
15,913 | private final void decodeFields ( LogBuffer buffer , final int len ) { final int limit = buffer . limit ( ) ; buffer . limit ( len + buffer . position ( ) ) ; for ( int i = 0 ; i < columnCnt ; i ++ ) { ColumnInfo info = columnInfo [ i ] ; switch ( info . type ) { case MYSQL_TYPE_TINY_BLOB : case MYSQL_TYPE_BLOB : case MYSQL_TYPE_MEDIUM_BLOB : case MYSQL_TYPE_LONG_BLOB : case MYSQL_TYPE_DOUBLE : case MYSQL_TYPE_FLOAT : case MYSQL_TYPE_GEOMETRY : case MYSQL_TYPE_JSON : info . meta = buffer . getUint8 ( ) ; break ; case MYSQL_TYPE_SET : case MYSQL_TYPE_ENUM : logger . warn ( "This enumeration value is only used internally " + "and cannot exist in a binlog: type=" + info . type ) ; break ; case MYSQL_TYPE_STRING : { int x = ( buffer . getUint8 ( ) << 8 ) ; x += buffer . getUint8 ( ) ; info . meta = x ; break ; } case MYSQL_TYPE_BIT : info . meta = buffer . getUint16 ( ) ; break ; case MYSQL_TYPE_VARCHAR : info . meta = buffer . getUint16 ( ) ; break ; case MYSQL_TYPE_NEWDECIMAL : { int x = buffer . getUint8 ( ) << 8 ; x += buffer . getUint8 ( ) ; info . meta = x ; break ; } case MYSQL_TYPE_TIME2 : case MYSQL_TYPE_DATETIME2 : case MYSQL_TYPE_TIMESTAMP2 : { info . meta = buffer . getUint8 ( ) ; break ; } default : info . meta = 0 ; break ; } } buffer . limit ( limit ) ; } | Decode field metadata by column types . |
15,914 | public LogEvent decode ( LogBuffer buffer , LogContext context ) throws IOException { final int limit = buffer . limit ( ) ; if ( limit >= FormatDescriptionLogEvent . LOG_EVENT_HEADER_LEN ) { LogHeader header = new LogHeader ( buffer , context . getFormatDescription ( ) ) ; final int len = header . getEventLen ( ) ; if ( limit >= len ) { LogEvent event ; if ( handleSet . get ( header . getType ( ) ) ) { buffer . limit ( len ) ; try { event = decode ( buffer , header , context ) ; } catch ( IOException e ) { if ( logger . isWarnEnabled ( ) ) { logger . warn ( "Decoding " + LogEvent . getTypeName ( header . getType ( ) ) + " failed from: " + context . getLogPosition ( ) , e ) ; } throw e ; } finally { buffer . limit ( limit ) ; } } else { event = new UnknownLogEvent ( header ) ; } if ( event != null ) { event . getHeader ( ) . setLogFileName ( context . getLogPosition ( ) . getFileName ( ) ) ; event . setSemival ( buffer . semival ) ; } buffer . consume ( len ) ; return event ; } } buffer . rewind ( ) ; return null ; } | Decoding an event from binary - log buffer . |
15,915 | public final int compareTo ( String fileName , final long position ) { final int val = this . fileName . compareTo ( fileName ) ; if ( val == 0 ) { return ( int ) ( this . position - position ) ; } return val ; } | Compares with the specified fileName and position . |
15,916 | public final LogBuffer duplicate ( final int pos , final int len ) { if ( pos + len > limit ) throw new IllegalArgumentException ( "limit excceed: " + ( pos + len ) ) ; final int off = origin + pos ; byte [ ] buf = Arrays . copyOfRange ( buffer , off , off + len ) ; return new LogBuffer ( buf , 0 , len ) ; } | Return n bytes in this buffer . |
15,917 | public final LogBuffer forward ( final int len ) { if ( position + len > origin + limit ) throw new IllegalArgumentException ( "limit excceed: " + ( position + len - origin ) ) ; this . position += len ; return this ; } | Forwards this buffer s position . |
15,918 | public final LogBuffer consume ( final int len ) { if ( limit > len ) { limit -= len ; origin += len ; position = origin ; return this ; } else if ( limit == len ) { limit = 0 ; origin = 0 ; position = 0 ; return this ; } else { throw new IllegalArgumentException ( "limit excceed: " + len ) ; } } | Consume this buffer moving origin and position . |
15,919 | public final int getInt8 ( final int pos ) { if ( pos >= limit || pos < 0 ) throw new IllegalArgumentException ( "limit excceed: " + pos ) ; return buffer [ origin + pos ] ; } | Return 8 - bit signed int from buffer . |
15,920 | public final int getUint8 ( final int pos ) { if ( pos >= limit || pos < 0 ) throw new IllegalArgumentException ( "limit excceed: " + pos ) ; return 0xff & buffer [ origin + pos ] ; } | Return 8 - bit unsigned int from buffer . |
15,921 | public final String getFixString ( final int pos , final int len , String charsetName ) { if ( pos + len > limit || pos < 0 ) throw new IllegalArgumentException ( "limit excceed: " + ( pos < 0 ? pos : ( pos + len ) ) ) ; final int from = origin + pos ; final int end = from + len ; byte [ ] buf = buffer ; int found = from ; for ( ; ( found < end ) && buf [ found ] != '\0' ; found ++ ) ; try { return new String ( buf , from , found - from , charsetName ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Unsupported encoding: " + charsetName , e ) ; } } | Return fix length string from buffer . |
15,922 | public final String getFixString ( final int len , String charsetName ) { if ( position + len > origin + limit ) throw new IllegalArgumentException ( "limit excceed: " + ( position + len - origin ) ) ; final int from = position ; final int end = from + len ; byte [ ] buf = buffer ; int found = from ; for ( ; ( found < end ) && buf [ found ] != '\0' ; found ++ ) ; try { String string = new String ( buf , from , found - from , charsetName ) ; position += len ; return string ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Unsupported encoding: " + charsetName , e ) ; } } | Return next fix length string from buffer . |
15,923 | public final String getString ( final int pos , String charsetName ) { if ( pos >= limit || pos < 0 ) throw new IllegalArgumentException ( "limit excceed: " + pos ) ; byte [ ] buf = buffer ; final int len = ( 0xff & buf [ origin + pos ] ) ; if ( pos + len + 1 > limit ) throw new IllegalArgumentException ( "limit excceed: " + ( pos + len + 1 ) ) ; try { return new String ( buf , origin + pos + 1 , len , charsetName ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Unsupported encoding: " + charsetName , e ) ; } } | Return dynamic length string from buffer . |
15,924 | public final String getString ( String charsetName ) { if ( position >= origin + limit ) throw new IllegalArgumentException ( "limit excceed: " + position ) ; byte [ ] buf = buffer ; final int len = ( 0xff & buf [ position ] ) ; if ( position + len + 1 > origin + limit ) throw new IllegalArgumentException ( "limit excceed: " + ( position + len + 1 - origin ) ) ; try { String string = new String ( buf , position + 1 , len , charsetName ) ; position += len + 1 ; return string ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Unsupported encoding: " + charsetName , e ) ; } } | Return next dynamic length string from buffer . |
15,925 | public final boolean nextOneRow ( BitSet columns , boolean after ) { final boolean hasOneRow = buffer . hasRemaining ( ) ; if ( hasOneRow ) { int column = 0 ; for ( int i = 0 ; i < columnLen ; i ++ ) if ( columns . get ( i ) ) { column ++ ; } if ( after && partial ) { partialBits . clear ( ) ; long valueOptions = buffer . getPackedLong ( ) ; int PARTIAL_JSON_UPDATES = 1 ; if ( ( valueOptions & PARTIAL_JSON_UPDATES ) != 0 ) { partialBits . set ( 1 ) ; buffer . forward ( ( jsonColumnCount + 7 ) / 8 ) ; } } nullBitIndex = 0 ; nullBits . clear ( ) ; buffer . fillBitmap ( nullBits , column ) ; } return hasOneRow ; } | Extracting next row from packed buffer . |
15,926 | static int mysqlToJavaType ( int type , final int meta , boolean isBinary ) { int javaType ; if ( type == LogEvent . MYSQL_TYPE_STRING ) { if ( meta >= 256 ) { int byte0 = meta >> 8 ; if ( ( byte0 & 0x30 ) != 0x30 ) { type = byte0 | 0x30 ; } else { switch ( byte0 ) { case LogEvent . MYSQL_TYPE_SET : case LogEvent . MYSQL_TYPE_ENUM : case LogEvent . MYSQL_TYPE_STRING : type = byte0 ; } } } } switch ( type ) { case LogEvent . MYSQL_TYPE_LONG : javaType = Types . INTEGER ; break ; case LogEvent . MYSQL_TYPE_TINY : javaType = Types . TINYINT ; break ; case LogEvent . MYSQL_TYPE_SHORT : javaType = Types . SMALLINT ; break ; case LogEvent . MYSQL_TYPE_INT24 : javaType = Types . INTEGER ; break ; case LogEvent . MYSQL_TYPE_LONGLONG : javaType = Types . BIGINT ; break ; case LogEvent . MYSQL_TYPE_DECIMAL : javaType = Types . DECIMAL ; break ; case LogEvent . MYSQL_TYPE_NEWDECIMAL : javaType = Types . DECIMAL ; break ; case LogEvent . MYSQL_TYPE_FLOAT : javaType = Types . REAL ; break ; case LogEvent . MYSQL_TYPE_DOUBLE : javaType = Types . DOUBLE ; break ; case LogEvent . MYSQL_TYPE_BIT : javaType = Types . BIT ; break ; case LogEvent . MYSQL_TYPE_TIMESTAMP : case LogEvent . MYSQL_TYPE_DATETIME : case LogEvent . MYSQL_TYPE_TIMESTAMP2 : case LogEvent . MYSQL_TYPE_DATETIME2 : javaType = Types . TIMESTAMP ; break ; case LogEvent . MYSQL_TYPE_TIME : case LogEvent . MYSQL_TYPE_TIME2 : javaType = Types . TIME ; break ; case LogEvent . MYSQL_TYPE_NEWDATE : case LogEvent . MYSQL_TYPE_DATE : javaType = Types . DATE ; break ; case LogEvent . MYSQL_TYPE_YEAR : javaType = Types . VARCHAR ; break ; case LogEvent . MYSQL_TYPE_ENUM : javaType = Types . INTEGER ; break ; case LogEvent . MYSQL_TYPE_SET : javaType = Types . BINARY ; break ; case LogEvent . MYSQL_TYPE_TINY_BLOB : case LogEvent . MYSQL_TYPE_MEDIUM_BLOB : case LogEvent . MYSQL_TYPE_LONG_BLOB : case LogEvent . MYSQL_TYPE_BLOB : if ( meta == 1 ) { javaType = Types . VARBINARY ; } else { javaType = Types . LONGVARBINARY ; } break ; case LogEvent . MYSQL_TYPE_VARCHAR : case LogEvent . MYSQL_TYPE_VAR_STRING : if ( isBinary ) { javaType = Types . VARBINARY ; } else { javaType = Types . VARCHAR ; } break ; case LogEvent . MYSQL_TYPE_STRING : if ( isBinary ) { javaType = Types . BINARY ; } else { javaType = Types . CHAR ; } break ; case LogEvent . MYSQL_TYPE_GEOMETRY : javaType = Types . BINARY ; break ; default : javaType = Types . OTHER ; } return javaType ; } | Maps the given MySQL type to the correct JDBC type . |
15,927 | protected void afterStartEventParser ( CanalEventParser eventParser ) { List < ClientIdentity > clientIdentitys = metaManager . listAllSubscribeInfo ( destination ) ; for ( ClientIdentity clientIdentity : clientIdentitys ) { subscribeChange ( clientIdentity ) ; } } | around event parser default impl |
15,928 | public long lastModified ( ) throws IOException { long lastModified = getFileForLastModifiedCheck ( ) . lastModified ( ) ; if ( lastModified == 0L ) { throw new FileNotFoundException ( getDescription ( ) + " cannot be resolved in the file system for resolving its last-modified timestamp" ) ; } return lastModified ; } | This implementation checks the timestamp of the underlying File if available . |
15,929 | public org . springframework . core . io . Resource createRelative ( String relativePath ) throws IOException { throw new FileNotFoundException ( "Cannot create a relative resource for " + getDescription ( ) ) ; } | This implementation throws a FileNotFoundException assuming that relative resources cannot be created for this resource . |
15,930 | public void setNameAliases ( Map < String , List < String > > aliases ) { this . nameAliases = new LinkedMultiValueMap < String , String > ( aliases ) ; } | Set name aliases . |
15,931 | public static long readUnsignedIntLittleEndian ( byte [ ] data , int index ) { long result = ( long ) ( data [ index ] & 0xFF ) | ( long ) ( ( data [ index + 1 ] & 0xFF ) << 8 ) | ( long ) ( ( data [ index + 2 ] & 0xFF ) << 16 ) | ( long ) ( ( data [ index + 3 ] & 0xFF ) << 24 ) ; return result ; } | Read 4 bytes in Little - endian byte order . |
15,932 | public synchronized String format ( final LogRecord record ) { buffer . setLength ( PREFIX . length ( ) ) ; buffer . append ( timestampFormatter . format ( new Date ( record . getMillis ( ) ) ) ) ; buffer . append ( ' ' ) ; buffer . append ( levelNumberToCommonsLevelName ( record . getLevel ( ) ) ) ; String [ ] parts = record . getSourceClassName ( ) . split ( "\\." ) ; buffer . append ( " [" + parts [ parts . length - 1 ] + "." + record . getSourceMethodName ( ) + "]" ) ; buffer . append ( SUFFIX ) ; buffer . append ( formatMessage ( record ) ) . append ( lineSeparator ) ; if ( record . getThrown ( ) != null ) { final StringWriter trace = new StringWriter ( ) ; record . getThrown ( ) . printStackTrace ( new PrintWriter ( trace ) ) ; buffer . append ( trace ) ; } return buffer . toString ( ) ; } | Format the given log record and return the formatted string . |
15,933 | public String getSeleniumScript ( String name ) { String rawFunction = readScript ( PREFIX + name ) ; return String . format ( "function() { return (%s).apply(null, arguments);}" , rawFunction ) ; } | Loads the named Selenium script and returns it wrapped in an anonymous function . |
15,934 | public static RegistrationRequest fromJson ( Map < String , Object > raw ) throws JsonException { Json json = new Json ( ) ; RegistrationRequest request = new RegistrationRequest ( ) ; if ( raw . get ( "name" ) instanceof String ) { request . name = ( String ) raw . get ( "name" ) ; } if ( raw . get ( "description" ) instanceof String ) { request . description = ( String ) raw . get ( "description" ) ; } if ( raw . get ( "configuration" ) instanceof Map ) { String converted = json . toJson ( raw . get ( "configuration" ) ) ; request . configuration = GridConfiguredJson . toType ( converted , GridNodeConfiguration . class ) ; } if ( raw . get ( "configuration" ) instanceof GridNodeConfiguration ) { request . configuration = ( GridNodeConfiguration ) raw . get ( "configuration" ) ; } return request ; } | Create an object from a registration request formatted as a json string . |
15,935 | public void validate ( ) throws GridConfigurationException { try { configuration . getHubHost ( ) ; configuration . getHubPort ( ) ; } catch ( RuntimeException e ) { throw new GridConfigurationException ( e . getMessage ( ) ) ; } } | Validate the current setting and throw a config exception is an invalid setup is detected . |
15,936 | public void forwardNewSessionRequestAndUpdateRegistry ( TestSession session ) throws NewSessionException { try ( NewSessionPayload payload = NewSessionPayload . create ( ImmutableMap . of ( "desiredCapabilities" , session . getRequestedCapabilities ( ) ) ) ) { StringBuilder json = new StringBuilder ( ) ; payload . writeTo ( json ) ; request . setBody ( json . toString ( ) ) ; session . forward ( getRequest ( ) , getResponse ( ) , true ) ; } catch ( IOException e ) { throw new NewSessionException ( "Error forwarding the request " + e . getMessage ( ) , e ) ; } } | Forward the new session request to the TestSession that has been assigned and parse the response to extract and return the external key assigned by the remote . |
15,937 | private void beforeSessionEvent ( ) throws NewSessionException { RemoteProxy p = session . getSlot ( ) . getProxy ( ) ; if ( p instanceof TestSessionListener ) { try { ( ( TestSessionListener ) p ) . beforeSession ( session ) ; } catch ( Exception e ) { log . severe ( "Error running the beforeSessionListener : " + e . getMessage ( ) ) ; e . printStackTrace ( ) ; throw new NewSessionException ( "The listener threw an exception ( listener bug )" , e ) ; } } } | calls the TestSessionListener is the proxy for that node has one specified . |
15,938 | public void waitForSessionBound ( ) throws InterruptedException , TimeoutException { GridHubConfiguration configuration = getRegistry ( ) . getHub ( ) . getConfiguration ( ) ; Integer newSessionWaitTimeout = configuration . newSessionWaitTimeout != null ? configuration . newSessionWaitTimeout : 0 ; if ( newSessionWaitTimeout > 0 ) { if ( ! sessionAssigned . await ( newSessionWaitTimeout . longValue ( ) , TimeUnit . MILLISECONDS ) ) { throw new TimeoutException ( "Request timed out waiting for a node to become available." ) ; } } else { sessionAssigned . await ( ) ; } } | wait for the registry to match the request with a TestSlot . |
15,939 | public static ExpectedCondition < Boolean > titleIs ( final String title ) { return new ExpectedCondition < Boolean > ( ) { private String currentTitle = "" ; public Boolean apply ( WebDriver driver ) { currentTitle = driver . getTitle ( ) ; return title . equals ( currentTitle ) ; } public String toString ( ) { return String . format ( "title to be \"%s\". Current title: \"%s\"" , title , currentTitle ) ; } } ; } | An expectation for checking the title of a page . |
15,940 | public static ExpectedCondition < Boolean > titleContains ( final String title ) { return new ExpectedCondition < Boolean > ( ) { private String currentTitle = "" ; public Boolean apply ( WebDriver driver ) { currentTitle = driver . getTitle ( ) ; return currentTitle != null && currentTitle . contains ( title ) ; } public String toString ( ) { return String . format ( "title to contain \"%s\". Current title: \"%s\"" , title , currentTitle ) ; } } ; } | An expectation for checking that the title contains a case - sensitive substring |
15,941 | public static ExpectedCondition < Boolean > urlToBe ( final String url ) { return new ExpectedCondition < Boolean > ( ) { private String currentUrl = "" ; public Boolean apply ( WebDriver driver ) { currentUrl = driver . getCurrentUrl ( ) ; return currentUrl != null && currentUrl . equals ( url ) ; } public String toString ( ) { return String . format ( "url to be \"%s\". Current url: \"%s\"" , url , currentUrl ) ; } } ; } | An expectation for the URL of the current page to be a specific url . |
15,942 | public static ExpectedCondition < Boolean > urlContains ( final String fraction ) { return new ExpectedCondition < Boolean > ( ) { private String currentUrl = "" ; public Boolean apply ( WebDriver driver ) { currentUrl = driver . getCurrentUrl ( ) ; return currentUrl != null && currentUrl . contains ( fraction ) ; } public String toString ( ) { return String . format ( "url to contain \"%s\". Current url: \"%s\"" , fraction , currentUrl ) ; } } ; } | An expectation for the URL of the current page to contain specific text . |
15,943 | public static ExpectedCondition < Boolean > urlMatches ( final String regex ) { return new ExpectedCondition < Boolean > ( ) { private String currentUrl ; private Pattern pattern ; private Matcher matcher ; public Boolean apply ( WebDriver driver ) { currentUrl = driver . getCurrentUrl ( ) ; pattern = Pattern . compile ( regex ) ; matcher = pattern . matcher ( currentUrl ) ; return matcher . find ( ) ; } public String toString ( ) { return String . format ( "url to match the regex \"%s\". Current url: \"%s\"" , regex , currentUrl ) ; } } ; } | Expectation for the URL to match a specific regular expression |
15,944 | public static ExpectedCondition < WebElement > presenceOfElementLocated ( final By locator ) { return new ExpectedCondition < WebElement > ( ) { public WebElement apply ( WebDriver driver ) { return driver . findElement ( locator ) ; } public String toString ( ) { return "presence of element located by: " + locator ; } } ; } | An expectation for checking that an element is present on the DOM of a page . This does not necessarily mean that the element is visible . |
15,945 | public static ExpectedCondition < WebElement > visibilityOfElementLocated ( final By locator ) { return new ExpectedCondition < WebElement > ( ) { public WebElement apply ( WebDriver driver ) { try { return elementIfVisible ( driver . findElement ( locator ) ) ; } catch ( StaleElementReferenceException e ) { return null ; } } public String toString ( ) { return "visibility of element located by " + locator ; } } ; } | An expectation for checking that an element is present on the DOM of a page and visible . Visibility means that the element is not only displayed but also has a height and width that is greater than 0 . |
15,946 | public static ExpectedCondition < WebElement > visibilityOf ( final WebElement element ) { return new ExpectedCondition < WebElement > ( ) { public WebElement apply ( WebDriver driver ) { return elementIfVisible ( element ) ; } public String toString ( ) { return "visibility of " + element ; } } ; } | An expectation for checking that an element known to be present on the DOM of a page is visible . Visibility means that the element is not only displayed but also has a height and width that is greater than 0 . |
15,947 | public static ExpectedCondition < List < WebElement > > presenceOfAllElementsLocatedBy ( final By locator ) { return new ExpectedCondition < List < WebElement > > ( ) { public List < WebElement > apply ( WebDriver driver ) { List < WebElement > elements = driver . findElements ( locator ) ; return elements . size ( ) > 0 ? elements : null ; } public String toString ( ) { return "presence of any elements located by " + locator ; } } ; } | An expectation for checking that there is at least one element present on a web page . |
15,948 | public static ExpectedCondition < Boolean > textToBePresentInElement ( final WebElement element , final String text ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { try { String elementText = element . getText ( ) ; return elementText . contains ( text ) ; } catch ( StaleElementReferenceException e ) { return null ; } } public String toString ( ) { return String . format ( "text ('%s') to be present in element %s" , text , element ) ; } } ; } | An expectation for checking if the given text is present in the specified element . |
15,949 | public static ExpectedCondition < Boolean > textToBePresentInElementLocated ( final By locator , final String text ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { try { String elementText = driver . findElement ( locator ) . getText ( ) ; return elementText . contains ( text ) ; } catch ( StaleElementReferenceException e ) { return null ; } } public String toString ( ) { return String . format ( "text ('%s') to be present in element found by %s" , text , locator ) ; } } ; } | An expectation for checking if the given text is present in the element that matches the given locator . |
15,950 | public static ExpectedCondition < Boolean > invisibilityOfElementLocated ( final By locator ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { try { return ! ( driver . findElement ( locator ) . isDisplayed ( ) ) ; } catch ( NoSuchElementException e ) { return true ; } catch ( StaleElementReferenceException e ) { return true ; } } public String toString ( ) { return "element to no longer be visible: " + locator ; } } ; } | An expectation for checking that an element is either invisible or not present on the DOM . |
15,951 | public static ExpectedCondition < Boolean > invisibilityOfElementWithText ( final By locator , final String text ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { try { return ! driver . findElement ( locator ) . getText ( ) . equals ( text ) ; } catch ( NoSuchElementException e ) { return true ; } catch ( StaleElementReferenceException e ) { return true ; } } public String toString ( ) { return String . format ( "element containing '%s' to no longer be visible: %s" , text , locator ) ; } } ; } | An expectation for checking that an element with text is either invisible or not present on the DOM . |
15,952 | public static ExpectedCondition < Boolean > stalenessOf ( final WebElement element ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver ignored ) { try { element . isEnabled ( ) ; return false ; } catch ( StaleElementReferenceException expected ) { return true ; } } public String toString ( ) { return String . format ( "element (%s) to become stale" , element ) ; } } ; } | Wait until an element is no longer attached to the DOM . |
15,953 | public static < T > ExpectedCondition < T > refreshed ( final ExpectedCondition < T > condition ) { return new ExpectedCondition < T > ( ) { public T apply ( WebDriver driver ) { try { return condition . apply ( driver ) ; } catch ( StaleElementReferenceException e ) { return null ; } } public String toString ( ) { return String . format ( "condition (%s) to be refreshed" , condition ) ; } } ; } | Wrapper for a condition which allows for elements to update by redrawing . |
15,954 | public static ExpectedCondition < Boolean > elementSelectionStateToBe ( final WebElement element , final boolean selected ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { return element . isSelected ( ) == selected ; } public String toString ( ) { return String . format ( "element (%s) to %sbe selected" , element , ( selected ? "" : "not " ) ) ; } } ; } | An expectation for checking if the given element is selected . |
15,955 | public static ExpectedCondition < Boolean > not ( final ExpectedCondition < ? > condition ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { Object result = condition . apply ( driver ) ; return result == null || result . equals ( Boolean . FALSE ) ; } public String toString ( ) { return "condition to not be valid: " + condition ; } } ; } | An expectation with the logical opposite condition of the given condition . |
15,956 | public static ExpectedCondition < Boolean > attributeToBe ( final By locator , final String attribute , final String value ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; public Boolean apply ( WebDriver driver ) { WebElement element = driver . findElement ( locator ) ; currentValue = element . getAttribute ( attribute ) ; if ( currentValue == null || currentValue . isEmpty ( ) ) { currentValue = element . getCssValue ( attribute ) ; } return value . equals ( currentValue ) ; } public String toString ( ) { return String . format ( "element found by %s to have value \"%s\". Current value: \"%s\"" , locator , value , currentValue ) ; } } ; } | An expectation for checking WebElement with given locator has attribute with a specific value |
15,957 | public static ExpectedCondition < Boolean > textToBe ( final By locator , final String value ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; public Boolean apply ( WebDriver driver ) { try { currentValue = driver . findElement ( locator ) . getText ( ) ; return currentValue . equals ( value ) ; } catch ( Exception e ) { return false ; } } public String toString ( ) { return String . format ( "element found by %s to have text \"%s\". Current text: \"%s\"" , locator , value , currentValue ) ; } } ; } | An expectation for checking WebElement with given locator has specific text |
15,958 | public static ExpectedCondition < Boolean > textMatches ( final By locator , final Pattern pattern ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; public Boolean apply ( WebDriver driver ) { try { currentValue = driver . findElement ( locator ) . getText ( ) ; return pattern . matcher ( currentValue ) . find ( ) ; } catch ( Exception e ) { return false ; } } public String toString ( ) { return String . format ( "text found by %s to match pattern \"%s\". Current text: \"%s\"" , locator , pattern . pattern ( ) , currentValue ) ; } } ; } | An expectation for checking WebElement with given locator has text with a value as a part of it |
15,959 | public static ExpectedCondition < List < WebElement > > numberOfElementsToBeMoreThan ( final By locator , final Integer number ) { return new ExpectedCondition < List < WebElement > > ( ) { private Integer currentNumber = 0 ; public List < WebElement > apply ( WebDriver webDriver ) { List < WebElement > elements = webDriver . findElements ( locator ) ; currentNumber = elements . size ( ) ; return currentNumber > number ? elements : null ; } public String toString ( ) { return String . format ( "number of elements found by %s to be more than \"%s\". Current number: \"%s\"" , locator , number , currentNumber ) ; } } ; } | An expectation for checking number of WebElements with given locator being more than defined number |
15,960 | public static ExpectedCondition < Boolean > attributeContains ( final WebElement element , final String attribute , final String value ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; public Boolean apply ( WebDriver driver ) { return getAttributeOrCssValue ( element , attribute ) . map ( seen -> seen . contains ( value ) ) . orElse ( false ) ; } public String toString ( ) { return String . format ( "value to contain \"%s\". Current value: \"%s\"" , value , currentValue ) ; } } ; } | An expectation for checking WebElement with given locator has attribute which contains specific value |
15,961 | public static ExpectedCondition < Boolean > attributeToBeNotEmpty ( final WebElement element , final String attribute ) { return driver -> getAttributeOrCssValue ( element , attribute ) . isPresent ( ) ; } | An expectation for checking WebElement any non empty value for given attribute |
15,962 | public static ExpectedCondition < WebElement > presenceOfNestedElementLocatedBy ( final WebElement element , final By childLocator ) { return new ExpectedCondition < WebElement > ( ) { public WebElement apply ( WebDriver webDriver ) { return element . findElement ( childLocator ) ; } public String toString ( ) { return String . format ( "visibility of element located by %s" , childLocator ) ; } } ; } | An expectation for checking child WebElement as a part of parent element to be present |
15,963 | public static ExpectedCondition < Boolean > invisibilityOfAllElements ( final List < WebElement > elements ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver webDriver ) { return elements . stream ( ) . allMatch ( ExpectedConditions :: isInvisible ) ; } public String toString ( ) { return "invisibility of all elements " + elements ; } } ; } | An expectation for checking all elements from given list to be invisible |
15,964 | public static ExpectedCondition < Boolean > invisibilityOf ( final WebElement element ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver webDriver ) { return isInvisible ( element ) ; } public String toString ( ) { return "invisibility of " + element ; } } ; } | An expectation for checking the element to be invisible |
15,965 | public static ExpectedCondition < Boolean > or ( final ExpectedCondition < ? > ... conditions ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { RuntimeException lastException = null ; for ( ExpectedCondition < ? > condition : conditions ) { try { Object result = condition . apply ( driver ) ; if ( result != null ) { if ( result instanceof Boolean ) { if ( Boolean . TRUE . equals ( result ) ) { return true ; } } else { return true ; } } } catch ( RuntimeException e ) { lastException = e ; } } if ( lastException != null ) { throw lastException ; } return false ; } public String toString ( ) { StringBuilder message = new StringBuilder ( "at least one condition to be valid: " ) ; Joiner . on ( " || " ) . appendTo ( message , conditions ) ; return message . toString ( ) ; } } ; } | An expectation with the logical or condition of the given list of conditions . |
15,966 | public static ExpectedCondition < Boolean > and ( final ExpectedCondition < ? > ... conditions ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { for ( ExpectedCondition < ? > condition : conditions ) { Object result = condition . apply ( driver ) ; if ( result instanceof Boolean ) { if ( Boolean . FALSE . equals ( result ) ) { return false ; } } if ( result == null ) { return false ; } } return true ; } public String toString ( ) { StringBuilder message = new StringBuilder ( "all conditions to be valid: " ) ; Joiner . on ( " && " ) . appendTo ( message , conditions ) ; return message . toString ( ) ; } } ; } | An expectation with the logical and condition of the given list of conditions . |
15,967 | public static ExpectedCondition < Boolean > javaScriptThrowsNoExceptions ( final String javaScript ) { return new ExpectedCondition < Boolean > ( ) { public Boolean apply ( WebDriver driver ) { try { ( ( JavascriptExecutor ) driver ) . executeScript ( javaScript ) ; return true ; } catch ( WebDriverException e ) { return false ; } } public String toString ( ) { return String . format ( "js %s to be executable" , javaScript ) ; } } ; } | An expectation to check if js executable . |
15,968 | public static ExpectedCondition < Object > jsReturnsValue ( final String javaScript ) { return new ExpectedCondition < Object > ( ) { public Object apply ( WebDriver driver ) { try { Object value = ( ( JavascriptExecutor ) driver ) . executeScript ( javaScript ) ; if ( value instanceof List ) { return ( ( List < ? > ) value ) . isEmpty ( ) ? null : value ; } if ( value instanceof String ) { return ( ( String ) value ) . isEmpty ( ) ? null : value ; } return value ; } catch ( WebDriverException e ) { return null ; } } public String toString ( ) { return String . format ( "js %s to be executable" , javaScript ) ; } } ; } | An expectation for String value from javascript |
15,969 | public Map < String , String > getAlert ( ) { HashMap < String , String > toReturn = new HashMap < > ( ) ; toReturn . put ( "text" , getAlertText ( ) ) ; return Collections . unmodifiableMap ( toReturn ) ; } | Used for serialising . Some of the drivers return the alert text like this . |
15,970 | @ SuppressWarnings ( "JavaDoc" ) public static String escape ( String toEscape ) { if ( toEscape . contains ( "\"" ) && toEscape . contains ( "'" ) ) { boolean quoteIsLast = false ; if ( toEscape . lastIndexOf ( "\"" ) == toEscape . length ( ) - 1 ) { quoteIsLast = true ; } String [ ] substringsWithoutQuotes = toEscape . split ( "\"" ) ; StringBuilder quoted = new StringBuilder ( "concat(" ) ; for ( int i = 0 ; i < substringsWithoutQuotes . length ; i ++ ) { quoted . append ( "\"" ) . append ( substringsWithoutQuotes [ i ] ) . append ( "\"" ) ; quoted . append ( ( ( i == substringsWithoutQuotes . length - 1 ) ? ( quoteIsLast ? ", '\"')" : ")" ) : ", '\"', " ) ) ; } return quoted . toString ( ) ; } if ( toEscape . contains ( "\"" ) ) { return String . format ( "'%s'" , toEscape ) ; } return String . format ( "\"%s\"" , toEscape ) ; } | Convert strings with both quotes and ticks into a valid xpath component |
15,971 | @ SuppressWarnings ( "unchecked" ) public static < T extends RemoteProxy > T getNewInstance ( RegistrationRequest request , GridRegistry registry ) { try { String proxyClass = request . getConfiguration ( ) . proxy ; if ( proxyClass == null ) { log . fine ( "No proxy class. Using default" ) ; proxyClass = BaseRemoteProxy . class . getCanonicalName ( ) ; } Class < ? > clazz = Class . forName ( proxyClass ) ; log . fine ( "Using class " + clazz . getName ( ) ) ; Object [ ] args = new Object [ ] { request , registry } ; Class < ? > [ ] argsClass = new Class [ ] { RegistrationRequest . class , GridRegistry . class } ; Constructor < ? > c = clazz . getConstructor ( argsClass ) ; Object proxy = c . newInstance ( args ) ; if ( proxy instanceof RemoteProxy ) { ( ( RemoteProxy ) proxy ) . setupTimeoutListener ( ) ; return ( T ) proxy ; } throw new InvalidParameterException ( "Error: " + proxy . getClass ( ) + " isn't a remote proxy" ) ; } catch ( InvocationTargetException e ) { throw new InvalidParameterException ( "Error: " + e . getTargetException ( ) . getMessage ( ) ) ; } catch ( Exception e ) { throw new InvalidParameterException ( "Error: " + e . getMessage ( ) ) ; } } | Takes a registration request and return the RemoteProxy associated to it . It can be any class extending RemoteProxy . |
15,972 | public RemoteProxy remove ( RemoteProxy proxy ) { for ( RemoteProxy p : proxies ) { if ( p . equals ( proxy ) ) { proxies . remove ( p ) ; return p ; } } throw new IllegalStateException ( "Did not contain proxy" + proxy ) ; } | Removes the specified instance from the proxySet |
15,973 | public RemoteWebDriverBuilder oneOf ( Capabilities maybeThis , Capabilities ... orOneOfThese ) { options . clear ( ) ; addAlternative ( maybeThis ) ; for ( Capabilities anOrOneOfThese : orOneOfThese ) { addAlternative ( anOrOneOfThese ) ; } return this ; } | Clears the current set of alternative browsers and instead sets the list of possible choices to the arguments given to this method . |
15,974 | public RemoteWebDriverBuilder addAlternative ( Capabilities options ) { Map < String , Object > serialized = validate ( Objects . requireNonNull ( options ) ) ; this . options . add ( serialized ) ; return this ; } | Add to the list of possible configurations that might be asked for . It is possible to ask for more than one type of browser per session . For example perhaps you have an extension that is available for two different kinds of browser and you d like to test it ) . |
15,975 | public String runHTMLSuite ( String browser , String startURL , String suiteURL , File outputFile , long timeoutInSeconds , String userExtensions ) throws IOException { File parent = outputFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } if ( outputFile . exists ( ) && ! outputFile . canWrite ( ) ) { throw new IOException ( "Can't write to outputFile: " + outputFile . getAbsolutePath ( ) ) ; } long timeoutInMs = 1000L * timeoutInSeconds ; if ( timeoutInMs < 0 ) { log . warning ( "Looks like the timeout overflowed, so resetting it to the maximum." ) ; timeoutInMs = Long . MAX_VALUE ; } WebDriver driver = null ; try { driver = createDriver ( browser ) ; URL suiteUrl = determineSuiteUrl ( startURL , suiteURL ) ; driver . get ( suiteUrl . toString ( ) ) ; Selenium selenium = new WebDriverBackedSelenium ( driver , startURL ) ; selenium . setTimeout ( String . valueOf ( timeoutInMs ) ) ; if ( userExtensions != null ) { selenium . setExtensionJs ( userExtensions ) ; } List < WebElement > allTables = driver . findElements ( By . id ( "suiteTable" ) ) ; if ( allTables . isEmpty ( ) ) { throw new RuntimeException ( "Unable to find suite table: " + driver . getPageSource ( ) ) ; } Results results = new CoreTestSuite ( suiteUrl . toString ( ) ) . run ( driver , selenium , new URL ( startURL ) ) ; HTMLTestResults htmlResults = results . toSuiteResult ( ) ; try ( Writer writer = Files . newBufferedWriter ( outputFile . toPath ( ) ) ) { htmlResults . write ( writer ) ; } return results . isSuccessful ( ) ? "PASSED" : "FAILED" ; } finally { if ( server != null ) { try { server . stop ( ) ; } catch ( Exception e ) { log . log ( Level . INFO , "Exception shutting down server. You may ignore this." , e ) ; } } if ( driver != null ) { driver . quit ( ) ; } } } | Launches a single HTML Selenium test suite . |
15,976 | public String newWindow ( WindowType type ) { Response response = execute ( "SAFARI_NEW_WINDOW" , ImmutableMap . of ( "newTab" , type == WindowType . TAB ) ) ; return ( String ) response . getValue ( ) ; } | Open either a new tab or window depending on what is requested and return the window handle without switching to it . |
15,977 | private String getConsoleIconPath ( DesiredCapabilities cap ) { String name = consoleIconName ( cap ) ; String path = "org/openqa/grid/images/" ; InputStream in = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( path + name + ".png" ) ; if ( in == null ) { return null ; } return "/grid/resources/" + path + name + ".png" ; } | get the icon representing the browser for the grid . If the icon cannot be located returns null . |
15,978 | private String getConfigInfo ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<div id='hub-config-container'>" ) ; GridHubConfiguration config = getRegistry ( ) . getHub ( ) . getConfiguration ( ) ; builder . append ( "<div id='hub-config-content'>" ) ; builder . append ( "<b>Config for the hub :</b><br/>" ) ; builder . append ( prettyHtmlPrint ( config ) ) ; builder . append ( getVerboseConfig ( ) ) ; builder . append ( "</div>" ) ; builder . append ( "<a id='config-view-toggle' href='#'>View Config</a>" ) ; builder . append ( "</div>" ) ; return builder . toString ( ) ; } | retracing how the hub config was built to help debugging . |
15,979 | private String getVerboseConfig ( ) { StringBuilder builder = new StringBuilder ( ) ; GridHubConfiguration config = getRegistry ( ) . getHub ( ) . getConfiguration ( ) ; builder . append ( "<div id='verbose-config-container'>" ) ; builder . append ( "<a id='verbose-config-view-toggle' href='#'>View Verbose</a>" ) ; builder . append ( "<div id='verbose-config-content'>" ) ; GridHubConfiguration tmp = new GridHubConfiguration ( ) ; builder . append ( "<br/><b>The final configuration comes from:</b><br/>" ) ; builder . append ( "<b>the default :</b><br/>" ) ; builder . append ( prettyHtmlPrint ( tmp ) ) ; if ( config . getRawArgs ( ) != null ) { builder . append ( "<b>updated with command line options:</b><br/>" ) ; builder . append ( String . join ( " " , config . getRawArgs ( ) ) ) ; if ( config . getConfigFile ( ) != null ) { builder . append ( "<br/><b>and configuration loaded from " ) . append ( config . getConfigFile ( ) ) . append ( ":</b><br/>" ) ; try { builder . append ( String . join ( "<br/>" , Files . readAllLines ( new File ( config . getConfigFile ( ) ) . toPath ( ) ) ) ) ; } catch ( IOException e ) { builder . append ( "<b>" ) . append ( e . getMessage ( ) ) . append ( "</b>" ) ; } } } builder . append ( "</div>" ) ; builder . append ( "</div>" ) ; return builder . toString ( ) ; } | Displays more detailed configuration |
15,980 | public TestSession getNewSession ( Map < String , Object > requestedCapability ) { if ( down ) { return null ; } return super . getNewSession ( requestedCapability ) ; } | overwrites the session allocation to discard the proxy that are down . |
15,981 | public HttpResponse encode ( Supplier < HttpResponse > factory , Response response ) { int status = response . getStatus ( ) == ErrorCodes . SUCCESS ? HTTP_OK : HTTP_INTERNAL_ERROR ; byte [ ] data = json . toJson ( getValueToEncode ( response ) ) . getBytes ( UTF_8 ) ; HttpResponse httpResponse = factory . get ( ) ; httpResponse . setStatus ( status ) ; httpResponse . setHeader ( CACHE_CONTROL , "no-cache" ) ; httpResponse . setHeader ( EXPIRES , "Thu, 01 Jan 1970 00:00:00 GMT" ) ; httpResponse . setHeader ( CONTENT_LENGTH , String . valueOf ( data . length ) ) ; httpResponse . setHeader ( CONTENT_TYPE , JSON_UTF_8 . toString ( ) ) ; httpResponse . setContent ( data ) ; return httpResponse ; } | Encodes the given response as a HTTP response message . This method is guaranteed not to throw . |
15,982 | public PropertySetting propertySetting ( PropertySetting setter ) { PropertySetting previous = this . setter ; this . setter = Objects . requireNonNull ( setter ) ; return previous ; } | Change how property setting is done . It s polite to set the value back once done processing . |
15,983 | public Actions keyUp ( CharSequence key ) { if ( isBuildingActions ( ) ) { action . addAction ( new KeyUpAction ( jsonKeyboard , jsonMouse , asKeys ( key ) ) ) ; } return addKeyAction ( key , codePoint -> tick ( defaultKeyboard . createKeyUp ( codePoint ) ) ) ; } | Performs a modifier key release . Releasing a non - depressed modifier key will yield undefined behaviour . |
15,984 | public Actions release ( ) { if ( isBuildingActions ( ) ) { action . addAction ( new ButtonReleaseAction ( jsonMouse , null ) ) ; } return tick ( defaultMouse . createPointerUp ( Button . LEFT . asArg ( ) ) ) ; } | Releases the depressed left mouse button at the current mouse location . |
15,985 | public Actions doubleClick ( ) { if ( isBuildingActions ( ) ) { action . addAction ( new DoubleClickAction ( jsonMouse , null ) ) ; } return clickInTicks ( LEFT ) . clickInTicks ( LEFT ) ; } | Performs a double - click at the current mouse location . |
15,986 | public Actions moveToElement ( WebElement target ) { if ( isBuildingActions ( ) ) { action . addAction ( new MoveMouseAction ( jsonMouse , ( Locatable ) target ) ) ; } return moveInTicks ( target , 0 , 0 ) ; } | Moves the mouse to the middle of the element . The element is scrolled into view and its location is calculated using getBoundingClientRect . |
15,987 | public Actions moveToElement ( WebElement target , int xOffset , int yOffset ) { if ( isBuildingActions ( ) ) { action . addAction ( new MoveToOffsetAction ( jsonMouse , ( Locatable ) target , xOffset , yOffset ) ) ; } LOG . info ( "When using the W3C Action commands, offsets are from the center of element" ) ; return moveInTicks ( target , xOffset , yOffset ) ; } | Moves the mouse to an offset from the top - left corner of the element . The element is scrolled into view and its location is calculated using getBoundingClientRect . |
15,988 | public Actions contextClick ( WebElement target ) { if ( isBuildingActions ( ) ) { action . addAction ( new ContextClickAction ( jsonMouse , ( Locatable ) target ) ) ; } return moveInTicks ( target , 0 , 0 ) . clickInTicks ( RIGHT ) ; } | Performs a context - click at middle of the given element . First performs a mouseMove to the location of the element . |
15,989 | public Actions contextClick ( ) { if ( isBuildingActions ( ) ) { action . addAction ( new ContextClickAction ( jsonMouse , null ) ) ; } return clickInTicks ( RIGHT ) ; } | Performs a context - click at the current mouse location . |
15,990 | public Actions dragAndDrop ( WebElement source , WebElement target ) { if ( isBuildingActions ( ) ) { action . addAction ( new ClickAndHoldAction ( jsonMouse , ( Locatable ) source ) ) ; action . addAction ( new MoveMouseAction ( jsonMouse , ( Locatable ) target ) ) ; action . addAction ( new ButtonReleaseAction ( jsonMouse , ( Locatable ) target ) ) ; } return moveInTicks ( source , 0 , 0 ) . tick ( defaultMouse . createPointerDown ( LEFT . asArg ( ) ) ) . moveInTicks ( target , 0 , 0 ) . tick ( defaultMouse . createPointerUp ( LEFT . asArg ( ) ) ) ; } | A convenience method that performs click - and - hold at the location of the source element moves to the location of the target element then releases the mouse . |
15,991 | public Actions dragAndDropBy ( WebElement source , int xOffset , int yOffset ) { if ( isBuildingActions ( ) ) { action . addAction ( new ClickAndHoldAction ( jsonMouse , ( Locatable ) source ) ) ; action . addAction ( new MoveToOffsetAction ( jsonMouse , null , xOffset , yOffset ) ) ; action . addAction ( new ButtonReleaseAction ( jsonMouse , null ) ) ; } return moveInTicks ( source , 0 , 0 ) . tick ( defaultMouse . createPointerDown ( LEFT . asArg ( ) ) ) . tick ( defaultMouse . createPointerMove ( Duration . ofMillis ( 250 ) , Origin . pointer ( ) , xOffset , yOffset ) ) . tick ( defaultMouse . createPointerUp ( LEFT . asArg ( ) ) ) ; } | A convenience method that performs click - and - hold at the location of the source element moves by a given offset then releases the mouse . |
15,992 | public Actions pause ( long pause ) { if ( isBuildingActions ( ) ) { action . addAction ( new PauseAction ( pause ) ) ; } return tick ( new Pause ( defaultMouse , Duration . ofMillis ( pause ) ) ) ; } | Performs a pause . |
15,993 | public void wait ( String message , long timeoutInMilliseconds , long intervalInMilliseconds ) { long start = System . currentTimeMillis ( ) ; long end = start + timeoutInMilliseconds ; while ( System . currentTimeMillis ( ) < end ) { if ( until ( ) ) return ; try { Thread . sleep ( intervalInMilliseconds ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( e ) ; } } throw new WaitTimedOutException ( message ) ; } | Wait until the until condition returns true or time runs out . |
15,994 | public String getQueryParameter ( String name ) { Iterable < String > allParams = getQueryParameters ( name ) ; if ( allParams == null ) { return null ; } Iterator < String > iterator = allParams . iterator ( ) ; return iterator . hasNext ( ) ? iterator . next ( ) : null ; } | Get a query parameter . The implementation will take care of decoding from the percent encoding . |
15,995 | public HttpRequest addQueryParameter ( String name , String value ) { queryParameters . put ( Objects . requireNonNull ( name , "Name must be set" ) , Objects . requireNonNull ( value , "Value must be set" ) ) ; return this ; } | Set a query parameter adding to existing values if present . The implementation will ensure that the name and value are properly encoded . |
15,996 | public CrossDomainRpc loadRpc ( HttpServletRequest request ) throws IOException { Charset encoding ; try { String enc = request . getCharacterEncoding ( ) ; encoding = Charset . forName ( enc ) ; } catch ( IllegalArgumentException | NullPointerException e ) { encoding = UTF_8 ; } try ( InputStream in = request . getInputStream ( ) ; Reader reader = new InputStreamReader ( in , encoding ) ; JsonInput jsonInput = json . newInput ( reader ) ) { Map < String , Object > read = jsonInput . read ( MAP_TYPE ) ; return new CrossDomainRpc ( getField ( read , Field . METHOD ) , getField ( read , Field . PATH ) , getField ( read , Field . DATA ) ) ; } catch ( JsonException e ) { throw new IllegalArgumentException ( "Failed to parse JSON request: " + e . getMessage ( ) , e ) ; } } | Parses the request for a CrossDomainRpc . |
15,997 | private static Capabilities dropCapabilities ( Capabilities capabilities ) { if ( capabilities == null ) { return new ImmutableCapabilities ( ) ; } MutableCapabilities caps ; if ( isLegacy ( capabilities ) ) { final Set < String > toRemove = Sets . newHashSet ( BINARY , PROFILE ) ; caps = new MutableCapabilities ( Maps . filterKeys ( capabilities . asMap ( ) , key -> ! toRemove . contains ( key ) ) ) ; } else { caps = new MutableCapabilities ( capabilities ) ; } Proxy proxy = Proxy . extractFrom ( capabilities ) ; if ( proxy != null ) { caps . setCapability ( PROXY , proxy ) ; } return caps ; } | Drops capabilities that we shouldn t send over the wire . |
15,998 | public File createTempDir ( String prefix , String suffix ) { try { File file = File . createTempFile ( prefix , suffix , baseDir ) ; file . delete ( ) ; File dir = new File ( file . getAbsolutePath ( ) ) ; if ( ! dir . mkdirs ( ) ) { throw new WebDriverException ( "Cannot create profile directory at " + dir . getAbsolutePath ( ) ) ; } FileHandler . createDir ( dir ) ; temporaryFiles . add ( dir ) ; return dir ; } catch ( IOException e ) { throw new WebDriverException ( "Unable to create temporary file at " + baseDir . getAbsolutePath ( ) ) ; } } | Create a temporary directory and track it for deletion . |
15,999 | public void deleteTempDir ( File file ) { if ( ! shouldReap ( ) ) { return ; } if ( temporaryFiles . remove ( file ) ) { FileHandler . delete ( file ) ; } } | Delete a temporary directory that we were responsible for creating . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.