[![enter image description here][1]][1]
in image the numbering is not in sequence order, I need to verify if no are in sequence 1, 2, 3 , 4 then test case pass else fail.
Social Networking URL #1:
text box
Social Networking URL #2:
text box
Social Networking URL #1:
textbox
Social Networking URL #1:
text box
To verify Numbering should go 1,2,3,4
please help, they are not allowing me to attach image for more clearance
You can get the all elements by driver.find_elements_by_css_selector(css_selector) with the given css_selector then you can get it text by .text finally check if the number is increasing sequencially:
Python:
def check_if_sequencial(css_selector):
result = True
elms = driver.find_elements_by_css_selector(css_selector)
for i in xrange(len(elms) - 1):
text1 = elms[i].text
text2 = elms[i+1].text
# slicing after dash to end of string, convert to int
number1 = int(text1[text1.index("#")+1 : len(text1)])
number2 = int(text1[text2.index("#")+1 : len(text2)])
if number2 != number1 + 1:
print "number1: %d and number2: %d are not sequencial" %(number1, number2)
result = False
break
return result
Java:
public boolean check_if_sequencial(String css_selector){
boolean result = true;
List elms = driver.findElements(By.cssSelector(css_selector));
for (int i = 0; i < elms.length - 1; i++) {
String text1 = elms[i].text;
String text2 = elms[i+1].text;
# spliting by dash take the second, convert to int
String[] parts1 = text1.split("#");
int number1 = Integer.parseInt(parts1[1]);
String[] parts2 = text2.split("#");
int number2 = Integer.parseInt(parts2[1]);
if (number2 != number1 + 1){
System.out.println("number1: " + number1 + " and number2: " + number2 + " are not sequencial");
result = false;
break;
}
}
return result;
}
Related
I am unable to select an item if there is only 1 result showing(see image 1). If there are 2 results, desired item can be selected(see image 2). It just proceeds to the next scenario which inputs the date. it inputs the dates in the search bar instead of the date field. but works perfectly when there are 2 results.
Image 1
image 1
Image 2
image 2
Here is my code:
java.util.List<WebElement> substituterlist = getDriver.findElements(By.xpath("//*[#id='select2-drop']/ul/li"));
int list = substituterlist.size();
for (int i = 1; i <= list; i++) {
WebElement subUser = getDriver.findElement(By.xpath("//*[#id='select2-drop']/ul/li[" + i + "]/div"));
String subUsername = subUser.getText();
System.out.println(subUsername.indexOf("-"));
String selectUsr = subUsername.substring(0, subUsername.indexOf("-") - 1);
if (substituteUser.equals(selectUsr)) {
waitForMoreTime(10);
subUser.click();
I am trying to remove a String at a certain index in my list of Strings however I can't seem to invoke the list.remove() method in groovy.
public List getCassetteTypes(socket, numOfSlots){
//get the cassettes layout
sendCommand(socket, 'syst:layout? ')
String systLayoutStr = readCommand(socket)
//this String looks like: '1 ABC, 2 DEF, 3 SPN, ....'
List listOfCassetteTypes = new ArrayList<String>()
//I split the String at ',' because for each cassetteName, I want to remove the number before it
listOfCassetteTypes = systLayoutStr.split(',')
for(int i = 0; i < numOfSlots; i++){
//remove any white spaces
listOfCassetteTypes[i] = listOfCassetteTypes[i].trim()
//remove the numerical value
listOfCassetteTypes[i] = listOfCassetteTypes[i].replace((i + 1) + ' ', '')
/* if the cassette name is 'SPN',
I want to remove it and append '-EXT' to the cassetteName before it,
because 'SPN' means the previous slot is extended,
'SPN' itself isn't a cassette */
if(listOfCassetteTypes[i].equalsIgnoreCase('spn')){
listOfCassetteTypes[i - 1] = listOfCassetteTypes[i - 1].concat('-EXT')
//this is what is not working for me, everything else is fine.
listOfCassetteTypes = listOfCassetteTypes.remove(i)
}
}
return listOfCassetteTypes
}
I've tried several different ways but none of them seem to work.
Instead of manipulating the list, you could process each entry in a pair with it's successor... I believe this does what you're after?
def layoutStr = '1 ABC, 2 DEF, 3 SPN, 4 GHI'
def splitted = layoutStr.split(',')
*.trim() // remove white space from all the entries (note *)
*.dropWhile { it ==~ /[0-9 ]/ } // drop until you hit a char that isn't a number or space
.collate(2, 1, true) // group them with the next element in the list
.findAll { it[0] != 'SPN' } // if a group starts with SPN, drop it
.collect {
// If the successor is SPN add -EXT, otherwise, just return the element
it[1] == 'SPN' ? "${it[0]}-EXT" : it[0]
}
assert splitted == ['ABC', 'DEF-EXT', 'GHI']
Followup question
To just get the numbers of the ones not SPN:
def layoutStr = '1 ABC, 2 DEF, 3 SPN, 4 GHI'
def splitted = layoutStr.split(',')
*.trim() // remove white space from all the entries (note *)
*.split(/\s+/) // Split all the entries on whitespace
.findResults { it[1] == 'SPN' ? null : it[0] } // Only keep those that don't have SPN
Note that this is a list of Strings, not Integers... If you need integers then:
.findResults { it[1] == 'SPN' ? null : it[0] as Integer }
#set($a = 10)
#set($b = 123)
#set($c = 456)
// If query string "q1" is not available then set $q1,$q2 to default values
#if($!input.params('q1') && $input.params('q1').empty)
#set($q1 = $b)
#set($q2 = $c)
// If query string "q1" available but not "q2" then add some value to $q1 and set it as $q2
#elseif($!input.params('q2') && $input.params('q2').empty)
#set($q1 = $input.params('q1'))
#set($q2 = $a + $q1 )
// If both query strings available then set them
#else
#set($q1 = $input.params('q1'))
#set($q2 = $input.params('q2'))
#end
I'm triying the above code in Integration request body mapping template. In second case where only q1 is specified as some number (let's say 10) then $q2 should be 22( 12 + 10) but it's becoming as 1210, I assume this is because those $q1 and $q2 are strings and they are getting combined.
So I tried to cast them using this answer, but I'm getting internal server error.
How can I cast string to int and them as integers?
The solution given in the other question works for me. Try this (just the second part of if-else):
#set($a = 10)
#set($q1 = $input.params('q1'))
#set($Integer = 0)
#set($q2 = $Integer.parseInt($q1) + $a)
{
"params" : {
"a" : "$a",
"q1" : "$q1",
"q2" : "$q2"
}
}
I have a large PDF that has been combined from multiple documents.
How can I split the PDF back into multiple documents with a keyword delimiter?
As well as Adobe Reader you will need Adobe Acrobat.
Add the following script using the Action Wizard:
Paste in the following script and modify for your needs. See //comments for help on customisation.
/* Extract Pages into Documents by Keyword */
// Iterates over all pages and find a given string and extracts all
// pages on which that string is found to a new file.
var pageArray = [];
var pageArrayEnd = [];
var stringToSearchFor = app.response("This Action Script splits the document by a keyword on each X number of pages, please enter the keyword:");
for (var p = 0; p < this.numPages; p++) {
// iterate over all words
for (var n = 0; n < this.getPageNumWords(p); n++) {
// DEBUGGING HELP, UNCOMMENT NEXT LINE, CHANGE TO MATCH MULTIPLE WORDS OR WHAT EVER ORDER, eg if ((this.getPageNthWord(p, n) == stringToSearchFor) && (this.getPageNthWord(p, n + 1) == stringToSearchForTWO)) {..., Also add a prompt for the second search word and iterate one less for (var n = 0; n < this.getPageNumWords(p) - 1; n++) ...
//app.alert("Word is " + this.getPageNthWord(p, n));
if (this.getPageNthWord(p, n) == stringToSearchFor) {
//app.alert("Found word on page " + p + " word number " + n, 3);
if (pageArray.length > 0) {
pageArrayEnd.push(p - 1);
}
pageArray.push(p);
break;
}
}
}
pageArrayEnd.push(this.numPages - 1);
//app.alert("Number of sub documents " + pageArray.length, 3);
if (pageArray.length > 0) {
// extract all pages that contain the string into a new document
for (var n = 0; n < pageArray.length; n++) {
var d = app.newDoc(); // this will add a blank page - we need to remove that once we are done
//app.alert("New Doc using pages " + pageArray[n] + " to " + pageArrayEnd[n], 3);
d.insertPages( {
nPage: d.numPages-1,
cPath: this.path,
nStart: pageArray[n],
nEnd: pageArrayEnd[n],
} );
// remove the first page
d.deletePages(0);
d.saveAs({ cPath: this.path.replace(".pdf","") + n + ".pdf" });
d.closeDoc(true);
}
}
Please have a look at this guide on how to split PDF into multiple file:
// Used to register all DLL assemblies.
WorkRegistry.Reset();
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFileName = "Output";
int[] splitIndex = new int[3] { 1, 3, 5 }; // Valid value for each index: 1 to (Page Count - 1).
// Create output PDF file path list
List<String> outputFilePaths = new List<String>();
for (int i = 0; i <= splitIndex.Length; i++)
{
outputFilePaths.Add(Program.RootPath + "\\" + outputFileName + "_" + i.ToString() + ".pdf");
}
// Split input PDF file to 4 files:
// File 0: page 0.
// File 1: page 1 ~ 2.
// File 2: page 3 ~ 4.
// File 3: page 5 ~ the last page.
PDFDocument.SplitDocument(inputFilePath, splitIndex, outputFilePaths.ToArray());
I want to check the number of characters I can insert in a text field, and was thinking of using 'for loop' but it would not help as Selenium tries to insert more than required character the field will not accept but test goes on without any failure, so is there a way to get character count of the text field?
Would this work?
final String myLongString = "Something horrrrribly looooong";
final int longStringLength = myLongString.length();
// assuming driver is a healthy WebDriver instance
WebElement elem = driver.findElement(By.id("myInput"));
elem.sendKeys(myLongString);
// it's possible that you'll first need to lose focus on elem before the next line
int realLength = elem.getValue().length();
assertEquals(longStringLength, realLength);
Using Protractor I captured the actual text in the field and then did a forloop to count each letter.
element(by.css('elementPATH')).getAttribute('value').then(function(words){
//forloop to count each word
var x = 0
for(var i = 0; i < words.length; i++) {
x = x + 1;
};
//check condition
expect(x).toBe(200);
return true;
});
Let me know if this helps.