How to set document.cookie in selenium - selenium

I'm struggling with setting "document.cookie" value via Selenium. I want to achieve something like this. Generally, when I'm on a real browser like Chrome, I open the console and type
document.cookie='my_secret_cookie=1;path=/'
And everything works like a charm.
How can I achieve this via Selenium? Currently, I've done something like this, but it doesn't seem to work for me:
Date today = new Date();
Date tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24));
Cookie newCookie = new Cookie.Builder("myCookie","my_secret_cookie=1")
.domain("my.site") // declared in my local.properties file
.path("/")
.expiresOn(tomorrow)
.isSecure(true)
.build();
driver.manage().addCookie(newCookie);
Any advice?

Related

What can make a functionality run a simulator and not on the device?

I'm building an app using React Native.
I'm fetching an array of values fetched from a database in order to provide users a line chart which refresh every X seconds ( 3s atm ).
This works fine on iOS simulator but when it comes to deploy to TestFlight, and run the app on a device, the curves are not displayed, nothing happens.
Since I can use some other feature that requires to fetch data from the DB, I figured out that the issue was not from the API requests.
I currently use react-native-chart-kit, but I tried with react-native-svg-charts as well, the issue remains the same.
Any hint ?
The issue is the same when I display the array of the fetched values, a new value appears on the simulator every 3 seconds but it does not show anything on the device.
I finally found the issue.
The issue were spotted at the API request.
My request takes 2 timestamp params : start time / end time
I always debug the app using the browser and launch ios sim from the RN project.
This time I tried to Run a the project from Xcode and edit the Scheme as release instead of debug .
When I checked the console from Xcode I noticed that my Start time timestamp when considered as 'NaN'.. Not the End time timestamp.
Back to the RN project and to the browser console, the timestamp is alright.
I made some random changes and now it works fine .
Here's what I had before solving the issue:
function formatDate(rawStamp) {
const now = new Date(rawStamp);
var convertToStr =
now.getFullYear() +
"-" +
("00" + (now.getMonth() + 1)).slice(-2) +
"-" +
("00" + now.getDate()).slice(-2) +
" " +
("00" + now.getHours()).slice(-2) +
":" +
("00" + now.getMinutes()).slice(-2) +
":" +
("00" + now.getSeconds()).slice(-2);
return convertToStr
}
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.parse(nowStr) - (300000)
const gameStampMinusXToStr = formatDate(gameStampMinusX)
Here's what solved the issue:
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.now() - 7200000 - 300000
const gameStampMinusXToStr = formatDate(gameStampMinusX)
I'm a newbie so I cannot explain this behavior, but seems that this little change makes Xcode recognize the timestamp, and proceed the the API request correctly.
If anyone can explain, feel free !

How to get date and time with Javascript in Selenium IDE

I'm trying to get the current date and time in Selenium IDE (latest version 3.7.4) in a format like this 2019-05-21 12:35:23 that is YYYY-MM-DD hh:mm:ss
I'm new to javascript and what I found so far is that in Javascript the current date is obtained from system using new Date();
So I've set the following commands in Selenium IDE
1)
Command: execute script
Target: new Date();
Value: currentdate
2)
Command: echo
Target: $(currentdate)
Value:
But it seems Date(); is not working and is not stored in variable currentdate. This is the output
executeScript on new Date(); with value currentdate OK
echo: undefined
'Untitled' completed successfully
What I'm doing wrong? Thanks for help in advance.
I stumbled across your question while looking for a way to do this myself. I found the answer elsewhere, so I thought I'd share it here in hopes of helping others.
You need to begin your JavaScript line with "return", like this:
return new Date();
This should place a verbose Date() value in your currentDate variable, which you can echo or use elsewhere. You'll probably want to format it using the toLocaleString() method, though, like this:
return new Date().toLocaleString();
That should return the date/time more closely formatted to your needs.

Google maps transit departure time not working properly

I am using this example: http://gmaps-samples-v3.googlecode.com/svn/trunk/transit/transit.html but when I modified the code with the info related to my location, the departure code is not working. I only changed the origin and the destination.
This is the page with my code: http://goo.gl/fgmB9e
Any advice or suggestion?
I replaced the line:
var tzOffset = (now.getTimezoneOffset() + 60) * 60 * 1000;
with:
var tzOffset = now.getTimezoneOffset();
and it looks like working properly.

