Why does my regex for "include?" not work? - watir-webdriver

I'm using Watir WebDriver and test/unit with Firefox.
The following code works:
assert(#browser.text.include?("Company employees"))
Why does the following code not work?
assert(#browser.text.include?(/Company employees/))

The String#include? method only accepts strings or characters. It does not accept regular expressions.
You can use either of the following to assert against the regexp:
assert(#browser.text.match(/Company employees/))
assert(#browser.text =~ /Company employees/)
assert(#browser.text[/Company employees/])
However, I think it is more clear (reading the code and the error message) if you use the assert_match:
assert_match(/Company employees/, #browser.text)

try assert(#browser.text.include?("/Company employees/"))

Related

What does this xpath function mean?

I'm trying to decode the URL characters such as "&amp" to "&", I found the code works in PostgreSQL - Replace HTML Entities
. The code is (xpath('/z/text()', ('<z>' || 'AT&T' || '</z>')::xml))[1] as output.
I try to understand this code and read the document of it, but the only thing I found is the explanation of xpath(xpath, xml [, nsarray]). I'm a freshman on PostgreSQL, and I know the /z/ is like a tag. But what is the "||","1" means? why should it use '/z/text()'.
If there have some links about that, it will very helpful. Thanks a lot.

Exim getting random credential in exim.conf

I have been trying to get perl subroutine value and substitution to get the required part of string from randomips subroutine in exim.conf. However when i use string substitution i get error as follow:
Here is what I am trying to achieve
I am trying to split string by colon and get first occurrence as "interface". I'll be using second occurrence as the "helo_data.
exim.pl
sub randomhosts {
#inet = ("x.x.x.1:hostname1.domain.com","x.x.x.2:hostname2.domain.com","x.x.x.3:hostname3.domain.com"
);
return $inet[int rand($#inet+1)];
}
exim.conf
dkim_remote_smtp:
driver = smtp
interface = "${perl{randomhosts}%:*}"
helo_data = "${sender_address_domain}"
Error I get is as follow:
"failed to expand "interface" option for dkim_remote_smtp transport: missing '}' after 'perl'".
Probably the syntax.
Any help?
The code that you are trying to copy was written by someone who doesn't know much about Perl. It includes this line:
return $inet[int rand($#inet+1)];
A Perl programmer would write this as
return $inet[rand #inet];
I think there are a couple of issues here - one with your Exim syntax and one with your Perl syntax.
Exim is giving you this error:
failed to expand "interface" option for dkim_remote_smtp transport: missing '}' after 'perl'
I don't know anything about calling Perl from Exim, but this page mentions a syntax like ${perl{foo}} (which is similar to the one used in the page you are copying from) and one like ${perl{foo}{argument}} for calling a subroutine and passing it an argument. Nowhere does it mention syntax like yours:
${perl{randomhosts}%:*}
I'm not sure where you have got that syntax from, but it seems likely that this is what is causing your first error.
In a comment, you say
I am stying to get first part of string before colon for each random array value for "interface" and part after colon for "helo_data"
It seems to me that Exim doesn't support this requirement. You would need to call the function twice to get the two pieces of information that you require. You might be able to do this in the Perl using something like state variables - but it would be far more complex than the code you currently have there.
Secondly, your Perl code has a syntax error, so even if Exim was able to call your code, it wouldn't work.
The code you're copying sets up #inet like this:
#inet = ("x.x.x.1", "x.x.x.2", "x.x.x.3", "x.x.x.4");
Your equivalent code is this:
#inet = (
"x.x.x.1:hostname1.domain.com",
"x.x.x.2:hostname2.domain.com,
x.x.x.3:hostname3.domain.com
);
I've reformatted it, to make the problems more obvious. You are missing a number of quote marks around the elements of the array. (Note: I see that while I have been writing this answer, you have fixed that.)
Update: Ok, here is some code to put into exim.pl that does what you want.
use feature qw[state];
sub randomhosts {
state $current;
my #inet = (
"x.x.x.1:hostname1.domain.com",
"x.x.x.2:hostname2.domain.com",
"x.x.x.3:hostname3.domain.com"
);
if ($_[0] eq 'generate') {
shift;
#{$current}{qw[ip host]} = split /:/, $inet[rand #inet];
}
return $current->{$_[0]};
}
It generates a new ip/host pair if its first argument is 'generate'. It will then return either the hostname or the ip address from the generated pair. I think you can probably call it from your Exim config file like this:
dkim_remote_smtp:
driver = smtp
interface = "${perl{randomhosts}{generate}{ip}}"
helo_data = "${perl{randomhosts}{host}}"
But I'm no expert in Exim, so that syntax might need tweaking.
First I would like to note I have not worked with exim so I cannot say what exactly you are trying to do and why you have done things exactly so.
In the link you posted, a method called 'randinet' is added to exim.pl and the interface line in exim.conf is replaced by
interface = "${perl{randinet}}"
You have implemented a 'randomhosts' method and replaced the interface line with
interface = "${perl{randomhosts}%:*}"
Now the parser complains about not finding the closing bracket. That is likely due to the symbols you felt free to add but the parser does not have the freedom to ignore.
I suggest you try
interface = "${perl{randomhosts}}"

Dealing with escaped characters in url

I'm trying to map the following url:
/languages/C%23/most_watched_overall.xml
to this action:
get "/languages/:language/:context.xml" do
...
end
The problem is that Sinatra doesn't recognize my mapping and I'm not sure where the problem is.
How about trying it with splats or regex routes? For example:
get "/languages/*/:context.xml" do
params[:splat]
end
See:
http://www.sinatrarb.com/intro#Routes

Zend Lucene - cannot search numbers

Using Zend Lucene I cannot search numbers in description fields
Added it like this:
$doc->addField(Zend_Search_Lucene_Field::Text('description', $current_item['item_short_description'], 'utf-8'));
Googling for this showed that applying following code should solve the problem, but it did not..:
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
any thougts?
You have to set the default analyzer twice: On the indexing process as well as on the searching process.
Use the code line from above:
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
Did you use that command before or after calling Zend_Search_Lucene::open()?
Calling it beforehand definitely works.
I'm not sure about 'zend', but for deal with number in lucene, you need use following technique:
To place int to document use following:
document.Add(new Field(FIELD_SPEC, NumberTools.LongToString(YOUR_INT), Field.Store.YES, Field.Index.UN_TOKENIZED));
To locate value use Term: Term(FIELD_SPEC, NumberTools.LongToString(YOUR_INT))

How to use "not" in XPath?

I want to write something of the sort:
//a[not contains(#id, 'xx')]
(meaning all the links that there 'id' attribute doesn't contain the string 'xx')
I can't find the right syntax.
not() is a function in XPath (as opposed to an operator), so
//a[not(contains(#id, 'xx'))]
you can use not(expression) function
or
expression != true()
None of these answers worked for me for python. I solved by this
a[not(#id='XX')]
Also you can use or condition in your xpath by | operator. Such as
a[not(#id='XX')]|a[not(#class='YY')]
Sometimes we want element which has no class. So you can do like
a[not(#class)]
Use boolean function like below:
//a[(contains(#id, 'xx'))=false]