Application name is not set. Call Builder#setApplicationName. error

Application: Connecting to BigQuery using BigQuery APIs for Java
Environment: Eclipse, Windows 7
My application was running fine until last night. I've made no changes (except for restarting my computer) and my code is suddenly giving me this error:
Application name is not set. Call Builder#setApplicationName.
Thankfully I had a tar'd version of my workspace from last night. I ran a folder compare and found the local_db.bin file was different. I deleted the existing local_db.bin file and tried to run the program again. And it worked fine!
Any idea why this might have happened?
Hopefully this will help anyone else who stumbles upon this issue.
Try this to set your application name
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.setApplicationName("Your app name")
.build();
If you are working with only Firebase Dynamic Links without Android or iOS app
Try this.
builder.setApplicationName(firebaseUtil.getApplicationName());
FirebaseUtil is custom class add keys and application name to this class
FirebaseDynamicLinks.Builder builder = new FirebaseDynamicLinks.Builder(
GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null);
// initialize with api key
FirebaseDynamicLinksRequestInitializer firebaseDynamicLinksRequestInitializer = new FirebaseDynamicLinksRequestInitializer(
firebaseUtil.getFirebaseApiKey());
builder.setFirebaseDynamicLinksRequestInitializer(firebaseDynamicLinksRequestInitializer);
builder.setApplicationName(firebaseUtil.getApplicationName());
// build dynamic links
FirebaseDynamicLinks firebasedynamiclinks = builder.build();
// create Firebase Dynamic Links request
CreateShortDynamicLinkRequest createShortLinkRequest = new CreateShortDynamicLinkRequest();
createShortLinkRequest.setLongDynamicLink(firebaseUtil.getFirebaseUrlPrefix() + "?link=" + urlToShorten);
Suffix suffix = new Suffix();
suffix.setOption(firebaseUtil.getShortSuffixOption());
createShortLinkRequest.setSuffix(suffix);
// request short url
FirebaseDynamicLinks.ShortLinks.Create request = firebasedynamiclinks.shortLinks()
.create(createShortLinkRequest);
CreateShortDynamicLinkResponse createShortDynamicLinkResponse = request.execute();

Recent changes to Rally C# REST API?

1) Earlier this week I was able to create defects and testcases using the Create method, which took 2 arguments at the time (a string and the DynamicJsonObject). However now, it needs three. I understand that one of these is now the workspace reference. How do I go about getting the workspace reference? For creating defects and testcases, I am using an empty string, and this seems to be working correctly for me. Is this to be expected?
2) For creating test case results, I am having a bit of trouble.
DynamicJsonObject newTCResult = new DynamicJsonObject();
newTCResult["Date"] = DateTime.Now.ToString("yyyyMMdd");
newTCResult["TestCase"] = "/testcase/11271454106";
newTCResult["Notes"] = "test";
newTCResult["Build"] = "13.1.0.90";
newTCResult["Verdict"] = "Pass";
CreateResult cr = restApi.Create(" ", "TestCaseResult", newTCResult);
As of right now, absolutely nothing is happening when I run this. I was able to do this successfully earlier this week (when I was able to use the Create method with two arguments). I feel that the problem is because I don't have a valid workspace reference. I followed the suggestion of another user in a similar question prior to this which worked for earlier, however now I am having this problem.
I was finally able to resolve this. It appears that the date field needs to be converted to UTC, so my code now looks something like this
newTCResult["Date"] = DateTime.UtcNow.ToString("o");
After making that small change results were working correctly.
It's somewhat surprising that Creates on Stories or Defects work with an empty string for a Workspace ref, although I suspect that on the server-side, the Webservices API is just using Default Workspace for the User of concern.
Either way, here's how you can get a ref to the Workspace of interest:
String myWorkspaceName = "My Workspace";
// Get a Reference to Target Workspace
Request workspaceRequest = new Request("workspace");
workspaceRequest.Fetch = new List<string>()
{
"Name",
"ObjectID"
};
workspaceRequest.Query = new Query("Name", Query.Operator.Equals, myWorkspaceName);
QueryResult workspaceQueryResults = restApi.Query(workspaceRequest);
var targetWorkspace = workspaceQueryResults.Results.First();
Console.WriteLine("Found Target Workspace: " + targetWorkspace["Name"]);
String workspaceRef = targetWorkspace["_ref"];
You can then use workspaceRef in your call to restApi.Create().